Skip to content

Commit

Permalink
pugins/outputs/influxdb: Prevent runtime panic.
Browse files Browse the repository at this point in the history
- Check and return error from NewBatchPoints to prevent runtime panic if
   user provides an unparsable precision time unit in config.
- Provide correct sample config precision examples.
- Update etc/telegraf.conf precision comment.
  • Loading branch information
netixen committed Feb 18, 2016
1 parent 1837f83 commit 716b82c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion etc/telegraf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
urls = ["http://localhost:8086"] # required
# The target database for metrics (telegraf will create it if not exists)
database = "telegraf" # required
# Precision of writes, valid values are n, u, ms, s, m, and h
# Precision of writes, valid values are "ns", "us" (or "µs"), "ms", "s", "m", "h".
# note: using second precision greatly helps InfluxDB compression
precision = "s"

Expand Down
9 changes: 6 additions & 3 deletions plugins/outputs/influxdb/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var sampleConfig = `
urls = ["http://localhost:8086"] # required
### The target database for metrics (telegraf will create it if not exists)
database = "telegraf" # required
### Precision of writes, valid values are n, u, ms, s, m, and h
### Precision of writes, valid values are "ns", "us" (or "µs"), "ms", "s", "m", "h".
### note: using "s" precision greatly improves InfluxDB compression
precision = "s"
Expand Down Expand Up @@ -156,17 +156,20 @@ func (i *InfluxDB) Description() string {
// Choose a random server in the cluster to write to until a successful write
// occurs, logging each unsuccessful. If all servers fail, return error.
func (i *InfluxDB) Write(metrics []telegraf.Metric) error {
bp, _ := client.NewBatchPoints(client.BatchPointsConfig{
bp, err := client.NewBatchPoints(client.BatchPointsConfig{
Database: i.Database,
Precision: i.Precision,
})
if err != nil {
return err
}

for _, metric := range metrics {
bp.AddPoint(metric.Point())
}

// This will get set to nil if a successful write occurs
err := errors.New("Could not write to any InfluxDB server in cluster")
err = errors.New("Could not write to any InfluxDB server in cluster")

p := rand.Perm(len(i.conns))
for _, n := range p {
Expand Down

0 comments on commit 716b82c

Please sign in to comment.