Skip to content

Commit

Permalink
Account for prometheus app metrics (dcos#35)
Browse files Browse the repository at this point in the history
* Account for prometheus app metrics

Mesos tasks may expose metrics via prometheus as an alternative to transmitting metrics via statsd (see
https://jira.mesosphere.com/browse/DCOS_OSS-3717). This commit allows the dcos_metrics output plugin to expose
prometheus task metrics via the /v0/containers/<cid>/app endpoint.

* Fix unittests for new year (influxdata#5213)

* Update comment; combine case statements
  • Loading branch information
philipnrmn authored and branden committed Feb 6, 2019
1 parent bee8503 commit 305792f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
9 changes: 5 additions & 4 deletions plugins/outputs/dcos_metrics/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ func (t *producerTranslator) Translate(metric telegraf.Metric) (msg producers.Me
ok = true
switch {
// Container metrics
// We assume any metric with a container_id tag but without a metric_type tag is a container metric from the
// dcos_containers input.
case hasAllKeys(tags, []string{"container_id"}) && !hasAnyKeys(tags, []string{"metric_type"}):
// We assume any metric with a container_id tag but without a metric_type tag or a url tag is a container metric from
// the dcos_containers input.
case hasAllKeys(tags, []string{"container_id"}) && !hasAnyKeys(tags, []string{"metric_type", "url"}):
msg = t.containerMetricsMessage(metric)

// App metrics
// We assume any metric with both a container_id tag and a metric_type tag is an app metric from the dcos_statsd
// input.
case hasAllKeys(tags, []string{"container_id", "metric_type"}):
// We assume any metric with both a container_id tag and a url tag is an app metric from the prometheus input.
case hasAllKeys(tags, []string{"container_id"}) && hasAnyKeys(tags, []string{"metric_type", "url"}):
msg = t.appMetricsMessage(metric)

// Node metrics
Expand Down
46 changes: 46 additions & 0 deletions plugins/outputs/dcos_metrics/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,52 @@ func TestTranslate(t *testing.T) {
},
},
},

// Custom metrics from tasks collected by the Prometheus input should appear as app metrics.
testCase{
name: "prom app metric",
input: metricParams{
name: "prefix.prom.foo",
tags: map[string]string{
"container_id": "cid",
"service_name": "sname",
"task_name": "tname",
"url": "http://example.com",
"label_name": "label_value",
},
fields: map[string]interface{}{
"metric1": uint64(0),
"metric2": uint64(1),
},
tm: tm,
tp: telegraf.Untyped,
},
output: producers.MetricsMessage{
Name: "dcos.metrics.app",
Dimensions: producers.Dimensions{
MesosID: translator.MesosID,
ClusterID: translator.DCOSClusterID,
Hostname: translator.DCOSNodePrivateIP,
ContainerID: "cid",
FrameworkName: "sname",
TaskName: "tname",
},
Datapoints: []producers.Datapoint{
producers.Datapoint{
Name: "prefix.prom.foo.metric1",
Value: uint64(0),
Timestamp: timestamp,
Tags: map[string]string{"label_name": "label_value", "url": "http://example.com"},
},
producers.Datapoint{
Name: "prefix.prom.foo.metric2",
Value: uint64(1),
Timestamp: timestamp,
Tags: map[string]string{"label_name": "label_value", "url": "http://example.com"},
},
},
},
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 305792f

Please sign in to comment.