prometheus

package
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeExpfmt

func DecodeExpfmt(r io.Reader, format expfmt.Format) ([]*dto.MetricFamily, error)

DecodeExpfmt decodes the reader of format into metric families.

func DecodeJSON

func DecodeJSON(r io.Reader) ([]*dto.MetricFamily, error)

DecodeJSON decodes a JSON array of metrics families.

func EncodeExpfmt

func EncodeExpfmt(mfs []*dto.MetricFamily, opts ...expfmt.Format) ([]byte, error)

EncodeExpfmt encodes the metrics family (defaults to expfmt.FmtProtoDelim).

func EncodeJSON

func EncodeJSON(mfs []*dto.MetricFamily) ([]byte, error)

EncodeJSON encodes the metric families to JSON.

func EncodeLineProtocol

func EncodeLineProtocol(mfs []*dto.MetricFamily) ([]byte, error)

EncodeLineProtocol converts prometheus metrics into line protocol.

func L

func L(name, value string) *dto.LabelPair

L is used with Family to create a series of label pairs for matching.

func NewInfluxCollector

func NewInfluxCollector(procID platform.IDGenerator, build platform.BuildInfo) prometheus.Collector

NewInfluxCollector returns a collector which exports influxdb process metrics.

Types

type AddLabels

type AddLabels struct {
	Labels map[string]string
}

AddLabels adds labels to all metrics. It will overwrite the label if it already exists.

func (*AddLabels) Transform

func (a *AddLabels) Transform(mfs []*dto.MetricFamily) []*dto.MetricFamily

Transform adds labels to the metrics.

type AuthorizationService

type AuthorizationService struct {
	AuthorizationService platform.AuthorizationService
	// contains filtered or unexported fields
}

AuthorizationService manages authorizations.

func NewAuthorizationService

func NewAuthorizationService() *AuthorizationService

NewAuthorizationService creates an instance of AuthorizationService.

func (*AuthorizationService) CreateAuthorization

func (s *AuthorizationService) CreateAuthorization(ctx context.Context, a *platform.Authorization) (err error)

CreateAuthorization creates an authorization, records function call latency, and counts function calls.

func (*AuthorizationService) DeleteAuthorization

func (s *AuthorizationService) DeleteAuthorization(ctx context.Context, id platform.ID) (err error)

DeleteAuthorization deletes an authorization, records function call latency, and counts function calls.

func (*AuthorizationService) FindAuthorizationByID

func (s *AuthorizationService) FindAuthorizationByID(ctx context.Context, id platform.ID) (a *platform.Authorization, err error)

FindAuthorizationByID returns an authorization given a id, records function call latency, and counts function calls.

func (*AuthorizationService) FindAuthorizationByToken

func (s *AuthorizationService) FindAuthorizationByToken(ctx context.Context, t string) (a *platform.Authorization, err error)

FindAuthorizationByToken returns an authorization given a token, records function call latency, and counts function calls.

func (*AuthorizationService) FindAuthorizations

func (s *AuthorizationService) FindAuthorizations(ctx context.Context, filter platform.AuthorizationFilter, opt ...platform.FindOptions) (as []*platform.Authorization, i int, err error)

FindAuthorizations returns authorizations given a filter, records function call latency, and counts function calls.

func (*AuthorizationService) PrometheusCollectors

func (s *AuthorizationService) PrometheusCollectors() []prometheus.Collector

PrometheusCollectors returns all authorization service prometheus collectors.

func (*AuthorizationService) UpdateAuthorization

func (s *AuthorizationService) UpdateAuthorization(ctx context.Context, id platform.ID, upd *platform.AuthorizationUpdate) (a *platform.Authorization, err error)

UpdateAuthorization updates the status and description.

type Encoder

type Encoder interface {
	// Encode encodes metrics into bytes.
	Encode(mfs []*dto.MetricFamily) ([]byte, error)
}

Encoder transforms metric families into bytes.

type EventRecorder

type EventRecorder struct {
	// contains filtered or unexported fields
}

EventRecorder implements http/metric.EventRecorder. It is used to collect http api metrics.

func NewEventRecorder

func NewEventRecorder(subsystem string) *EventRecorder

NewEventRecorder returns an instance of a metric event recorder. Subsystem is expected to be descriptive of the type of metric being recorded. Possible values may include write, query, task, dashboard, etc.

The general structure of the metrics produced from the metric recorder should be

http_<subsystem>_request_count{org_id=<org_id>, status=<status>, endpoint=<endpoint>} ... http_<subsystem>_request_bytes{org_id=<org_id>, status=<status>, endpoint=<endpoint>} ... http_<subsystem>_response_bytes{org_id=<org_id>, status=<status>, endpoint=<endpoint>} ...

func (*EventRecorder) PrometheusCollectors

func (r *EventRecorder) PrometheusCollectors() []prometheus.Collector

PrometheusCollectors exposes the prometheus collectors associated with a metric recorder.

func (*EventRecorder) Record

func (r *EventRecorder) Record(ctx context.Context, e metric.Event)

Record metric records the request count, response bytes, and request bytes with labels for the org, endpoint, and status.

type Expfmt

type Expfmt struct {
	Format expfmt.Format
}

Expfmt encodes metric families into prometheus exposition format.

func (*Expfmt) Encode

func (e *Expfmt) Encode(mfs []*dto.MetricFamily) ([]byte, error)

Encode encodes metrics into prometheus exposition format bytes.

type Filter

type Filter struct {
	Gatherer prometheus.Gatherer
	Matcher  Matcher
}

Filter filters the metrics from Gather using Matcher.

func (*Filter) Gather

func (f *Filter) Gather() ([]*dto.MetricFamily, error)

Gather filters all metrics to only those that match the Matcher.

Example
package main

import (
	"bytes"
	"fmt"

	"github.com/influxdata/influxdb/v2/prometheus"
	pr "github.com/prometheus/client_golang/prometheus"
	dto "github.com/prometheus/client_model/go"
	"github.com/prometheus/common/expfmt"
)

const metrics = `
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 85
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.11.4"} 1
# HELP storage_compactions_queued Number of queued compactions.
# TYPE storage_compactions_queued gauge
storage_compactions_queued{level="1"} 1
storage_compactions_queued{level="2"} 2
`

func main() {
	mfs, _ := prometheus.DecodeExpfmt(bytes.NewBufferString(metrics), expfmt.FmtText)
	fmt.Printf("Start with %d metric families\n", len(mfs))
	fmt.Printf("%s\n", metrics)

	filter := &prometheus.Filter{
		Gatherer: pr.GathererFunc(func() ([]*dto.MetricFamily, error) {
			return mfs, nil
		}),
		Matcher: prometheus.NewMatcher().
			Family("go_goroutines").
			Family(
				"storage_compactions_queued",
				prometheus.L("level", "2"),
			),
	}

	fmt.Printf("Filtering for the entire go_goroutines family and\njust the level=2 label of the storage_compactions_queued family.\n\n")
	filtered, _ := filter.Gather()
	b, _ := prometheus.EncodeExpfmt(filtered, expfmt.FmtText)

	fmt.Printf("After filtering:\n\n%s", string(b))

}
Output:

Start with 3 metric families

# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 85
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.11.4"} 1
# HELP storage_compactions_queued Number of queued compactions.
# TYPE storage_compactions_queued gauge
storage_compactions_queued{level="1"} 1
storage_compactions_queued{level="2"} 2

Filtering for the entire go_goroutines family and
just the level=2 label of the storage_compactions_queued family.

After filtering:

# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 85
# HELP storage_compactions_queued Number of queued compactions.
# TYPE storage_compactions_queued gauge
storage_compactions_queued{level="2"} 2

type JSON

type JSON struct{}

JSON encodes metric families into JSON.

func (*JSON) Encode

func (j *JSON) Encode(mfs []*dto.MetricFamily) ([]byte, error)

Encode encodes metrics JSON bytes. This not always works as some prometheus values are NaN or Inf.

type Labels

type Labels map[string]bool

Labels are string representations of a set of prometheus label pairs that are used to match to metric.

func (Labels) Match

func (ls Labels) Match(metric *dto.Metric) bool

Match checks if the metric's labels matches this set of labels.

type LineProtocol

type LineProtocol struct{}

LineProtocol encodes metric families into influxdb line protocol.

func (*LineProtocol) Encode

func (l *LineProtocol) Encode(mfs []*dto.MetricFamily) ([]byte, error)

Encode encodes metrics into line protocol format bytes.

type Matcher

type Matcher map[string]Labels // family name to label/value

Matcher is used to match families of prometheus metrics.

func NewMatcher

func NewMatcher() Matcher

NewMatcher returns a new matcher.

func (Matcher) Family

func (m Matcher) Family(name string, lps ...*dto.LabelPair) Matcher

Family helps constuct match by adding a metric family to match to.

func (Matcher) Match

func (m Matcher) Match(mfs []*dto.MetricFamily) []*dto.MetricFamily

Match returns all metric families that match.

type RemoveLabels

type RemoveLabels struct {
	Labels map[string]struct{}
}

RemoveLabels adds labels to all metrics. It will overwrite the label if it already exists.

func (*RemoveLabels) Transform

func (r *RemoveLabels) Transform(mfs []*dto.MetricFamily) []*dto.MetricFamily

Transform removes labels from the metrics.

type RenameFamilies

type RenameFamilies struct {
	FromTo map[string]string
}

RenameFamilies changes the name of families to another name

func (*RenameFamilies) Transform

func (r *RenameFamilies) Transform(mfs []*dto.MetricFamily) []*dto.MetricFamily

Transform renames metric families names.

type Transformer

type Transformer interface {
	// Transform updates the metrics family
	Transform(mfs []*dto.MetricFamily) []*dto.MetricFamily
}

Transformer modifies prometheus metrics families.

Jump to

Keyboard shortcuts

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