func (a *Agent) Close() error {
	var err error
	for _, o := range a.Config.Outputs {
		err = o.Output.Close()
		switch ot := o.Output.(type) {
		case telegraf.ServiceOutput:
			ot.Stop()
		}
	}
	return err
}
Close closes the connection to all configured outputs
package agent
import (
	"fmt"
	"log"
	"os"
	"runtime"
	"sync"
	"time"
	"github.com/influxdata/telegraf"
	"github.com/influxdata/telegraf/selfstat"
	"github.com/ostrost/ostent/internal"
	"github.com/ostrost/ostent/internal/config"
	"github.com/ostrost/ostent/internal/models"
)
type Agent struct {
	Config *config.Config
}
func NewAgent(config *config.Config) (*Agent, error) {
	a := &Agent{
		Config: config,
	}
	if !a.Config.Agent.OmitHostname {
		if a.Config.Agent.Hostname == "" {
			hostname, err := os.Hostname()
			if err != nil {
				return nil, err
			}
			a.Config.Agent.Hostname = hostname
		}
		config.Tags["host"] = a.Config.Agent.Hostname
	}
	return a, nil
}
func (a *Agent) Connect() error {
	for _, o := range a.Config.Outputs {
		o.Quiet = a.Config.Agent.Quiet
		switch ot := o.Output.(type) {
		case telegraf.ServiceOutput:
			if err := ot.Start(); err != nil {
				log.Printf("E! Service for output %s failed to start, exiting\n%s\n",
					o.Name, err.Error())
				return err
			}
		}
		log.Printf("D! Attempting connection to output: %s\n", o.Name)
		err := o.Output.Connect()
		if err != nil {
			log.Printf("E! Failed to connect to output %s, retrying in 15s, "+
				"error was '%s' \n", o.Name, err)
			time.Sleep(15 * time.Second)
			err = o.Output.Connect()
			if err != nil {
				return err
			}
		}
		log.Printf("D! Successfully connected to output: %s\n", o.Name)
	}
	return nil
}