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
- tomcat_jvm_memory
- source
- tomcat_jvm_memorypool has the following tags:
- name
- type
- source
- tomcat_connector
- name
- source
## Example Output

View File

@ -117,19 +117,24 @@ func (s *Tomcat) Gather(acc telegraf.Accumulator) error {
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, nil)
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{}{
@ -151,6 +156,7 @@ func (s *Tomcat) Gather(acc telegraf.Accumulator) error {
tccTags := map[string]string{
"name": name,
"source": s.URL,
}
tccFields := map[string]interface{}{

View File

@ -60,7 +60,16 @@ func TestHTTPTomcat8(t *testing.T) {
"total": int64(58195968),
"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
jvmMemoryPoolFields := map[string]interface{}{
@ -72,6 +81,7 @@ func TestHTTPTomcat8(t *testing.T) {
jvmMemoryPoolTags := map[string]string{
"name": "PS Perm Gen",
"type": "Non-heap memory",
"source": ts.URL,
}
acc.AssertContainsTaggedFields(t, "tomcat_jvm_memorypool", jvmMemoryPoolFields, jvmMemoryPoolTags)
@ -89,6 +99,7 @@ func TestHTTPTomcat8(t *testing.T) {
}
connectorTags := map[string]string{
"name": "http-apr-8080",
"source": ts.URL,
}
acc.AssertContainsTaggedFields(t, "tomcat_connector", connectorFields, connectorTags)
}
@ -148,6 +159,7 @@ func TestHTTPTomcat6(t *testing.T) {
}
connectorTags := map[string]string{
"name": "http-8080",
"source": ts.URL,
}
acc.AssertContainsTaggedFields(t, "tomcat_connector", connectorFields, connectorTags)
}