2015-04-01 16:34:32 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2015-04-07 16:24:34 +00:00
|
|
|
"fmt"
|
2015-04-01 16:34:32 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/influxdb/tivan"
|
|
|
|
_ "github.com/influxdb/tivan/plugins/all"
|
|
|
|
)
|
|
|
|
|
|
|
|
var fDebug = flag.Bool("debug", false, "show metrics as they're generated to stdout")
|
2015-04-07 00:24:24 +00:00
|
|
|
var fTest = flag.Bool("test", false, "gather metrics, print them out, and exit")
|
2015-04-01 16:34:32 +00:00
|
|
|
var fConfig = flag.String("config", "", "configuration file to load")
|
2015-04-07 16:24:34 +00:00
|
|
|
var fVersion = flag.Bool("version", false, "display the version")
|
2015-05-18 22:10:11 +00:00
|
|
|
var fSampleConfig = flag.Bool("sample-config", false, "print out full sample configuration")
|
2015-04-07 16:24:34 +00:00
|
|
|
|
|
|
|
var Version = "unreleased"
|
2015-04-01 16:34:32 +00:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
2015-04-07 16:24:34 +00:00
|
|
|
if *fVersion {
|
|
|
|
fmt.Printf("InfluxDB Tivan agent - Version %s\n", Version)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-05-18 22:10:11 +00:00
|
|
|
if *fSampleConfig {
|
|
|
|
tivan.PrintSampleConfig()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-04-01 16:34:32 +00:00
|
|
|
var (
|
|
|
|
config *tivan.Config
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
if *fConfig != "" {
|
|
|
|
config, err = tivan.LoadConfig(*fConfig)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
config = tivan.DefaultConfig()
|
|
|
|
}
|
|
|
|
|
2015-04-06 16:32:10 +00:00
|
|
|
ag, err := tivan.NewAgent(config)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2015-04-01 16:34:32 +00:00
|
|
|
|
|
|
|
if *fDebug {
|
|
|
|
ag.Debug = true
|
|
|
|
}
|
|
|
|
|
|
|
|
plugins, err := ag.LoadPlugins()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2015-04-07 00:24:24 +00:00
|
|
|
if *fTest {
|
2015-05-18 21:10:12 +00:00
|
|
|
if *fConfig != "" {
|
|
|
|
err = ag.Test()
|
|
|
|
} else {
|
|
|
|
err = ag.TestAllPlugins()
|
|
|
|
}
|
|
|
|
|
2015-04-07 00:24:24 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ag.Connect()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2015-04-01 16:34:32 +00:00
|
|
|
shutdown := make(chan struct{})
|
|
|
|
|
|
|
|
signals := make(chan os.Signal)
|
|
|
|
|
|
|
|
signal.Notify(signals, os.Interrupt)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
<-signals
|
|
|
|
close(shutdown)
|
|
|
|
}()
|
|
|
|
|
|
|
|
log.Print("InfluxDB Agent running")
|
|
|
|
log.Printf("Loaded plugins: %s", strings.Join(plugins, " "))
|
|
|
|
if ag.Debug {
|
|
|
|
log.Printf("Debug: enabled")
|
2015-05-20 05:19:32 +00:00
|
|
|
log.Printf("Agent Config: Interval:%s, Debug:%#v, Hostname:%#v\n",
|
|
|
|
ag.Interval, ag.Debug, ag.Hostname)
|
2015-04-01 16:34:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if config.URL != "" {
|
|
|
|
log.Printf("Sending metrics to: %s", config.URL)
|
|
|
|
log.Printf("Tags enabled: %v", config.ListTags())
|
|
|
|
}
|
|
|
|
|
|
|
|
ag.Run(shutdown)
|
|
|
|
}
|