Update after the PR review.

This commit is contained in:
Illya Chekrygin 2016-05-12 22:29:27 -07:00
parent 66b589b25d
commit 91ee07464d
3 changed files with 22 additions and 20 deletions

View File

@ -6,7 +6,7 @@ via raw TCP.
## Configuration:
```toml
## controller information tor connect and retrieve tier-id value
## controller information to connect and retrieve tier-id value
controllerTierURL = "https://foo.saas.appdynamics.com/controller/rest/applications/bar/tiers/baz?output=JSON"
controllerUserName = "apiuser"
controllerPassword = "apipass"

View File

@ -1,13 +1,13 @@
package influxdb
package appdynamics
import (
"encoding/json"
"fmt"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/outputs"
"io/ioutil"
"log"
"net/http"
"github.com/influxdata/telegraf/plugins/outputs"
)
var sampleConfig = `
@ -35,7 +35,7 @@ type Appdynamics struct {
}
// Close - There is nothing to close here, but need to comply with output interface
func (a *Appdynamics) Close() error{
func (a *Appdynamics) Close() error {
return nil
}
@ -85,7 +85,7 @@ func (a *Appdynamics) getTierId() (int64, error) {
return 0, err
}
if len(tiers) != 1 {
fmt.Println("Invalid reply: ", tiers)
return 0, fmt.Errorf("Invalid reply: %v", tiers)
}
return tiers[0].Id, nil
@ -105,10 +105,9 @@ func (a *Appdynamics) Write(metrics []telegraf.Metric) error {
default:
appdType = "sum"
}
url := a.AgentURL + metric.Name() + fmt.Sprintf("&value=%v&type=%s", metric.Fields()["value"], appdType)
fmt.Printf("Calling %s ...\n", url)
_, err := http.Get(url)
if err != nil {
url := fmt.Sprintf("%s%s&value=%v&type=%s", a.AgentURL, metric.Name(), metric.Fields()["value"], appdType)
log.Printf("Calling %s ...\n", url)
if _, err := http.Post(url, "", nil); err != nil {
log.Println("ERROR: " + err.Error())
}
}

View File

@ -1,4 +1,4 @@
package influxdb
package appdynamics
import (
"fmt"
@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
)
// TestAppdynamicsError - attemp to initialize Appdynamics with invalid controller user name value
// TestAppdynamicsError - attempt to initialize Appdynamics with invalid controller user name value
func TestAppdynamicsError(t *testing.T) {
a := Appdynamics{
ControllerTierURL: "https://foo.saas.appdynamics.com/controller/rest/applications/bar/tiers/baz?output=JSON",
@ -18,6 +18,7 @@ func TestAppdynamicsError(t *testing.T) {
ControllerPassword: "pass123",
AgentURL: "http://localhost:8293/machineagent/metrics?name=Server|Component:%d|Custom+Metrics|",
}
assert.Error(t, a.Connect())
}
@ -41,18 +42,20 @@ func TestAppdynamicsOK(t *testing.T) {
ControllerPassword: "pass123",
AgentURL: "http://localhost:8293/machineagent/metrics?name=Server|Component:%d|Custom+Metrics|",
}
// this error is expected since we are not connecting to actual controller
assert.Error(t, a.Connect())
// reset agent url value with '123' tier id
a.AgentURL = fmt.Sprintf(a.AgentURL, 123)
assert.Equal(t, a.AgentURL, "http://localhost:8293/machineagent/metrics?name=Server|Component:123|Custom+Metrics|")
tm := time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC)
// counter type - appd-type: sum
m, _ := telegraf.NewMetric(
"foo",
map[string]string{"metrcic_type": "counter"},
map[string]string{"metric_type": "counter"},
map[string]interface{}{"value": float64(1.23)},
time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC),
tm,
)
metrics := []telegraf.Metric{m}
assert.NoError(t, a.Write(metrics))
@ -64,7 +67,7 @@ func TestAppdynamicsOK(t *testing.T) {
"foo",
map[string]string{"metric_type": "gauge"},
map[string]interface{}{"value": float64(4.56)},
time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC),
tm,
)
metrics = []telegraf.Metric{m}
assert.NoError(t, a.Write(metrics))
@ -74,9 +77,9 @@ func TestAppdynamicsOK(t *testing.T) {
// other type - defaults to appd-type: sum
m, _ = telegraf.NewMetric(
"foo",
map[string]string{"metric_type": "bar"},
map[string]string{"metric_type": "other"},
map[string]interface{}{"value": float64(7.89)},
time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC),
tm,
)
metrics = []telegraf.Metric{m}
assert.NoError(t, a.Write(metrics))