Support specifying influxdb retention policy

closes #692
This commit is contained in:
Cameron Sparr 2016-02-29 16:13:00 +00:00 committed by Michele Fadda
parent f01932a256
commit 49a29c0c09
3 changed files with 35 additions and 21 deletions

View File

@ -3,6 +3,7 @@
### Release Notes ### Release Notes
### Features ### Features
- [#692](https://github.com/influxdata/telegraf/pull/770): Support InfluxDB retention policies
### Bugfixes ### Bugfixes
- [#748](https://github.com/influxdata/telegraf/issues/748): Fix sensor plugin split on ":" - [#748](https://github.com/influxdata/telegraf/issues/748): Fix sensor plugin split on ":"

View File

@ -56,15 +56,17 @@
# Configuration for influxdb server to send metrics to # Configuration for influxdb server to send metrics to
[[outputs.influxdb]] [[outputs.influxdb]]
# The full HTTP or UDP endpoint URL for your InfluxDB instance. ## The full HTTP or UDP endpoint URL for your InfluxDB instance.
# Multiple urls can be specified but it is assumed that they are part of the same ## Multiple urls can be specified as part of the same cluster,
# cluster, this means that only ONE of the urls will be written to each interval. ## this means that only ONE of the urls will be written to each interval.
# urls = ["udp://localhost:8089"] # UDP endpoint example # urls = ["udp://localhost:8089"] # UDP endpoint example
urls = ["http://localhost:8086"] # required urls = ["http://localhost:8086"] # required
# The target database for metrics (telegraf will create it if not exists) ## The target database for metrics (telegraf will create it if not exists).
database = "telegraf" # required database = "telegraf" # required
# Precision of writes, valid values are "ns", "us" (or "µs"), "ms", "s", "m", "h". ## Retention policy to write to.
# note: using second precision greatly helps InfluxDB compression retention_policy = "default"
## Precision of writes, valid values are "ns", "us" (or "µs"), "ms", "s", "m", "h".
## note: using "s" precision greatly improves InfluxDB compression.
precision = "s" precision = "s"
## Write timeout (for the InfluxDB client), formatted as a string. ## Write timeout (for the InfluxDB client), formatted as a string.
@ -72,11 +74,18 @@
timeout = "5s" timeout = "5s"
# username = "telegraf" # username = "telegraf"
# password = "metricsmetricsmetricsmetrics" # password = "metricsmetricsmetricsmetrics"
# Set the user agent for HTTP POSTs (can be useful for log differentiation) ## Set the user agent for HTTP POSTs (can be useful for log differentiation)
# user_agent = "telegraf" # user_agent = "telegraf"
# Set UDP payload size, defaults to InfluxDB UDP Client default (512 bytes) ## Set UDP payload size, defaults to InfluxDB UDP Client default (512 bytes)
# udp_payload = 512 # udp_payload = 512
## Optional SSL Config
# ssl_ca = "/etc/telegraf/ca.pem"
# ssl_cert = "/etc/telegraf/cert.pem"
# ssl_key = "/etc/telegraf/key.pem"
## Use SSL but skip chain & host verification
# insecure_skip_verify = false
############################################################################### ###############################################################################
# INPUTS # # INPUTS #

View File

@ -18,15 +18,16 @@ import (
type InfluxDB struct { type InfluxDB struct {
// URL is only for backwards compatability // URL is only for backwards compatability
URL string URL string
URLs []string `toml:"urls"` URLs []string `toml:"urls"`
Username string Username string
Password string Password string
Database string Database string
UserAgent string UserAgent string
Precision string Precision string
Timeout internal.Duration RetentionPolicy string
UDPPayload int `toml:"udp_payload"` Timeout internal.Duration
UDPPayload int `toml:"udp_payload"`
// Path to CA file // Path to CA file
SSLCA string `toml:"ssl_ca"` SSLCA string `toml:"ssl_ca"`
@ -46,10 +47,12 @@ var sampleConfig = `
## this means that only ONE of the urls will be written to each interval. ## this means that only ONE of the urls will be written to each interval.
# urls = ["udp://localhost:8089"] # UDP endpoint example # urls = ["udp://localhost:8089"] # UDP endpoint example
urls = ["http://localhost:8086"] # required urls = ["http://localhost:8086"] # required
## The target database for metrics (telegraf will create it if not exists) ## The target database for metrics (telegraf will create it if not exists).
database = "telegraf" # required database = "telegraf" # required
## Retention policy to write to.
retention_policy = "default"
## Precision of writes, valid values are "ns", "us" (or "µs"), "ms", "s", "m", "h". ## Precision of writes, valid values are "ns", "us" (or "µs"), "ms", "s", "m", "h".
## note: using "s" precision greatly improves InfluxDB compression ## note: using "s" precision greatly improves InfluxDB compression.
precision = "s" precision = "s"
## Write timeout (for the InfluxDB client), formatted as a string. ## Write timeout (for the InfluxDB client), formatted as a string.
@ -164,8 +167,9 @@ func (i *InfluxDB) Write(metrics []telegraf.Metric) error {
} }
} }
bp, err := client.NewBatchPoints(client.BatchPointsConfig{ bp, err := client.NewBatchPoints(client.BatchPointsConfig{
Database: i.Database, Database: i.Database,
Precision: i.Precision, Precision: i.Precision,
RetentionPolicy: i.RetentionPolicy,
}) })
if err != nil { if err != nil {
return err return err