Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e393c3af3f
commit
4978089aab
4963 changed files with 677545 additions and 0 deletions
89
plugins/inputs/tomcat/README.md
Normal file
89
plugins/inputs/tomcat/README.md
Normal file
|
@ -0,0 +1,89 @@
|
|||
# Tomcat Input Plugin
|
||||
|
||||
The Tomcat plugin collects statistics available from the tomcat manager status
|
||||
page from the `http://<host>/manager/status/all?XML=true URL.` (`XML=true` will
|
||||
return only xml data).
|
||||
|
||||
See the [Tomcat documentation][1] for details of these statistics.
|
||||
|
||||
[1]: https://tomcat.apache.org/tomcat-9.0-doc/manager-howto.html#Server_Status
|
||||
|
||||
## Global configuration options <!-- @/docs/includes/plugin_config.md -->
|
||||
|
||||
In addition to the plugin-specific configuration settings, plugins support
|
||||
additional global and plugin configuration settings. These settings are used to
|
||||
modify metrics, tags, and field or create aliases and configure ordering, etc.
|
||||
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||
|
||||
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
|
||||
|
||||
## Configuration
|
||||
|
||||
```toml @sample.conf
|
||||
# Gather metrics from the Tomcat server status page.
|
||||
[[inputs.tomcat]]
|
||||
## URL of the Tomcat server status
|
||||
# url = "http://127.0.0.1:8080/manager/status/all?XML=true"
|
||||
|
||||
## HTTP Basic Auth Credentials
|
||||
# username = "tomcat"
|
||||
# password = "s3cret"
|
||||
|
||||
## Request timeout
|
||||
# timeout = "5s"
|
||||
|
||||
## Optional TLS Config
|
||||
# tls_ca = "/etc/telegraf/ca.pem"
|
||||
# tls_cert = "/etc/telegraf/cert.pem"
|
||||
# tls_key = "/etc/telegraf/key.pem"
|
||||
## Use TLS but skip chain & host verification
|
||||
# insecure_skip_verify = false
|
||||
```
|
||||
|
||||
## Metrics
|
||||
|
||||
- tomcat_jvm_memory
|
||||
- free
|
||||
- max
|
||||
- total
|
||||
- tomcat_jvm_memorypool
|
||||
- committed
|
||||
- init
|
||||
- max
|
||||
- used
|
||||
- tomcat_connector
|
||||
- bytes_received
|
||||
- bytes_sent
|
||||
- current_thread_busy
|
||||
- current_thread_count
|
||||
- error_count
|
||||
- max_threads
|
||||
- max_time
|
||||
- processing_time
|
||||
- request_count
|
||||
|
||||
### Tags
|
||||
|
||||
- tomcat_jvm_memory
|
||||
- source
|
||||
- tomcat_jvm_memorypool has the following tags:
|
||||
- name
|
||||
- type
|
||||
- source
|
||||
- tomcat_connector
|
||||
- name
|
||||
- source
|
||||
|
||||
## Example Output
|
||||
|
||||
```text
|
||||
tomcat_jvm_memory,host=N8-MBP free=20014352i,max=127729664i,total=41459712i 1474663361000000000
|
||||
tomcat_jvm_memorypool,host=N8-MBP,name=Eden\ Space,type=Heap\ memory committed=11534336i,init=2228224i,max=35258368i,used=1941200i 1474663361000000000
|
||||
tomcat_jvm_memorypool,host=N8-MBP,name=Survivor\ Space,type=Heap\ memory committed=1376256i,init=262144i,max=4390912i,used=1376248i 1474663361000000000
|
||||
tomcat_jvm_memorypool,host=N8-MBP,name=Tenured\ Gen,type=Heap\ memory committed=28549120i,init=5636096i,max=88080384i,used=18127912i 1474663361000000000
|
||||
tomcat_jvm_memorypool,host=N8-MBP,name=Code\ Cache,type=Non-heap\ memory committed=6946816i,init=2555904i,max=251658240i,used=6406528i 1474663361000000000
|
||||
tomcat_jvm_memorypool,host=N8-MBP,name=Compressed\ Class\ Space,type=Non-heap\ memory committed=1966080i,init=0i,max=1073741824i,used=1816120i 1474663361000000000
|
||||
tomcat_jvm_memorypool,host=N8-MBP,name=Metaspace,type=Non-heap\ memory committed=18219008i,init=0i,max=-1i,used=17559376i 1474663361000000000
|
||||
tomcat_connector,host=N8-MBP,name=ajp-bio-8009 bytes_received=0i,bytes_sent=0i,current_thread_count=0i,current_threads_busy=0i,error_count=0i,max_threads=200i,max_time=0i,processing_time=0i,request_count=0i 1474663361000000000
|
||||
tomcat_connector,host=N8-MBP,name=http-bio-8080 bytes_received=0i,bytes_sent=86435i,current_thread_count=10i,current_threads_busy=1i,error_count=2i,max_threads=200i,max_time=167i,processing_time=245i,request_count=15i 1474663361000000000
|
||||
```
|
18
plugins/inputs/tomcat/sample.conf
Normal file
18
plugins/inputs/tomcat/sample.conf
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Gather metrics from the Tomcat server status page.
|
||||
[[inputs.tomcat]]
|
||||
## URL of the Tomcat server status
|
||||
# url = "http://127.0.0.1:8080/manager/status/all?XML=true"
|
||||
|
||||
## HTTP Basic Auth Credentials
|
||||
# username = "tomcat"
|
||||
# password = "s3cret"
|
||||
|
||||
## Request timeout
|
||||
# timeout = "5s"
|
||||
|
||||
## Optional TLS Config
|
||||
# tls_ca = "/etc/telegraf/ca.pem"
|
||||
# tls_cert = "/etc/telegraf/cert.pem"
|
||||
# tls_key = "/etc/telegraf/key.pem"
|
||||
## Use TLS but skip chain & host verification
|
||||
# insecure_skip_verify = false
|
206
plugins/inputs/tomcat/tomcat.go
Normal file
206
plugins/inputs/tomcat/tomcat.go
Normal file
|
@ -0,0 +1,206 @@
|
|||
//go:generate ../../../tools/readme_config_includer/generator
|
||||
package tomcat
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/config"
|
||||
"github.com/influxdata/telegraf/plugins/common/tls"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
)
|
||||
|
||||
//go:embed sample.conf
|
||||
var sampleConfig string
|
||||
|
||||
type Tomcat struct {
|
||||
URL string `toml:"url"`
|
||||
Username string `toml:"username"`
|
||||
Password string `toml:"password"`
|
||||
Timeout config.Duration `toml:"timeout"`
|
||||
tls.ClientConfig
|
||||
|
||||
client *http.Client
|
||||
request *http.Request
|
||||
}
|
||||
|
||||
type tomcatStatus struct {
|
||||
TomcatJvm tomcatJvm `xml:"jvm"`
|
||||
TomcatConnectors []tomcatConnector `xml:"connector"`
|
||||
}
|
||||
|
||||
type tomcatJvm struct {
|
||||
JvmMemory jvmMemoryStat `xml:"memory"`
|
||||
JvmMemoryPools []jvmMemoryPoolStat `xml:"memorypool"`
|
||||
}
|
||||
|
||||
type jvmMemoryStat struct {
|
||||
Free int64 `xml:"free,attr"`
|
||||
Total int64 `xml:"total,attr"`
|
||||
Max int64 `xml:"max,attr"`
|
||||
}
|
||||
|
||||
type jvmMemoryPoolStat struct {
|
||||
Name string `xml:"name,attr"`
|
||||
Type string `xml:"type,attr"`
|
||||
UsageInit int64 `xml:"usageInit,attr"`
|
||||
UsageCommitted int64 `xml:"usageCommitted,attr"`
|
||||
UsageMax int64 `xml:"usageMax,attr"`
|
||||
UsageUsed int64 `xml:"usageUsed,attr"`
|
||||
}
|
||||
|
||||
type tomcatConnector struct {
|
||||
Name string `xml:"name,attr"`
|
||||
ThreadInfo threadInfo `xml:"threadInfo"`
|
||||
RequestInfo requestInfo `xml:"requestInfo"`
|
||||
}
|
||||
|
||||
type threadInfo struct {
|
||||
MaxThreads int64 `xml:"maxThreads,attr"`
|
||||
CurrentThreadCount int64 `xml:"currentThreadCount,attr"`
|
||||
CurrentThreadsBusy int64 `xml:"currentThreadsBusy,attr"`
|
||||
}
|
||||
|
||||
type requestInfo struct {
|
||||
MaxTime int `xml:"maxTime,attr"`
|
||||
ProcessingTime int `xml:"processingTime,attr"`
|
||||
RequestCount int `xml:"requestCount,attr"`
|
||||
ErrorCount int `xml:"errorCount,attr"`
|
||||
BytesReceived int64 `xml:"bytesReceived,attr"`
|
||||
BytesSent int64 `xml:"bytesSent,attr"`
|
||||
}
|
||||
|
||||
func (*Tomcat) SampleConfig() string {
|
||||
return sampleConfig
|
||||
}
|
||||
|
||||
func (s *Tomcat) Gather(acc telegraf.Accumulator) error {
|
||||
if s.client == nil {
|
||||
client, err := s.createHTTPClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.client = client
|
||||
}
|
||||
|
||||
if s.request == nil {
|
||||
_, err := url.Parse(s.URL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
request, err := http.NewRequest("GET", s.URL, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
request.SetBasicAuth(s.Username, s.Password)
|
||||
s.request = request
|
||||
}
|
||||
|
||||
resp, err := s.client.Do(s.request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("received HTTP status code %d from %q; expected 200",
|
||||
resp.StatusCode, s.URL)
|
||||
}
|
||||
|
||||
var status tomcatStatus
|
||||
if err := xml.NewDecoder(resp.Body).Decode(&status); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tags := map[string]string{
|
||||
"source": s.URL,
|
||||
}
|
||||
|
||||
// add tomcat_jvm_memory measurements
|
||||
tcm := map[string]interface{}{
|
||||
"free": status.TomcatJvm.JvmMemory.Free,
|
||||
"total": status.TomcatJvm.JvmMemory.Total,
|
||||
"max": status.TomcatJvm.JvmMemory.Max,
|
||||
}
|
||||
acc.AddFields("tomcat_jvm_memory", tcm, tags)
|
||||
|
||||
// add tomcat_jvm_memorypool measurements
|
||||
for _, mp := range status.TomcatJvm.JvmMemoryPools {
|
||||
tcmpTags := map[string]string{
|
||||
"name": mp.Name,
|
||||
"type": mp.Type,
|
||||
"source": s.URL,
|
||||
}
|
||||
|
||||
tcmpFields := map[string]interface{}{
|
||||
"init": mp.UsageInit,
|
||||
"committed": mp.UsageCommitted,
|
||||
"max": mp.UsageMax,
|
||||
"used": mp.UsageUsed,
|
||||
}
|
||||
|
||||
acc.AddFields("tomcat_jvm_memorypool", tcmpFields, tcmpTags)
|
||||
}
|
||||
|
||||
// add tomcat_connector measurements
|
||||
for _, c := range status.TomcatConnectors {
|
||||
name, err := strconv.Unquote(c.Name)
|
||||
if err != nil {
|
||||
name = c.Name
|
||||
}
|
||||
|
||||
tccTags := map[string]string{
|
||||
"name": name,
|
||||
"source": s.URL,
|
||||
}
|
||||
|
||||
tccFields := map[string]interface{}{
|
||||
"max_threads": c.ThreadInfo.MaxThreads,
|
||||
"current_thread_count": c.ThreadInfo.CurrentThreadCount,
|
||||
"current_threads_busy": c.ThreadInfo.CurrentThreadsBusy,
|
||||
"max_time": c.RequestInfo.MaxTime,
|
||||
"processing_time": c.RequestInfo.ProcessingTime,
|
||||
"request_count": c.RequestInfo.RequestCount,
|
||||
"error_count": c.RequestInfo.ErrorCount,
|
||||
"bytes_received": c.RequestInfo.BytesReceived,
|
||||
"bytes_sent": c.RequestInfo.BytesSent,
|
||||
}
|
||||
|
||||
acc.AddFields("tomcat_connector", tccFields, tccTags)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Tomcat) createHTTPClient() (*http.Client, error) {
|
||||
tlsConfig, err := s.ClientConfig.TLSConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: tlsConfig,
|
||||
},
|
||||
Timeout: time.Duration(s.Timeout),
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
inputs.Add("tomcat", func() telegraf.Input {
|
||||
return &Tomcat{
|
||||
URL: "http://127.0.0.1:8080/manager/status/all?XML=true",
|
||||
Username: "tomcat",
|
||||
Password: "s3cret",
|
||||
Timeout: config.Duration(5 * time.Second),
|
||||
}
|
||||
})
|
||||
}
|
174
plugins/inputs/tomcat/tomcat_test.go
Normal file
174
plugins/inputs/tomcat/tomcat_test.go
Normal file
|
@ -0,0 +1,174 @@
|
|||
package tomcat
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
||||
var tomcatStatus8 = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml-stylesheet type="text/xsl" href="/manager/xform.xsl" ?>
|
||||
<status>
|
||||
<jvm>
|
||||
<memory free='17909336' total='58195968' max='620756992'/>
|
||||
<memorypool name='PS Eden Space' type='Heap memory' usageInit='8912896' usageCommitted='35651584' usageMax='230686720' usageUsed='25591384'/>
|
||||
<memorypool name='PS Old Gen' type='Heap memory' usageInit='21495808' usageCommitted='21495808' usageMax='465567744' usageUsed='13663040'/>
|
||||
<memorypool name='PS Survivor Space' type='Heap memory' usageInit='1048576' usageCommitted='1048576' usageMax='1048576' usageUsed='1032208'/>
|
||||
<memorypool name='Code Cache' type='Non-heap memory' usageInit='2555904' usageCommitted='2555904' usageMax='50331648' usageUsed='1220096'/>
|
||||
<memorypool name='PS Perm Gen' type='Non-heap memory' usageInit='22020096' usageCommitted='22020096' usageMax='174063616' usageUsed='17533952'/>
|
||||
</jvm>
|
||||
<connector name='"ajp-apr-8009"'>
|
||||
<threadInfo maxThreads="200" currentThreadCount="0" currentThreadsBusy="0"/>
|
||||
<requestInfo maxTime="0" processingTime="0" requestCount="0" errorCount="0" bytesReceived="0" bytesSent="0"/>
|
||||
<workers>
|
||||
</workers>
|
||||
</connector>
|
||||
<connector name='"http-apr-8080"'>
|
||||
<threadInfo maxThreads="200" currentThreadCount="5" currentThreadsBusy="1"/>
|
||||
<requestInfo maxTime="68" processingTime="88" requestCount="2" errorCount="1" bytesReceived="0" bytesSent="9286"/>
|
||||
<workers>
|
||||
<worker stage="S" requestProcessingTime="4" requestBytesSent="0" requestBytesReceived="0" remoteAddr="127.0.0.1" virtualHost="127.0.0.1"
|
||||
method="GET" currentUri="/manager/status/all" currentQueryString="XML=true" protocol="HTTP/1.1"/>
|
||||
</workers>
|
||||
</connector>
|
||||
</status>`
|
||||
|
||||
func TestHTTPTomcat8(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
if _, err := fmt.Fprintln(w, tomcatStatus8); err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
tc := Tomcat{
|
||||
URL: ts.URL,
|
||||
Username: "tomcat",
|
||||
Password: "s3cret",
|
||||
}
|
||||
|
||||
var acc testutil.Accumulator
|
||||
require.NoError(t, tc.Gather(&acc))
|
||||
|
||||
// tomcat_jvm_memory
|
||||
jvmMemoryFields := map[string]interface{}{
|
||||
"free": int64(17909336),
|
||||
"total": int64(58195968),
|
||||
"max": int64(620756992),
|
||||
}
|
||||
jvmMemoryTags := map[string]string{
|
||||
"source": ts.URL,
|
||||
}
|
||||
for _, metric := range acc.Metrics {
|
||||
fmt.Println(metric.Measurement)
|
||||
for k, v := range metric.Tags {
|
||||
fmt.Printf("%s: %s\n", k, v)
|
||||
}
|
||||
}
|
||||
acc.AssertContainsTaggedFields(t, "tomcat_jvm_memory", jvmMemoryFields, jvmMemoryTags)
|
||||
|
||||
// tomcat_jvm_memorypool
|
||||
jvmMemoryPoolFields := map[string]interface{}{
|
||||
"init": int64(22020096),
|
||||
"committed": int64(22020096),
|
||||
"max": int64(174063616),
|
||||
"used": int64(17533952),
|
||||
}
|
||||
jvmMemoryPoolTags := map[string]string{
|
||||
"name": "PS Perm Gen",
|
||||
"type": "Non-heap memory",
|
||||
"source": ts.URL,
|
||||
}
|
||||
acc.AssertContainsTaggedFields(t, "tomcat_jvm_memorypool", jvmMemoryPoolFields, jvmMemoryPoolTags)
|
||||
|
||||
// tomcat_connector
|
||||
connectorFields := map[string]interface{}{
|
||||
"max_threads": int64(200),
|
||||
"current_thread_count": int64(5),
|
||||
"current_threads_busy": int64(1),
|
||||
"max_time": int(68),
|
||||
"processing_time": int(88),
|
||||
"request_count": int(2),
|
||||
"error_count": int(1),
|
||||
"bytes_received": int64(0),
|
||||
"bytes_sent": int64(9286),
|
||||
}
|
||||
connectorTags := map[string]string{
|
||||
"name": "http-apr-8080",
|
||||
"source": ts.URL,
|
||||
}
|
||||
acc.AssertContainsTaggedFields(t, "tomcat_connector", connectorFields, connectorTags)
|
||||
}
|
||||
|
||||
var tomcatStatus6 = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml-stylesheet type="text/xsl" href="xform.xsl" ?>
|
||||
<status>
|
||||
<jvm>
|
||||
<memory free="1942681600" total="2040070144" max="2040070144"/>
|
||||
</jvm>
|
||||
<connector name="http-8080">
|
||||
<threadInfo maxThreads="150" currentThreadCount="2" currentThreadsBusy="2"/>
|
||||
<requestInfo maxTime="1005" processingTime="2465" requestCount="436" errorCount="16" bytesReceived="0" bytesSent="550196"/>
|
||||
<workers>
|
||||
<worker stage="K" requestProcessingTime="526" requestBytesSent="0" requestBytesReceived="0" remoteAddr="127.0.0.1" virtualHost="?" method="?"
|
||||
currentUri="?" currentQueryString="?" protocol="?"/>
|
||||
<worker stage="S" requestProcessingTime="1" requestBytesSent="0" requestBytesReceived="0" remoteAddr="127.0.0.1" virtualHost="127.0.0.1"
|
||||
method="GET" currentUri="/manager/status/all" currentQueryString="XML=true" protocol="HTTP/1.1"/>
|
||||
</workers>
|
||||
</connector>
|
||||
</status>`
|
||||
|
||||
func TestHTTPTomcat6(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
if _, err := fmt.Fprintln(w, tomcatStatus6); err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
tc := Tomcat{
|
||||
URL: ts.URL,
|
||||
Username: "tomcat",
|
||||
Password: "s3cret",
|
||||
}
|
||||
|
||||
var acc testutil.Accumulator
|
||||
require.NoError(t, tc.Gather(&acc))
|
||||
|
||||
// tomcat_jvm_memory
|
||||
jvmMemoryFields := map[string]interface{}{
|
||||
"free": int64(1942681600),
|
||||
"total": int64(2040070144),
|
||||
"max": int64(2040070144),
|
||||
}
|
||||
acc.AssertContainsFields(t, "tomcat_jvm_memory", jvmMemoryFields)
|
||||
|
||||
// tomcat_connector
|
||||
connectorFields := map[string]interface{}{
|
||||
"bytes_received": int64(0),
|
||||
"bytes_sent": int64(550196),
|
||||
"current_thread_count": int64(2),
|
||||
"current_threads_busy": int64(2),
|
||||
"error_count": int(16),
|
||||
"max_threads": int64(150),
|
||||
"max_time": int(1005),
|
||||
"processing_time": int(2465),
|
||||
"request_count": int(436),
|
||||
}
|
||||
connectorTags := map[string]string{
|
||||
"name": "http-8080",
|
||||
"source": ts.URL,
|
||||
}
|
||||
acc.AssertContainsTaggedFields(t, "tomcat_connector", connectorFields, connectorTags)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue