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:
parent
b55a93a3e1
commit
3357229ec2
|
@ -4,11 +4,13 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
cfg "github.com/influxdata/config"
|
||||||
"github.com/influxdata/telegraf/agent"
|
"github.com/influxdata/telegraf/agent"
|
||||||
"github.com/influxdata/telegraf/internal/config"
|
"github.com/influxdata/telegraf/internal/config"
|
||||||
_ "github.com/influxdata/telegraf/plugins/inputs/all"
|
_ "github.com/influxdata/telegraf/plugins/inputs/all"
|
||||||
|
@ -144,6 +146,13 @@ func main() {
|
||||||
c.OutputFilters = outputFilters
|
c.OutputFilters = outputFilters
|
||||||
c.InputFilters = inputFilters
|
c.InputFilters = inputFilters
|
||||||
err = c.LoadConfig(*fConfig)
|
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 {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,9 @@ type AgentConfig struct {
|
||||||
// Quiet is the option for running in quiet mode
|
// Quiet is the option for running in quiet mode
|
||||||
Quiet bool
|
Quiet bool
|
||||||
Hostname string
|
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.
|
// 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()
|
# Override default hostname, if empty use os.Hostname()
|
||||||
hostname = ""
|
hostname = ""
|
||||||
|
|
||||||
|
# Set configuration management port
|
||||||
|
config-port = ""
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# OUTPUTS #
|
# OUTPUTS #
|
||||||
|
|
Loading…
Reference in New Issue