go fmt run over jolokia.go

This commit is contained in:
saiello 2015-10-29 14:48:39 +01:00 committed by Cameron Sparr
parent 40d8aeecb0
commit 62270a3697
1 changed files with 71 additions and 78 deletions

View File

@ -13,7 +13,6 @@ import (
"github.com/influxdb/telegraf/plugins" "github.com/influxdb/telegraf/plugins"
) )
type Server struct { type Server struct {
Name string Name string
Host string Host string
@ -28,14 +27,12 @@ type Metric struct {
} }
type Jolokia struct { type Jolokia struct {
Context string Context string
Servers []Server Servers []Server
Metrics []Metric Metrics []Metric
Tags map[string]string Tags map[string]string
} }
func (j *Jolokia) SampleConfig() string { func (j *Jolokia) SampleConfig() string {
return `[jolokia] return `[jolokia]
context = "/jolokia/read" context = "/jolokia/read"
@ -70,8 +67,6 @@ func (j *Jolokia) Description() string {
return "Read JMX metrics through Jolokia" return "Read JMX metrics through Jolokia"
} }
func getAttr(requestUrl *url.URL) (map[string]interface{}, error) { func getAttr(requestUrl *url.URL) (map[string]interface{}, error) {
//make request //make request
resp, err := http.Get(requestUrl.String()) resp, err := http.Get(requestUrl.String())
@ -110,7 +105,7 @@ func (m *Metric) shouldPass(field string) bool {
if m.Pass != nil { if m.Pass != nil {
for _, pass := range m.Pass{ for _, pass := range m.Pass {
if strings.HasPrefix(field, pass) { if strings.HasPrefix(field, pass) {
return true return true
} }
@ -121,7 +116,7 @@ func (m *Metric) shouldPass(field string) bool {
if m.Drop != nil { if m.Drop != nil {
for _, drop := range m.Drop{ for _, drop := range m.Drop {
if strings.HasPrefix(field, drop) { if strings.HasPrefix(field, drop) {
return false return false
} }
@ -135,7 +130,7 @@ func (m *Metric) shouldPass(field string) bool {
func (m *Metric) filterFields(fields map[string]interface{}) map[string]interface{} { func (m *Metric) filterFields(fields map[string]interface{}) map[string]interface{} {
for field, _ := range fields{ for field, _ := range fields {
if !m.shouldPass(field) { if !m.shouldPass(field) {
delete(fields, field) delete(fields, field)
} }
@ -144,7 +139,6 @@ func (m *Metric) filterFields(fields map[string]interface{}) map[string]interfac
return fields return fields
} }
func (j *Jolokia) Gather(acc plugins.Accumulator) error { func (j *Jolokia) Gather(acc plugins.Accumulator) error {
context := j.Context //"/jolokia/read" context := j.Context //"/jolokia/read"
@ -152,11 +146,10 @@ func (j *Jolokia) Gather(acc plugins.Accumulator) error {
metrics := j.Metrics metrics := j.Metrics
tags := j.Tags tags := j.Tags
if tags == nil{ if tags == nil {
tags = map[string]string{} tags = map[string]string{}
} }
for _, server := range servers { for _, server := range servers {
for _, metric := range metrics { for _, metric := range metrics {
@ -182,7 +175,7 @@ func (j *Jolokia) Gather(acc plugins.Accumulator) error {
case interface{}: case interface{}:
acc.Add(measurement, values.(interface{}), tags) acc.Add(measurement, values.(interface{}), tags)
} }
}else{ } else {
fmt.Printf("Missing key 'value' in '%s' output response\n", requestUrl.String()) fmt.Printf("Missing key 'value' in '%s' output response\n", requestUrl.String())
} }
} }