grafana

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const LoggerTag = "GRAFANA"

Variables

This section is empty.

Functions

func New

func New(level log.Level, cfg Config) (log.Logger, error)

New creates a new logger that can extract parameters from log messages and send them to Grafana Cloud using the Graphite endpoint. It starts a background goroutine that will be sending metrics to the Grafana Cloud server as often as described in Config.Interval parameter.

Types

type Config

type Config struct {
	// Metrics is a list of metric definitions.
	Metrics []Metric

	// Interval specifies how often logs should be sent to the Grafana Cloud
	// server. Logs with the same name in that interval will be replaced with
	// never ones.
	Interval uint

	// Graphite server endpoint.
	GraphiteEndpoint string

	// Graphite API key.
	GraphiteAPIKey string

	// HTTPClient used to send metrics to Grafana Cloud.
	HTTPClient *http.Client

	// Logger used to log errors related to this logger, such as connection errors.
	Logger log.Logger
}

Config is the configuration for the Grafana logger.

type Metric

type Metric struct {
	// MatchMessage is a regexp that must match the log message.
	MatchMessage *regexp.Regexp

	// MatchFields is a list of regexp's that must match the values of the
	// fields defined in the map keys.
	MatchFields map[string]*regexp.Regexp

	// Value is the dot-separated path of the field with the metric value.
	// If empty, the value 1 will be used as the metric value.
	Value string

	// Name is the name of the metric. It can contain references to log fields
	// in the format ${path}, where path is the dot-separated path to the field.
	Name string

	// Tag is a list of metric tags. They can contain references to log fields
	// in the format ${path}, where path is the dot-separated path to the field.
	Tags map[string][]string

	// OnDuplicate specifies how duplicated values in the same interval should
	// be handled.
	OnDuplicate OnDuplicate

	// TransformFunc defines the function applied to the value before setting it.
	TransformFunc func(float64) float64

	// ParserFunc is going to be applied to transform the value reflection to an actual float64 value
	ParserFunc func(reflect.Value) (float64, bool)
	// contains filtered or unexported fields
}

Metric describes one Grafana metric.

type OnDuplicate added in v0.4.9

type OnDuplicate int
const (
	Replace OnDuplicate = iota // Replace the current value.
	Ignore                     // Use previous value.
	Sum                        // Add to the current value.
	Max                        // Use higher value.
	Min                        // Use lower value.
)

Jump to

Keyboard shortcuts

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