influxdb output: try to connect on write if there are no conns

This commit is contained in:
Cameron Sparr 2016-02-26 16:26:43 +00:00 committed by Michele Fadda
parent dfc10ed8cb
commit de26b44c15
1 changed files with 7 additions and 0 deletions

View File

@ -129,6 +129,7 @@ func (i *InfluxDB) Connect() error {
if e != nil {
log.Println("Database creation failed: " + e.Error())
continue
}
conns = append(conns, c)
@ -156,6 +157,12 @@ 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 {
if len(i.conns) == 0 {
err := i.Connect()
if err != nil {
return err
}
}
bp, err := client.NewBatchPoints(client.BatchPointsConfig{
Database: i.Database,
Precision: i.Precision,