grafana

package
v0.5.3-rc.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2022 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const LoggerTag = "GRAFANA"

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, level log.Level, cfg Config) log.Logger

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.

func ToFloatVersion added in v0.5.2

func ToFloatVersion(value reflect.Value) (float64, bool)

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 contains a configuration values for 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)
}

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.
	Sub                        // Subtract from 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