From 32124a791338faabb7fd590bf13c45540a1e4667 Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Wed, 12 Aug 2015 11:04:25 -0600 Subject: [PATCH] Adding a Close() function to the Output interface and to the agent --- agent.go | 11 ++++++++++- outputs/influxdb/influxdb.go | 5 +++++ outputs/registry.go | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/agent.go b/agent.go index f86e27920..1c90bf1a4 100644 --- a/agent.go +++ b/agent.go @@ -67,7 +67,7 @@ func NewAgent(config *Config) (*Agent, error) { return agent, nil } -// Connect connects to the agent's config URL +// Connect connects to all configured outputs func (a *Agent) Connect() error { for _, o := range a.outputs { err := o.output.Connect() @@ -78,6 +78,15 @@ func (a *Agent) Connect() error { return nil } +// Close closes the connection to all configured outputs +func (a *Agent) Close() error { + var err error + for _, o := range a.outputs { + err = o.output.Close() + } + return err +} + // LoadOutputs loads the agent's outputs func (a *Agent) LoadOutputs() ([]string, error) { var names []string diff --git a/outputs/influxdb/influxdb.go b/outputs/influxdb/influxdb.go index 1153f064b..96505a4d7 100644 --- a/outputs/influxdb/influxdb.go +++ b/outputs/influxdb/influxdb.go @@ -52,6 +52,11 @@ func (i *InfluxDB) Connect() error { return nil } +func (i *InfluxDB) Close() error { + // InfluxDB client does not provide a Close() function + return nil +} + func (i *InfluxDB) Write(bp client.BatchPoints) error { bp.Database = i.Database if _, err := i.conn.Write(bp); err != nil { diff --git a/outputs/registry.go b/outputs/registry.go index ccc40f9b2..a2f22f73b 100644 --- a/outputs/registry.go +++ b/outputs/registry.go @@ -6,6 +6,7 @@ import ( type Output interface { Connect() error + Close() error Write(client.BatchPoints) error }