forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a template system for the graphite serializer
closes influxdata#925 closes influxdata#879
- Loading branch information
Showing
12 changed files
with
400 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,6 +178,9 @@ | |
# servers = ["localhost:2003"] | ||
# ## Prefix metrics name | ||
# prefix = "" | ||
# ## Graphite output template | ||
# ## see https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md | ||
# template = "host.tags.measurement.field" | ||
# ## timeout in seconds for the write connection to graphite | ||
# timeout = 2 | ||
|
||
|
@@ -251,22 +254,20 @@ | |
# [[outputs.librato]] | ||
# ## Librator API Docs | ||
# ## http://dev.librato.com/v1/metrics-authentication | ||
# | ||
# ## Librato API user | ||
# api_user = "[email protected]" # required. | ||
# | ||
# ## Librato API token | ||
# api_token = "my-secret-token" # required. | ||
# | ||
# ### Debug | ||
# ## Debug | ||
# # debug = false | ||
# | ||
# ### Tag Field to populate source attribute (optional) | ||
# ### This is typically the _hostname_ from which the metric was obtained. | ||
# ## Tag Field to populate source attribute (optional) | ||
# ## This is typically the _hostname_ from which the metric was obtained. | ||
# source_tag = "host" | ||
# | ||
# ## Connection timeout. | ||
# # timeout = "5s" | ||
# ## Output Name Template (same as graphite buckets) | ||
# ## see https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md#graphite | ||
# template = "host.tags.measurement.field" | ||
|
||
|
||
# # Configuration for MQTT server to send metrics to | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,34 @@ | ||
# Graphite Output Plugin | ||
|
||
This plugin writes to [Graphite](http://graphite.readthedocs.org/en/latest/index.html) via raw TCP. | ||
This plugin writes to [Graphite](http://graphite.readthedocs.org/en/latest/index.html) | ||
via raw TCP. | ||
|
||
## Configuration: | ||
|
||
```toml | ||
# Configuration for Graphite server to send metrics to | ||
[[outputs.graphite]] | ||
## TCP endpoint for your graphite instance. | ||
servers = ["localhost:2003"] | ||
## Prefix metrics name | ||
prefix = "" | ||
## Graphite output template | ||
## see https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md | ||
template = "host.tags.measurement.field" | ||
## timeout in seconds for the write connection to graphite | ||
timeout = 2 | ||
``` | ||
|
||
Parameters: | ||
|
||
Servers []string | ||
Prefix string | ||
Timeout int | ||
Servers []string | ||
Prefix string | ||
Timeout int | ||
Template string | ||
|
||
* `servers`: List of strings, ["mygraphiteserver:2003"]. | ||
* `prefix`: String use to prefix all sent metrics. | ||
* `timeout`: Connection timeout in second. | ||
* `timeout`: Connection timeout in seconds. | ||
* `template`: Template for graphite output format, see | ||
https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md | ||
for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ type Librato struct { | |
NameFromTags bool | ||
SourceTag string | ||
Timeout internal.Duration | ||
Template string | ||
|
||
apiUrl string | ||
client *http.Client | ||
|
@@ -29,22 +30,20 @@ type Librato struct { | |
var sampleConfig = ` | ||
## Librator API Docs | ||
## http://dev.librato.com/v1/metrics-authentication | ||
## Librato API user | ||
api_user = "[email protected]" # required. | ||
## Librato API token | ||
api_token = "my-secret-token" # required. | ||
### Debug | ||
## Debug | ||
# debug = false | ||
### Tag Field to populate source attribute (optional) | ||
### This is typically the _hostname_ from which the metric was obtained. | ||
## Tag Field to populate source attribute (optional) | ||
## This is typically the _hostname_ from which the metric was obtained. | ||
source_tag = "host" | ||
## Connection timeout. | ||
# timeout = "5s" | ||
## Output Name Template (same as graphite buckets) | ||
## see https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md#graphite | ||
template = "host.tags.measurement.field" | ||
` | ||
|
||
type LMetrics struct { | ||
|
@@ -152,17 +151,13 @@ func (l *Librato) Description() string { | |
return "Configuration for Librato API to send metrics to." | ||
} | ||
|
||
func (l *Librato) buildGaugeName(m telegraf.Metric, fieldName string) string { | ||
// Use the GraphiteSerializer | ||
graphiteSerializer := graphite.GraphiteSerializer{} | ||
return graphiteSerializer.SerializeBucketName(m, fieldName) | ||
} | ||
|
||
func (l *Librato) buildGauges(m telegraf.Metric) ([]*Gauge, error) { | ||
gauges := []*Gauge{} | ||
serializer := graphite.GraphiteSerializer{Template: l.Template} | ||
bucket := serializer.SerializeBucketName(m.Name(), m.Tags()) | ||
for fieldName, value := range m.Fields() { | ||
gauge := &Gauge{ | ||
Name: l.buildGaugeName(m, fieldName), | ||
Name: graphite.InsertField(bucket, fieldName), | ||
MeasureTime: m.Time().Unix(), | ||
} | ||
if !gauge.verifyValue(value) { | ||
|
Oops, something went wrong.