Add prometheus_client service output module, update prometheus client
- Adds a client implementation using the prometheus go_client library
that exposes metrics.
- Adds a new type of output "ServiceOutput" which follows inline with
the "ServicePlugin", adding a Stop and Start method for the service
This change also requires the newer prometheus/client_golang code, so
the prometheus plugin needed to be changed.
Added the following to Godep:
- bitbucket.org/ww/goautoneg (in github.com/common/expfmt/encode.go)
- prometheus/common/expfmt (in plugins/prometheus.go)
- github.com/prometheus/common/model (in plugins/prometheus.go)
- github.com/prometheus/procfs (in github.com/client_golang/prometheus)
- github.com/beorn7/perks/quantile (in github.com/client_golang/prometheus)
X-Github-Meta: closes #306
This commit is contained in:
committed by
Cameron Sparr
parent
7cc60dfb8f
commit
4449f7f2fb
90
outputs/prometheus_client/prometheus_client_test.go
Normal file
90
outputs/prometheus_client/prometheus_client_test.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package prometheus_client
|
||||
|
||||
import (
|
||||
"github.com/influxdb/influxdb/client/v2"
|
||||
"github.com/influxdb/telegraf/plugins/prometheus"
|
||||
"github.com/influxdb/telegraf/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var pTesting *PrometheusClient = &PrometheusClient{}
|
||||
|
||||
func TestPrometheusStart(t *testing.T) {
|
||||
require.NoError(t, pTesting.Start())
|
||||
}
|
||||
|
||||
func TestPrometheusWritePointEmptyTag(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping integration test in short mode")
|
||||
}
|
||||
p := &prometheus.Prometheus{
|
||||
Urls: []string{"http://" + testutil.GetLocalHost() + ":9126/metrics"},
|
||||
}
|
||||
tags := make(map[string]string)
|
||||
var points = []*client.Point{
|
||||
client.NewPoint(
|
||||
"test_point_1",
|
||||
tags,
|
||||
map[string]interface{}{"value": 0.0}),
|
||||
client.NewPoint(
|
||||
"test_point_2",
|
||||
tags,
|
||||
map[string]interface{}{"value": 1.0}),
|
||||
}
|
||||
require.NoError(t, pTesting.Write(points))
|
||||
|
||||
expected := []struct {
|
||||
name string
|
||||
value float64
|
||||
tags map[string]string
|
||||
}{
|
||||
{"test_point_1", 0.0, tags},
|
||||
{"test_point_2", 1.0, tags},
|
||||
}
|
||||
|
||||
var acc testutil.Accumulator
|
||||
|
||||
require.NoError(t, p.Gather(&acc))
|
||||
for _, e := range expected {
|
||||
assert.NoError(t, acc.ValidateValue(e.name, e.value))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrometheusWritePointTag(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping integration test in short mode")
|
||||
}
|
||||
p := &prometheus.Prometheus{
|
||||
Urls: []string{"http://" + testutil.GetLocalHost() + ":9126/metrics"},
|
||||
}
|
||||
tags := make(map[string]string)
|
||||
tags["testtag"] = "testvalue"
|
||||
var points = []*client.Point{
|
||||
client.NewPoint(
|
||||
"test_point_3",
|
||||
tags,
|
||||
map[string]interface{}{"value": 0.0}),
|
||||
client.NewPoint(
|
||||
"test_point_4",
|
||||
tags,
|
||||
map[string]interface{}{"value": 1.0}),
|
||||
}
|
||||
require.NoError(t, pTesting.Write(points))
|
||||
|
||||
expected := []struct {
|
||||
name string
|
||||
value float64
|
||||
}{
|
||||
{"test_point_3", 0.0},
|
||||
{"test_point_4", 1.0},
|
||||
}
|
||||
|
||||
var acc testutil.Accumulator
|
||||
|
||||
require.NoError(t, p.Gather(&acc))
|
||||
for _, e := range expected {
|
||||
assert.True(t, acc.CheckTaggedValue(e.name, e.value, tags))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user