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 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 Gauge
- type Histogram
- type Metric
- type Options
Constants ¶
const (
PrometheusFormatRequirement = "^" + prometheusBaseFormt + "$"
)
PrometheusFormatRequirement is required format defined by prometheus for metric and label names.
Variables ¶
var ( CfgOptionInstanceKey = "core/metrics/instance" 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. 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 DiskFree ¶ added in v0.13.2
DiskFree returns the available disk space (from the program's data root).
func DiskTotal ¶ added in v0.13.2
DiskTotal returns the total disk space (from the program's data root).
func DiskUsed ¶ added in v0.13.2
DiskUsed returns the used disk space (from the program's data root).
func DiskUsedPercent ¶ added in v0.13.2
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 MemAvailable ¶ added in v0.13.2
MemAvailable returns the available system memory.
func MemUsedPercent ¶ added in v0.13.2
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) 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 ¶ added in v0.13.2
type FetchingCounter struct {
// contains filtered or unexported fields
}
FetchingCounter is a counter metric that fetches the values via a function call.
func NewFetchingCounter ¶ added in v0.13.2
func NewFetchingCounter(id string, labels map[string]string, fn func() uint64, opts *Options) (*FetchingCounter, error)
NewFetchingCounter registers a new fetching counter metric.
func (FetchingCounter) ID ¶ added in v0.13.2
func (m FetchingCounter) ID() string
ID returns the given ID of the metric.
func (FetchingCounter) LabeledID ¶ added in v0.13.2
func (m FetchingCounter) LabeledID() string
LabeledID returns the Prometheus-compatible labeled ID of the metric.
func (FetchingCounter) Opts ¶ added in v0.13.2
func (m FetchingCounter) Opts() *Options
Opts returns the metric options. They may not be modified.
func (*FetchingCounter) WritePrometheus ¶ added in v0.13.2
func (fc *FetchingCounter) WritePrometheus(w io.Writer)
WritePrometheus writes the metric in the prometheus format to the given writer.
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) 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 Options ¶
type Options struct { // Name defines an optional human readable name for the metric. Name 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.