Update after the PR review.
This commit is contained in:
parent
66b589b25d
commit
91ee07464d
|
@ -6,7 +6,7 @@ via raw TCP.
|
||||||
## Configuration:
|
## Configuration:
|
||||||
|
|
||||||
```toml
|
```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"
|
controllerTierURL = "https://foo.saas.appdynamics.com/controller/rest/applications/bar/tiers/baz?output=JSON"
|
||||||
controllerUserName = "apiuser"
|
controllerUserName = "apiuser"
|
||||||
controllerPassword = "apipass"
|
controllerPassword = "apipass"
|
||||||
|
@ -14,4 +14,4 @@ via raw TCP.
|
||||||
## |Component:%d| gets transformed into |Component:id| during initialization - where 'id' is a tier-id for
|
## |Component:%d| gets transformed into |Component:id| during initialization - where 'id' is a tier-id for
|
||||||
## this controller application/tier combination
|
## this controller application/tier combination
|
||||||
agentURL = "http://localhost:8293/machineagent/metrics?name=Server|Component:%d|Custom+Metrics|"
|
agentURL = "http://localhost:8293/machineagent/metrics?name=Server|Component:%d|Custom+Metrics|"
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package influxdb
|
package appdynamics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
|
"github.com/influxdata/telegraf/plugins/outputs"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"github.com/influxdata/telegraf/plugins/outputs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var sampleConfig = `
|
var sampleConfig = `
|
||||||
|
@ -23,9 +23,9 @@ var sampleConfig = `
|
||||||
|
|
||||||
type Appdynamics struct {
|
type Appdynamics struct {
|
||||||
// Controller values for retrieving tier-id from the controller
|
// Controller values for retrieving tier-id from the controller
|
||||||
ControllerTierURL string
|
ControllerTierURL string
|
||||||
ControllerUserName string
|
ControllerUserName string
|
||||||
ControllerPassword string
|
ControllerPassword string
|
||||||
|
|
||||||
// Machine agent URL format string
|
// Machine agent URL format string
|
||||||
AgentURL string
|
AgentURL string
|
||||||
|
@ -35,7 +35,7 @@ type Appdynamics struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close - There is nothing to close here, but need to comply with output interface
|
// 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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ func (a *Appdynamics) getTierId() (int64, error) {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
if len(tiers) != 1 {
|
if len(tiers) != 1 {
|
||||||
fmt.Println("Invalid reply: ", tiers)
|
return 0, fmt.Errorf("Invalid reply: %v", tiers)
|
||||||
}
|
}
|
||||||
|
|
||||||
return tiers[0].Id, nil
|
return tiers[0].Id, nil
|
||||||
|
@ -105,10 +105,9 @@ func (a *Appdynamics) Write(metrics []telegraf.Metric) error {
|
||||||
default:
|
default:
|
||||||
appdType = "sum"
|
appdType = "sum"
|
||||||
}
|
}
|
||||||
url := a.AgentURL + metric.Name() + fmt.Sprintf("&value=%v&type=%s", metric.Fields()["value"], appdType)
|
url := fmt.Sprintf("%s%s&value=%v&type=%s", a.AgentURL, metric.Name(), metric.Fields()["value"], appdType)
|
||||||
fmt.Printf("Calling %s ...\n", url)
|
log.Printf("Calling %s ...\n", url)
|
||||||
_, err := http.Get(url)
|
if _, err := http.Post(url, "", nil); err != nil {
|
||||||
if err != nil {
|
|
||||||
log.Println("ERROR: " + err.Error())
|
log.Println("ERROR: " + err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package influxdb
|
package appdynamics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"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) {
|
func TestAppdynamicsError(t *testing.T) {
|
||||||
a := Appdynamics{
|
a := Appdynamics{
|
||||||
ControllerTierURL: "https://foo.saas.appdynamics.com/controller/rest/applications/bar/tiers/baz?output=JSON",
|
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",
|
ControllerPassword: "pass123",
|
||||||
AgentURL: "http://localhost:8293/machineagent/metrics?name=Server|Component:%d|Custom+Metrics|",
|
AgentURL: "http://localhost:8293/machineagent/metrics?name=Server|Component:%d|Custom+Metrics|",
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Error(t, a.Connect())
|
assert.Error(t, a.Connect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,18 +42,20 @@ func TestAppdynamicsOK(t *testing.T) {
|
||||||
ControllerPassword: "pass123",
|
ControllerPassword: "pass123",
|
||||||
AgentURL: "http://localhost:8293/machineagent/metrics?name=Server|Component:%d|Custom+Metrics|",
|
AgentURL: "http://localhost:8293/machineagent/metrics?name=Server|Component:%d|Custom+Metrics|",
|
||||||
}
|
}
|
||||||
|
|
||||||
// this error is expected since we are not connecting to actual controller
|
// this error is expected since we are not connecting to actual controller
|
||||||
assert.Error(t, a.Connect())
|
assert.Error(t, a.Connect())
|
||||||
// reset agent url value with '123' tier id
|
// reset agent url value with '123' tier id
|
||||||
a.AgentURL = fmt.Sprintf(a.AgentURL, 123)
|
a.AgentURL = fmt.Sprintf(a.AgentURL, 123)
|
||||||
assert.Equal(t, a.AgentURL, "http://localhost:8293/machineagent/metrics?name=Server|Component:123|Custom+Metrics|")
|
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
|
// counter type - appd-type: sum
|
||||||
m, _ := telegraf.NewMetric(
|
m, _ := telegraf.NewMetric(
|
||||||
"foo",
|
"foo",
|
||||||
map[string]string{"metrcic_type": "counter"},
|
map[string]string{"metric_type": "counter"},
|
||||||
map[string]interface{}{"value": float64(1.23)},
|
map[string]interface{}{"value": float64(1.23)},
|
||||||
time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC),
|
tm,
|
||||||
)
|
)
|
||||||
metrics := []telegraf.Metric{m}
|
metrics := []telegraf.Metric{m}
|
||||||
assert.NoError(t, a.Write(metrics))
|
assert.NoError(t, a.Write(metrics))
|
||||||
|
@ -64,7 +67,7 @@ func TestAppdynamicsOK(t *testing.T) {
|
||||||
"foo",
|
"foo",
|
||||||
map[string]string{"metric_type": "gauge"},
|
map[string]string{"metric_type": "gauge"},
|
||||||
map[string]interface{}{"value": float64(4.56)},
|
map[string]interface{}{"value": float64(4.56)},
|
||||||
time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC),
|
tm,
|
||||||
)
|
)
|
||||||
metrics = []telegraf.Metric{m}
|
metrics = []telegraf.Metric{m}
|
||||||
assert.NoError(t, a.Write(metrics))
|
assert.NoError(t, a.Write(metrics))
|
||||||
|
@ -74,9 +77,9 @@ func TestAppdynamicsOK(t *testing.T) {
|
||||||
// other type - defaults to appd-type: sum
|
// other type - defaults to appd-type: sum
|
||||||
m, _ = telegraf.NewMetric(
|
m, _ = telegraf.NewMetric(
|
||||||
"foo",
|
"foo",
|
||||||
map[string]string{"metric_type": "bar"},
|
map[string]string{"metric_type": "other"},
|
||||||
map[string]interface{}{"value": float64(7.89)},
|
map[string]interface{}{"value": float64(7.89)},
|
||||||
time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC),
|
tm,
|
||||||
)
|
)
|
||||||
metrics = []telegraf.Metric{m}
|
metrics = []telegraf.Metric{m}
|
||||||
assert.NoError(t, a.Write(metrics))
|
assert.NoError(t, a.Write(metrics))
|
||||||
|
|
Loading…
Reference in New Issue