Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pugins/outputs/influxdb: Prevent runtime panic. #715

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you update etc/telegraf.conf with this comment as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

### 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