feat(inputs.tomcat): add source tag (#12170)

This commit is contained in:
Joshua Powers 2022-11-07 07:28:09 -07:00 committed by GitHub
parent 6659e3d62a
commit a3424a982f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 9 deletions

View File

@ -64,11 +64,15 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
### Tags ### Tags
- tomcat_jvm_memory
- source
- tomcat_jvm_memorypool has the following tags: - tomcat_jvm_memorypool has the following tags:
- name - name
- type - type
- source
- tomcat_connector - tomcat_connector
- name - name
- source
## Example Output ## Example Output

View File

@ -117,19 +117,24 @@ func (s *Tomcat) Gather(acc telegraf.Accumulator) error {
return err return err
} }
tags := map[string]string{
"source": s.URL,
}
// add tomcat_jvm_memory measurements // add tomcat_jvm_memory measurements
tcm := map[string]interface{}{ tcm := map[string]interface{}{
"free": status.TomcatJvm.JvmMemory.Free, "free": status.TomcatJvm.JvmMemory.Free,
"total": status.TomcatJvm.JvmMemory.Total, "total": status.TomcatJvm.JvmMemory.Total,
"max": status.TomcatJvm.JvmMemory.Max, "max": status.TomcatJvm.JvmMemory.Max,
} }
acc.AddFields("tomcat_jvm_memory", tcm, nil) acc.AddFields("tomcat_jvm_memory", tcm, tags)
// add tomcat_jvm_memorypool measurements // add tomcat_jvm_memorypool measurements
for _, mp := range status.TomcatJvm.JvmMemoryPools { for _, mp := range status.TomcatJvm.JvmMemoryPools {
tcmpTags := map[string]string{ tcmpTags := map[string]string{
"name": mp.Name, "name": mp.Name,
"type": mp.Type, "type": mp.Type,
"source": s.URL,
} }
tcmpFields := map[string]interface{}{ tcmpFields := map[string]interface{}{
@ -150,7 +155,8 @@ func (s *Tomcat) Gather(acc telegraf.Accumulator) error {
} }
tccTags := map[string]string{ tccTags := map[string]string{
"name": name, "name": name,
"source": s.URL,
} }
tccFields := map[string]interface{}{ tccFields := map[string]interface{}{

View File

@ -60,7 +60,16 @@ func TestHTTPTomcat8(t *testing.T) {
"total": int64(58195968), "total": int64(58195968),
"max": int64(620756992), "max": int64(620756992),
} }
acc.AssertContainsFields(t, "tomcat_jvm_memory", jvmMemoryFields) 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 // tomcat_jvm_memorypool
jvmMemoryPoolFields := map[string]interface{}{ jvmMemoryPoolFields := map[string]interface{}{
@ -70,8 +79,9 @@ func TestHTTPTomcat8(t *testing.T) {
"used": int64(17533952), "used": int64(17533952),
} }
jvmMemoryPoolTags := map[string]string{ jvmMemoryPoolTags := map[string]string{
"name": "PS Perm Gen", "name": "PS Perm Gen",
"type": "Non-heap memory", "type": "Non-heap memory",
"source": ts.URL,
} }
acc.AssertContainsTaggedFields(t, "tomcat_jvm_memorypool", jvmMemoryPoolFields, jvmMemoryPoolTags) acc.AssertContainsTaggedFields(t, "tomcat_jvm_memorypool", jvmMemoryPoolFields, jvmMemoryPoolTags)
@ -88,7 +98,8 @@ func TestHTTPTomcat8(t *testing.T) {
"bytes_sent": int64(9286), "bytes_sent": int64(9286),
} }
connectorTags := map[string]string{ connectorTags := map[string]string{
"name": "http-apr-8080", "name": "http-apr-8080",
"source": ts.URL,
} }
acc.AssertContainsTaggedFields(t, "tomcat_connector", connectorFields, connectorTags) acc.AssertContainsTaggedFields(t, "tomcat_connector", connectorFields, connectorTags)
} }
@ -147,7 +158,8 @@ func TestHTTPTomcat6(t *testing.T) {
"request_count": int(436), "request_count": int(436),
} }
connectorTags := map[string]string{ connectorTags := map[string]string{
"name": "http-8080", "name": "http-8080",
"source": ts.URL,
} }
acc.AssertContainsTaggedFields(t, "tomcat_connector", connectorFields, connectorTags) acc.AssertContainsTaggedFields(t, "tomcat_connector", connectorFields, connectorTags)
} }