Adding a Close() function to the Output interface and to the agent
This commit is contained in:
parent
08042089f9
commit
32124a7913
11
agent.go
11
agent.go
|
@ -67,7 +67,7 @@ func NewAgent(config *Config) (*Agent, error) {
|
||||||
return agent, nil
|
return agent, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect connects to the agent's config URL
|
// Connect connects to all configured outputs
|
||||||
func (a *Agent) Connect() error {
|
func (a *Agent) Connect() error {
|
||||||
for _, o := range a.outputs {
|
for _, o := range a.outputs {
|
||||||
err := o.output.Connect()
|
err := o.output.Connect()
|
||||||
|
@ -78,6 +78,15 @@ func (a *Agent) Connect() error {
|
||||||
return nil
|
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
|
// LoadOutputs loads the agent's outputs
|
||||||
func (a *Agent) LoadOutputs() ([]string, error) {
|
func (a *Agent) LoadOutputs() ([]string, error) {
|
||||||
var names []string
|
var names []string
|
||||||
|
|
|
@ -52,6 +52,11 @@ func (i *InfluxDB) Connect() error {
|
||||||
return nil
|
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 {
|
func (i *InfluxDB) Write(bp client.BatchPoints) error {
|
||||||
bp.Database = i.Database
|
bp.Database = i.Database
|
||||||
if _, err := i.conn.Write(bp); err != nil {
|
if _, err := i.conn.Write(bp); err != nil {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
type Output interface {
|
type Output interface {
|
||||||
Connect() error
|
Connect() error
|
||||||
|
Close() error
|
||||||
Write(client.BatchPoints) error
|
Write(client.BatchPoints) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue