From 3357229ec2d55b19b8370871bcba18eeed28a3b5 Mon Sep 17 00:00:00 2001 From: Tim Raymond Date: Tue, 9 Feb 2016 11:03:43 -0500 Subject: [PATCH] Add configuration management service This sets up a configuration managemet service on a configureable port (which itself is configureable by the configuration management service!). It sets up an HTTP handler on this port whereby GETs to / will deliver the current TOML configuration that Telegraf booted from. POSTs to / will update that configuration. Telegraf can then be restarted from the configuration by sending SIGHUP through existing mechanisms. This configuration management service is not authenticated in any way! It is assumed that this service will only be available behind the firewall. --- cmd/telegraf/telegraf.go | 9 +++++++++ internal/config/config.go | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index 78687d286..cd12ff3c8 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -4,11 +4,13 @@ import ( "flag" "fmt" "log" + "net/http" "os" "os/signal" "strings" "syscall" + cfg "github.com/influxdata/config" "github.com/influxdata/telegraf/agent" "github.com/influxdata/telegraf/internal/config" _ "github.com/influxdata/telegraf/plugins/inputs/all" @@ -144,6 +146,13 @@ func main() { c.OutputFilters = outputFilters c.InputFilters = inputFilters err = c.LoadConfig(*fConfig) + + if c.Agent.ConfigPort != "" { + cf, _ := cfg.NewConfig(*fConfig, struct{}{}) + log.Printf("Starting configuration management service on port %s\n", c.Agent.ConfigPort) + go http.ListenAndServe(c.Agent.ConfigPort, cf.HTTP()) + } + if err != nil { log.Fatal(err) } diff --git a/internal/config/config.go b/internal/config/config.go index 9b35cd407..3e1de7880 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -92,6 +92,9 @@ type AgentConfig struct { // Quiet is the option for running in quiet mode Quiet bool Hostname string + + // ConfigPort is the location of the HTTP handlers for remotely changing config + ConfigPort string } // Inputs returns a list of strings of the configured inputs. @@ -175,6 +178,9 @@ var header = `# Telegraf configuration # Override default hostname, if empty use os.Hostname() hostname = "" + # Set configuration management port + config-port = "" + ############################################################################### # OUTPUTS #