Documentation ¶
Index ¶
- func DecodeExpfmt(r io.Reader, format expfmt.Format) ([]*dto.MetricFamily, error)
- func DecodeJSON(r io.Reader) ([]*dto.MetricFamily, error)
- func EncodeExpfmt(mfs []*dto.MetricFamily, opts ...expfmt.Format) ([]byte, error)
- func EncodeJSON(mfs []*dto.MetricFamily) ([]byte, error)
- func EncodeLineProtocol(mfs []*dto.MetricFamily) ([]byte, error)
- func L(name, value string) *dto.LabelPair
- func NewInfluxCollector(procID platform.IDGenerator, build platform.BuildInfo) prometheus.Collector
- type AddLabels
- type AuthorizationService
- func (s *AuthorizationService) CreateAuthorization(ctx context.Context, a *platform.Authorization) (err error)
- func (s *AuthorizationService) DeleteAuthorization(ctx context.Context, id platform.ID) (err error)
- func (s *AuthorizationService) FindAuthorizationByID(ctx context.Context, id platform.ID) (a *platform.Authorization, err error)
- func (s *AuthorizationService) FindAuthorizationByToken(ctx context.Context, t string) (a *platform.Authorization, err error)
- func (s *AuthorizationService) FindAuthorizations(ctx context.Context, filter platform.AuthorizationFilter, ...) (as []*platform.Authorization, i int, err error)
- func (s *AuthorizationService) PrometheusCollectors() []prometheus.Collector
- func (s *AuthorizationService) UpdateAuthorization(ctx context.Context, id platform.ID, upd *platform.AuthorizationUpdate) (a *platform.Authorization, err error)
- type Encoder
- type EventRecorder
- type Expfmt
- type Filter
- type JSON
- type Labels
- type LineProtocol
- type Matcher
- type RemoveLabels
- type RenameFamilies
- type Transformer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeExpfmt ¶
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 ¶
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 NewInfluxCollector ¶
func NewInfluxCollector(procID platform.IDGenerator, build platform.BuildInfo) prometheus.Collector
NewInfluxCollector returns a collector which exports influxdb process metrics.
Types ¶
type AddLabels ¶
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 ¶
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.
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 Labels ¶
Labels are string representations of a set of prometheus label pairs that are used to match to metric.
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 ¶
Matcher is used to match families of prometheus metrics.
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 ¶
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.