Skip to content

Commit

Permalink
jolokia: run fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
saiello committed Apr 15, 2016
1 parent 83aa86c commit 161b946
Show file tree
Hide file tree
Showing 3 changed files with 406 additions and 16 deletions.
26 changes: 12 additions & 14 deletions plugins/inputs/jolokia/jolokia.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package jolokia

import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"time"
"bytes"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
Expand All @@ -23,10 +23,10 @@ type Server struct {
}

type Metric struct {
Name string
Mbean string
Name string
Mbean string
Attribute string
Path string
Path string
}

type JolokiaClient interface {
Expand All @@ -44,10 +44,10 @@ func (c JolokiaClientImpl) MakeRequest(req *http.Request) (*http.Response, error
type Jolokia struct {
jClient JolokiaClient
Context string
Mode string
Mode string
Servers []Server
Metrics []Metric
Proxy Server
Proxy Server
}

func (j *Jolokia) SampleConfig() string {
Expand Down Expand Up @@ -86,13 +86,13 @@ func (j *Jolokia) SampleConfig() string {
[[inputs.jolokia.metrics]]
name = "thread_count"
mbean = "java.lang:type=Threading"
attribute = "TotalStartedThreadCount,ThreadCount,DaemonThreadCount,PeakThreadCount"
attribute = "TotalStartedThreadCount,ThreadCount,DaemonThreadCount,PeakThreadCount"
## This collect number of class loaded/unloaded counts metrics.
[[inputs.jolokia.metrics]]
name = "class_count"
mbean = "java.lang:type=ClassLoading"
attribute = "LoadedClassCount,UnloadedClassCount,TotalLoadedClassCount"
attribute = "LoadedClassCount,UnloadedClassCount,TotalLoadedClassCount"
`
}

Expand Down Expand Up @@ -142,14 +142,13 @@ func (j *Jolokia) doRequest(req *http.Request) (map[string]interface{}, error) {
return jsonOut, nil
}


func (j *Jolokia) prepareRequest(server Server, metric Metric) (*http.Request, error) {
var jolokiaUrl *url.URL
context := j.Context // Usually "/jolokia"

// Create bodyContent
bodyContent := map[string]interface{}{
"type": "read",
"type": "read",
"mbean": metric.Mbean,
}

Expand All @@ -161,7 +160,7 @@ func (j *Jolokia) prepareRequest(server Server, metric Metric) (*http.Request, e
}

// 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)

Expand Down Expand Up @@ -217,7 +216,6 @@ func (j *Jolokia) prepareRequest(server Server, metric Metric) (*http.Request, e
return req, nil
}


func (j *Jolokia) Gather(acc telegraf.Accumulator) error {
servers := j.Servers
metrics := j.Metrics
Expand All @@ -233,15 +231,15 @@ func (j *Jolokia) Gather(acc telegraf.Accumulator) error {
measurement := metric.Name

req, err := j.prepareRequest(server, metric)
if err != nil{
if err != nil {
return err
}

out, err := j.doRequest(req)

if err != nil {
fmt.Printf("Error handling response: %s\n", err)
}else {
} else {

if values, ok := out["value"]; ok {
switch t := values.(type) {
Expand Down
3 changes: 1 addition & 2 deletions plugins/inputs/jolokia/jolokia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const empty = ""

var Servers = []Server{Server{Name: "as1", Host: "127.0.0.1", Port: "8080"}}
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",
Mbean: "java.lang:type=Memory", Attribute: "HeapMemoryUsage"}

Expand Down Expand Up @@ -117,7 +117,6 @@ func TestHttpJsonOn404(t *testing.T) {
assert.Equal(t, 0, len(acc.Metrics))
}


// Test that the proper values are ignored or collected
func TestHttpInvalidJson(t *testing.T) {

Expand Down
Loading

0 comments on commit 161b946

Please sign in to comment.