Creating circleci job to just lint and vet code
This commit is contained in:
21
agent.go
21
agent.go
@@ -19,8 +19,13 @@ type runningPlugin struct {
|
||||
config *ConfiguredPlugin
|
||||
}
|
||||
|
||||
// Agent runs telegraf and collects data based on the given config
|
||||
type Agent struct {
|
||||
|
||||
// Interval at which to gather information
|
||||
Interval Duration
|
||||
|
||||
// Run in debug mode?
|
||||
Debug bool
|
||||
Hostname string
|
||||
|
||||
@@ -31,6 +36,7 @@ type Agent struct {
|
||||
conn *client.Client
|
||||
}
|
||||
|
||||
// NewAgent returns an Agent struct based off the given Config
|
||||
func NewAgent(config *Config) (*Agent, error) {
|
||||
agent := &Agent{Config: config, Interval: Duration{10 * time.Second}}
|
||||
|
||||
@@ -57,8 +63,9 @@ func NewAgent(config *Config) (*Agent, error) {
|
||||
return agent, nil
|
||||
}
|
||||
|
||||
func (agent *Agent) Connect() error {
|
||||
config := agent.Config
|
||||
// Connect connects to the agent's config URL
|
||||
func (a *Agent) Connect() error {
|
||||
config := a.Config
|
||||
|
||||
u, err := url.Parse(config.URL)
|
||||
if err != nil {
|
||||
@@ -77,11 +84,12 @@ func (agent *Agent) Connect() error {
|
||||
return err
|
||||
}
|
||||
|
||||
agent.conn = c
|
||||
a.conn = c
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadPlugins loads the agent's plugins
|
||||
func (a *Agent) LoadPlugins() ([]string, error) {
|
||||
var names []string
|
||||
|
||||
@@ -201,10 +209,12 @@ func (a *Agent) crankSeparate(shutdown chan struct{}, plugin *runningPlugin) err
|
||||
}
|
||||
}
|
||||
|
||||
// TestAllPlugins verifies that we can 'Gather' from all plugins with the
|
||||
// default configuration
|
||||
func (a *Agent) TestAllPlugins() error {
|
||||
var names []string
|
||||
|
||||
for name, _ := range plugins.Plugins {
|
||||
for name := range plugins.Plugins {
|
||||
names = append(names, name)
|
||||
}
|
||||
|
||||
@@ -230,6 +240,8 @@ func (a *Agent) TestAllPlugins() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Test verifies that we can 'Gather' from all plugins with their configured
|
||||
// Config struct
|
||||
func (a *Agent) Test() error {
|
||||
var acc BatchPoints
|
||||
|
||||
@@ -253,6 +265,7 @@ func (a *Agent) Test() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run runs the agent daemon, gathering every Interval
|
||||
func (a *Agent) Run(shutdown chan struct{}) error {
|
||||
if a.conn == nil {
|
||||
err := a.Connect()
|
||||
|
||||
Reference in New Issue
Block a user