health

package
v1.29.4 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 14 Imported by: 4

README

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.

Global configuration options

In addition to the plugin-specific configuration settings, plugins support additional global and plugin configuration settings. These settings are used to modify metrics, tags, and field or create aliases and configure ordering, etc. See the CONFIGURATION.md for more details.

Configuration

# Configurable HTTP health check resource based on metrics
[[outputs.health]]
  ## 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"

  ## NOTE: Due to the way TOML is parsed, tables must be at the END of the
  ## plugin definition, otherwise additional config options are read as part of
  ## the table

  ## 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"] }
  ##
  ## [[outputs.health.compares]]
  ##   field = "buffer_size"
  ##   lt = 5000.0
  ##
  ## [[outputs.health.contains]]
  ##   field = "buffer_size"
compares

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.

contains

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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    config.Duration `toml:"read_timeout"`
	WriteTimeout   config.Duration `toml:"write_timeout"`
	BasicUsername  string          `toml:"basic_username"`
	BasicPassword  string          `toml:"basic_password"`
	tlsint.ServerConfig

	Compares []*Compares     `toml:"compares"`
	Contains []*Contains     `toml:"contains"`
	Log      telegraf.Logger `toml:"-"`
	// 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) 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 (*Health) SampleConfig() string

func (*Health) ServeHTTP

func (h *Health) ServeHTTP(rw http.ResponseWriter, _ *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