v0.0.0-...-16a0e24 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2020 License: MIT Imports: 13 Imported by: 0


Health Output Plugin

The health plugin provides a HTTP health check resource that can be configured to return a failure status code based on the value of a metric.

When the plugin is healthy it will return a 200 response; when unhealthy it will return a 503 response. The default state is healthy, one or more checks must fail in order for the resource to enter the failed state.

  ## Address and port to listen on.
  ##   ex: service_address = "http://localhost:8080"
  ##       service_address = "unix:///var/run/telegraf-health.sock"
  # service_address = "http://:8080"

  ## The maximum duration for reading the entire request.
  # read_timeout = "5s"
  ## The maximum duration for writing the entire response.
  # write_timeout = "5s"

  ## Username and password to accept for HTTP basic authentication.
  # basic_username = "user1"
  # basic_password = "secret"

  ## Allowed CA certificates for client certificates.
  # tls_allowed_cacerts = ["/etc/telegraf/clientca.pem"]

  ## TLS server certificate and private key.
  # tls_cert = "/etc/telegraf/cert.pem"
  # tls_key = "/etc/telegraf/key.pem"

  ## One or more check sub-tables should be defined, it is also recommended to
  ## use metric filtering to limit the metrics that flow into this output.
  ## When using the default buffer sizes, this example will fail when the
  ## metric buffer is half full.
  ## namepass = ["internal_write"]
  ## tagpass = { output = ["influxdb"] }
  ## [[]]
  ##   field = "buffer_size"
  ##   lt = 5000.0
  ## [[]]
  ##   field = "buffer_size"

The compares check is used to assert basic mathematical relationships. Use it by choosing a field key and one or more comparisons that must hold true. If the field is not found on a metric no comparison will be made.

Comparisons must be hold true on all metrics for the check to pass.


The contains check can be used to require a field key to exist on at least one metric.

If the field is found on any metric the check passes.




This section is empty.


This section is empty.


This section is empty.


type Checker

type Checker interface {
	// Check returns true if the metrics meet its criteria.
	Check(metrics []telegraf.Metric) bool

type Compares

type Compares struct {
	Field string   `toml:"field"`
	GT    *float64 `toml:"gt"`
	GE    *float64 `toml:"ge"`
	LT    *float64 `toml:"lt"`
	LE    *float64 `toml:"le"`
	EQ    *float64 `toml:"eq"`
	NE    *float64 `toml:"ne"`

func (*Compares) Check

func (c *Compares) Check(metrics []telegraf.Metric) bool

type Contains

type Contains struct {
	Field string `toml:"field"`

func (*Contains) Check

func (c *Contains) Check(metrics []telegraf.Metric) bool

type Health

type Health struct {
	ServiceAddress string            `toml:"service_address"`
	ReadTimeout    internal.Duration `toml:"read_timeout"`
	WriteTimeout   internal.Duration `toml:"write_timeout"`
	BasicUsername  string            `toml:"basic_username"`
	BasicPassword  string            `toml:"basic_password"`

	Compares []*Compares `toml:"compares"`
	Contains []*Contains `toml:"contains"`
	// contains filtered or unexported fields

func NewHealth

func NewHealth() *Health

func (*Health) Close

func (h *Health) Close() error

Close shuts down the HTTP server.

func (*Health) Connect

func (h *Health) Connect() error

Connect starts the HTTP server.

func (*Health) Description

func (h *Health) Description() string

func (*Health) Init

func (h *Health) Init() error

func (*Health) Origin

func (h *Health) Origin() string

Origin returns the URL of the HTTP server.

func (*Health) SampleConfig

func (h *Health) SampleConfig() string

func (*Health) ServeHTTP

func (h *Health) ServeHTTP(rw http.ResponseWriter, req *http.Request)

func (*Health) Write

func (h *Health) Write(metrics []telegraf.Metric) error

Write runs all checks over the metric batch and adjust health state.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL