diff --git a/collector/cmd/collector/main.go b/collector/cmd/collector/main.go index bbf3b62..1051ca9 100644 --- a/collector/cmd/collector/main.go +++ b/collector/cmd/collector/main.go @@ -7,27 +7,37 @@ import ( "github.com/bobrik/collectd-docker/collector" "github.com/fsouza/go-dockerclient" + "path" ) func main() { - endpoint := flag.String("endpoint", "unix:///var/run/docker.sock", "docker endpoint") - host := flag.String("host", "", "host to report") - interval := flag.Int("interval", 1, "interval to report") + e := flag.String("endpoint", "unix:///var/run/docker.sock", "docker endpoint") + c := flag.String("cert", "", "cert path for tls") + h := flag.String("host", "", "host to report") + i := flag.Int("interval", 1, "interval to report") flag.Parse() - if *host == "" { + if *h == "" { flag.PrintDefaults() os.Exit(1) } - client, err := docker.NewClient(*endpoint) + var client *docker.Client + var err error + + if *c != "" { + client, err = docker.NewTLSClient(*e, path.Join(*c, "cert.pem"), path.Join(*c, "key.pem"), path.Join(*c, "ca.pem")) + } else { + client, err = docker.NewClient(*e) + } + if err != nil { log.Fatal(err) } - writer := collector.NewCollectdWriter(*host, os.Stdout) + writer := collector.NewCollectdWriter(*h, os.Stdout) - collector := collector.NewCollector(client, writer, *interval) + collector := collector.NewCollector(client, writer, *i) err = collector.Run(5) if err != nil {