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.
This commit is contained in:
Tim Raymond 2016-02-09 11:03:43 -05:00
parent b55a93a3e1
commit 3357229ec2
2 changed files with 15 additions and 0 deletions

View File

@ -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)
}

View File

@ -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 #