diff --git a/plugins/inputs/tomcat/tomcat.go b/plugins/inputs/tomcat/tomcat.go index b9dcc731d..dd3c03ce3 100644 --- a/plugins/inputs/tomcat/tomcat.go +++ b/plugins/inputs/tomcat/tomcat.go @@ -165,7 +165,7 @@ func (s *Tomcat) Gather(acc telegraf.Accumulator) error { for _, c := range status.TomcatConnectors { name, err := strconv.Unquote(c.Name) if err != nil { - return fmt.Errorf("Unable to unquote name '%s': %s", c.Name, err) + name = c.Name } tccTags := map[string]string{ diff --git a/plugins/inputs/tomcat/tomcat_test.go b/plugins/inputs/tomcat/tomcat_test.go index 8bdddd6d0..5e206ab83 100644 --- a/plugins/inputs/tomcat/tomcat_test.go +++ b/plugins/inputs/tomcat/tomcat_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/require" ) -var tomcatStatus = ` +var tomcatStatus8 = ` @@ -37,10 +37,10 @@ var tomcatStatus = ` ` -func TestHTTPTomcat(t *testing.T) { +func TestHTTPTomcat8(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - fmt.Fprintln(w, tomcatStatus) + fmt.Fprintln(w, tomcatStatus8) })) defer ts.Close() @@ -91,5 +91,63 @@ func TestHTTPTomcat(t *testing.T) { "name": "http-apr-8080", } acc.AssertContainsTaggedFields(t, "tomcat_connector", connectorFields, connectorTags) - +} + +var tomcatStatus6 = ` + + + + + + + + + + + + + +` + +func TestHTTPTomcat6(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + fmt.Fprintln(w, tomcatStatus6) + })) + defer ts.Close() + + tc := Tomcat{ + URL: ts.URL, + Username: "tomcat", + Password: "s3cret", + } + + var acc testutil.Accumulator + err := tc.Gather(&acc) + require.NoError(t, err) + + // 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", + } + acc.AssertContainsTaggedFields(t, "tomcat_connector", connectorFields, connectorTags) }