Documentation ¶
Index ¶
- Constants
- Variables
- func AddGlobalLabel(name, value string) error
- func DiskFree() (free uint64, ok bool)
- func DiskTotal() (total uint64, ok bool)
- func DiskUsed() (used uint64, ok bool)
- func DiskUsedPercent() (usedPercent float64, ok bool)
- func EnableMetricPersistence(key string) error
- func ExportValues(requestPermission api.Permission, internalOnly bool) map[string]any
- func LoadAvg1() (loadAvg float64, ok bool)
- func LoadAvg15() (loadAvg float64, ok bool)
- func LoadAvg5() (loadAvg float64, ok bool)
- func MemAvailable() (available uint64, ok bool)
- func MemTotal() (total uint64, ok bool)
- func MemUsed() (used uint64, ok bool)
- func MemUsedPercent() (usedPercent float64, ok bool)
- func SetNamespace(namespace string) error
- func WriteMetrics(w io.Writer, permission api.Permission, expertiseLevel config.ExpertiseLevel)
- type Counter
- type FetchingCounter
- type FloatMetric
- type Gauge
- type Histogram
- type Metric
- type MetricExport
- type Metrics
- type Options
- type UIntMetric
Constants ¶
const (
PrometheusFormatRequirement = "^" + prometheusBaseFormt + "$"
)
PrometheusFormatRequirement is required format defined by prometheus for metric and label names.
Variables ¶
var ( CfgOptionInstanceKey = "core/metrics/instance" CfgOptionCommentKey = "core/metrics/comment" CfgOptionPushKey = "core/metrics/push" )
Configuration Keys.
var ( // ErrAlreadyStarted is returned when an operation is only valid before the // first metric is registered, and is called after. ErrAlreadyStarted = errors.New("can only be changed before first metric is registered") // ErrAlreadyRegistered is returned when a metric with the same ID is // registered again. ErrAlreadyRegistered = errors.New("metric already registered") // ErrAlreadySet is returned when a value is already set and cannot be changed. ErrAlreadySet = errors.New("already set") // ErrInvalidOptions is returned when invalid options where provided. ErrInvalidOptions = errors.New("invalid options") )
var ( // ErrAlreadyInitialized is returned when trying to initialize an option // more than once or if the time window for initializing is over. ErrAlreadyInitialized = errors.New("already initialized") )
Functions ¶
func AddGlobalLabel ¶
AddGlobalLabel adds a global label to all metrics. Global labels must be added before any metric is registered. Does not affect golang runtime metrics.
func DiskUsedPercent ¶
DiskUsedPercent returns the percent of used disk space (from the program's data root).
func EnableMetricPersistence ¶
EnableMetricPersistence enables metric persistence for metrics that opted for it. They given key is the database key where the metric data will be persisted. This call also directly loads the stored data from the database. The returned error is only about loading the metrics, not about enabling persistence. May only be called once.
func ExportValues ¶
func ExportValues(requestPermission api.Permission, internalOnly bool) map[string]any
ExportValues exports the values of all supported metrics.
func MemAvailable ¶
MemAvailable returns the available system memory.
func MemUsedPercent ¶
MemUsedPercent returns the percent of used system memory.
func SetNamespace ¶
SetNamespace sets the namespace for all metrics. It is prefixed to all metric IDs. It must be set before any metric is registered. Does not affect golang runtime metrics.
func WriteMetrics ¶
func WriteMetrics(w io.Writer, permission api.Permission, expertiseLevel config.ExpertiseLevel)
WriteMetrics writes all metrics that match the given permission and expertiseLevel to the given writer.
Types ¶
type Counter ¶
Counter is a counter metric.
func NewCounter ¶
NewCounter registers a new counter metric.
func (*Counter) CurrentValue ¶
CurrentValue returns the current counter value.
func (Counter) LabeledID ¶
func (m Counter) LabeledID() string
LabeledID returns the Prometheus-compatible labeled ID of the metric.
func (Counter) Opts ¶
func (m Counter) Opts() *Options
Opts returns the metric options. They may not be modified.
func (Counter) WritePrometheus ¶
WritePrometheus writes the metric in the prometheus format to the given writer.
type FetchingCounter ¶
type FetchingCounter struct {
// contains filtered or unexported fields
}
FetchingCounter is a counter metric that fetches the values via a function call.
func NewFetchingCounter ¶
func NewFetchingCounter(id string, labels map[string]string, fn func() uint64, opts *Options) (*FetchingCounter, error)
NewFetchingCounter registers a new fetching counter metric.
func (*FetchingCounter) CurrentValue ¶
func (fc *FetchingCounter) CurrentValue() uint64
CurrentValue returns the current counter value.
func (FetchingCounter) ID ¶
func (m FetchingCounter) ID() string
ID returns the given ID of the metric.
func (FetchingCounter) LabeledID ¶
func (m FetchingCounter) LabeledID() string
LabeledID returns the Prometheus-compatible labeled ID of the metric.
func (FetchingCounter) Opts ¶
func (m FetchingCounter) Opts() *Options
Opts returns the metric options. They may not be modified.
func (*FetchingCounter) WritePrometheus ¶
func (fc *FetchingCounter) WritePrometheus(w io.Writer)
WritePrometheus writes the metric in the prometheus format to the given writer.
type FloatMetric ¶
type FloatMetric interface {
CurrentValue() float64
}
FloatMetric is an interface for special functions of float metrics.
type Gauge ¶
Gauge is a gauge metric.
func NewGauge ¶
func NewGauge(id string, labels map[string]string, fn func() float64, opts *Options) (*Gauge, error)
NewGauge registers a new gauge metric.
func (*Gauge) CurrentValue ¶
CurrentValue returns the current gauge value.
func (Gauge) LabeledID ¶
func (m Gauge) LabeledID() string
LabeledID returns the Prometheus-compatible labeled ID of the metric.
func (Gauge) Opts ¶
func (m Gauge) Opts() *Options
Opts returns the metric options. They may not be modified.
func (Gauge) WritePrometheus ¶
WritePrometheus writes the metric in the prometheus format to the given writer.
type Histogram ¶
Histogram is a histogram metric.
func NewHistogram ¶
NewHistogram registers a new histogram metric.
func (Histogram) LabeledID ¶
func (m Histogram) LabeledID() string
LabeledID returns the Prometheus-compatible labeled ID of the metric.
func (Histogram) Opts ¶
func (m Histogram) Opts() *Options
Opts returns the metric options. They may not be modified.
func (Histogram) WritePrometheus ¶
WritePrometheus writes the metric in the prometheus format to the given writer.
type Metric ¶
type Metric interface { ID() string LabeledID() string Opts() *Options WritePrometheus(w io.Writer) }
Metric represents one or more metrics.
type MetricExport ¶
MetricExport is used to export a metric and its current value.
func ExportMetrics ¶
func ExportMetrics(requestPermission api.Permission) []*MetricExport
ExportMetrics exports all registered metrics.
type Options ¶
type Options struct { // Name defines an optional human readable name for the metric. Name string // InternalID specifies an alternative internal ID that will be used when // exposing the metric via the API in a structured format. InternalID string // AlertLimit defines an upper limit that triggers an alert. AlertLimit float64 // AlertTimeframe defines an optional timeframe in seconds for which the // AlertLimit should be interpreted in. AlertTimeframe float64 // Permission defines the permission that is required to read the metric. Permission api.Permission // ExpertiseLevel defines the expertise level that the metric is meant for. ExpertiseLevel config.ExpertiseLevel // Persist enabled persisting the metric on shutdown and loading the previous // value at start. This is only supported for counters. Persist bool }
Options can be used to set advanced metric settings.
type UIntMetric ¶
type UIntMetric interface {
CurrentValue() uint64
}
UIntMetric is an interface for special functions of uint metrics.