jolokia: run fmt
This commit is contained in:
parent
83aa86c404
commit
5e9980f263
|
@ -1,6 +1,7 @@
|
||||||
package jolokia
|
package jolokia
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -8,7 +9,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
"bytes"
|
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
|
@ -23,10 +23,10 @@ type Server struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Metric struct {
|
type Metric struct {
|
||||||
Name string
|
Name string
|
||||||
Mbean string
|
Mbean string
|
||||||
Attribute string
|
Attribute string
|
||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
type JolokiaClient interface {
|
type JolokiaClient interface {
|
||||||
|
@ -44,10 +44,10 @@ func (c JolokiaClientImpl) MakeRequest(req *http.Request) (*http.Response, error
|
||||||
type Jolokia struct {
|
type Jolokia struct {
|
||||||
jClient JolokiaClient
|
jClient JolokiaClient
|
||||||
Context string
|
Context string
|
||||||
Mode string
|
Mode string
|
||||||
Servers []Server
|
Servers []Server
|
||||||
Metrics []Metric
|
Metrics []Metric
|
||||||
Proxy Server
|
Proxy Server
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Jolokia) SampleConfig() string {
|
func (j *Jolokia) SampleConfig() string {
|
||||||
|
@ -86,13 +86,13 @@ func (j *Jolokia) SampleConfig() string {
|
||||||
[[inputs.jolokia.metrics]]
|
[[inputs.jolokia.metrics]]
|
||||||
name = "thread_count"
|
name = "thread_count"
|
||||||
mbean = "java.lang:type=Threading"
|
mbean = "java.lang:type=Threading"
|
||||||
attribute = "TotalStartedThreadCount,ThreadCount,DaemonThreadCount,PeakThreadCount"
|
attribute = "TotalStartedThreadCount,ThreadCount,DaemonThreadCount,PeakThreadCount"
|
||||||
|
|
||||||
## This collect number of class loaded/unloaded counts metrics.
|
## This collect number of class loaded/unloaded counts metrics.
|
||||||
[[inputs.jolokia.metrics]]
|
[[inputs.jolokia.metrics]]
|
||||||
name = "class_count"
|
name = "class_count"
|
||||||
mbean = "java.lang:type=ClassLoading"
|
mbean = "java.lang:type=ClassLoading"
|
||||||
attribute = "LoadedClassCount,UnloadedClassCount,TotalLoadedClassCount"
|
attribute = "LoadedClassCount,UnloadedClassCount,TotalLoadedClassCount"
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,14 +142,13 @@ func (j *Jolokia) doRequest(req *http.Request) (map[string]interface{}, error) {
|
||||||
return jsonOut, nil
|
return jsonOut, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (j *Jolokia) prepareRequest(server Server, metric Metric) (*http.Request, error) {
|
func (j *Jolokia) prepareRequest(server Server, metric Metric) (*http.Request, error) {
|
||||||
var jolokiaUrl *url.URL
|
var jolokiaUrl *url.URL
|
||||||
context := j.Context // Usually "/jolokia"
|
context := j.Context // Usually "/jolokia"
|
||||||
|
|
||||||
// Create bodyContent
|
// Create bodyContent
|
||||||
bodyContent := map[string]interface{}{
|
bodyContent := map[string]interface{}{
|
||||||
"type": "read",
|
"type": "read",
|
||||||
"mbean": metric.Mbean,
|
"mbean": metric.Mbean,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +160,7 @@ func (j *Jolokia) prepareRequest(server Server, metric Metric) (*http.Request, e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add target, only in proxy mode
|
// Add target, only in proxy mode
|
||||||
if ( j.Mode == "proxy") {
|
if j.Mode == "proxy" {
|
||||||
|
|
||||||
serviceUrl := fmt.Sprintf("service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", server.Host, server.Port)
|
serviceUrl := fmt.Sprintf("service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", server.Host, server.Port)
|
||||||
|
|
||||||
|
@ -217,7 +216,6 @@ func (j *Jolokia) prepareRequest(server Server, metric Metric) (*http.Request, e
|
||||||
return req, nil
|
return req, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (j *Jolokia) Gather(acc telegraf.Accumulator) error {
|
func (j *Jolokia) Gather(acc telegraf.Accumulator) error {
|
||||||
servers := j.Servers
|
servers := j.Servers
|
||||||
metrics := j.Metrics
|
metrics := j.Metrics
|
||||||
|
@ -233,7 +231,7 @@ func (j *Jolokia) Gather(acc telegraf.Accumulator) error {
|
||||||
measurement := metric.Name
|
measurement := metric.Name
|
||||||
|
|
||||||
req, err := j.prepareRequest(server, metric)
|
req, err := j.prepareRequest(server, metric)
|
||||||
if err != nil{
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +239,7 @@ func (j *Jolokia) Gather(acc telegraf.Accumulator) error {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error handling response: %s\n", err)
|
fmt.Printf("Error handling response: %s\n", err)
|
||||||
}else {
|
} else {
|
||||||
|
|
||||||
if values, ok := out["value"]; ok {
|
if values, ok := out["value"]; ok {
|
||||||
switch t := values.(type) {
|
switch t := values.(type) {
|
||||||
|
|
|
@ -48,7 +48,7 @@ const empty = ""
|
||||||
|
|
||||||
var Servers = []Server{Server{Name: "as1", Host: "127.0.0.1", Port: "8080"}}
|
var Servers = []Server{Server{Name: "as1", Host: "127.0.0.1", Port: "8080"}}
|
||||||
var HeapMetric = Metric{Name: "heap_memory_usage",
|
var HeapMetric = Metric{Name: "heap_memory_usage",
|
||||||
Mbean: "java.lang:type=Memory", Attribute: "HeapMemoryUsage" }
|
Mbean: "java.lang:type=Memory", Attribute: "HeapMemoryUsage"}
|
||||||
var UsedHeapMetric = Metric{Name: "heap_memory_usage",
|
var UsedHeapMetric = Metric{Name: "heap_memory_usage",
|
||||||
Mbean: "java.lang:type=Memory", Attribute: "HeapMemoryUsage"}
|
Mbean: "java.lang:type=Memory", Attribute: "HeapMemoryUsage"}
|
||||||
|
|
||||||
|
@ -117,7 +117,6 @@ func TestHttpJsonOn404(t *testing.T) {
|
||||||
assert.Equal(t, 0, len(acc.Metrics))
|
assert.Equal(t, 0, len(acc.Metrics))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Test that the proper values are ignored or collected
|
// Test that the proper values are ignored or collected
|
||||||
func TestHttpInvalidJson(t *testing.T) {
|
func TestHttpInvalidJson(t *testing.T) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue