prometheus

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: Apache-2.0, MIT Imports: 20 Imported by: 0

README

English | 中文

tRPC-Go prometheus metrics plugin

Go Reference Go Report Card LICENSE Releases Docs Tests Coverage

Config

plugins:                                          #Plugin configuration.
  metrics:                                        #Reference metrics.
    prometheus:                                   #Start prometheus.
      ip: 0.0.0.0                                 #Prometheus bind address.
      port: 8090                                  #Prometheus bind port.
      path: /metrics                              #Metrics path.
      namespace: Development                      #Namespace.
      subsystem: trpc                             #Subsystem.
      rawmode:   false                            #Raw mode, no conversion of special characters for metrics.
      enablepush: true                            #Enable push mode, not enabled by default.
      gateway: http://localhost:9091              #Prometheus gateway address.
      password: username:MyPassword               #Set the account password, username and MyPassword are split by a colon.
      job: job                                    #Job name.
      pushinterval: 1                             #Push data every 1 second by default

Tutorial

Reference prometheus

Reference it in main.go and configure the parameters in yaml.

import _ "trpc.group/trpc-go/trpc-metrics-prometheus"
Report data

trpc metrics usage guidelines trpc metrics

Query reported data

Query the metrics locally via curl to see if the metrics were generated successfully.

curl ${ip}:${port}/$path |grep ${namespace}_${subsystem}

Report call data

Add configuration

  filter:
    - prometheus                                   #Add prometheus filter

The call data currently supports both Histogram for request time and SUM for request volume. The metric names are prefixed with ClientFilter and ServerFilter.

Notice

  1. Prometheus currently only supports PolicySUM/PolicySET/PolicyHistogram type reporting, other types of support please submit pr.
  2. Prometheus metric does not support Chinese and special characters, illegal characters will be automatically converted to '' in the acsii table, Chinese and other utf8 characters are converted to the corresponding data, such as "trpc.Chinese metric" -> "trpc_20013_25991_25351_26631", close this function can be used to set rawmode is true, exception reporting will fail directly.
  3. The plugin only provides exporter, not Pushgateway and Prometheus server.
  4. Multi-dimension reporting uses the metrics.NewMultiDimensionMetricsX interface to set multi-dimension names, otherwise conflicts may occur.
  5. If you need to push custom data, you can call the GetDefaultPusher method after the plugin is initialized, otherwise the returned pusher is empty.

Documentation

Overview

Package prometheus is a tRPC metric filter that provides prometheus exporter, Sink and Labels feature.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientFilter

func ClientFilter(ctx context.Context, req, rsp interface{}, handler filter.ClientHandleFunc) error

ClientFilter client filter for prome.

func GetDefaultPusher

func GetDefaultPusher() *push.Pusher

GetDefaultPusher get default pusher.

func NewMetricsCache

func NewMetricsCache() *metricsCache

NewMetricsCache Create Cache

func ServerFilter

func ServerFilter(ctx context.Context, req interface{}, handler filter.ServerHandleFunc) (rsp interface{}, err error)

ServerFilter server filter for prome.

func SetClientBounds

func SetClientBounds(b metrics.BucketBounds)

SetClientBounds set client filter buckets.

func SetServerBounds

func SetServerBounds(b metrics.BucketBounds)

SetServerBounds set server filter buckets.

Types

type Config

type Config struct {
	IP           string `yaml:"ip"`           //metrics monitoring address.
	Port         int32  `yaml:"port"`         //metrics listens to the port.
	Path         string `yaml:"path"`         //metrics path.
	Namespace    string `yaml:"namespace"`    //formal or test.
	Subsystem    string `yaml:"subsystem"`    //default trpc.
	RawMode      bool   `yaml:"rawmode"`      //by default, the special character in metrics will be converted.
	EnablePush   bool   `yaml:"enablepush"`   //push is not enabled by default.
	Password     string `yaml:"password"`     //account Password.
	Gateway      string `yaml:"gateway"`      //push gateway address.
	PushInterval uint32 `yaml:"pushinterval"` //push interval,default 1s.
	Job          string `yaml:"job"`          //reported task name.
}

Config config struct.

func (Config) Default

func (c Config) Default() *Config

Default set default values

type Plugin

type Plugin struct {
}

Plugin plugin obj

func (*Plugin) Setup

func (p *Plugin) Setup(name string, decoder plugin.Decoder) error

Setup init plugin

func (*Plugin) Type

func (p *Plugin) Type() string

Type plugin type

type Sink

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

Sink struct

func GetDefaultPrometheusSink

func GetDefaultPrometheusSink() *Sink

GetDefaultPrometheusSink get prome sink.

func (*Sink) GetMetricsName

func (s *Sink) GetMetricsName(m *metrics.Metrics) string

GetMetricsName returns metrics name.

func (*Sink) Name

func (s *Sink) Name() string

Name return sink name.

func (*Sink) Report

func (s *Sink) Report(rec metrics.Record, opts ...metrics.Option) error

Report report.

func (*Sink) ReportSingleLabel

func (s *Sink) ReportSingleLabel(rec metrics.Record, opts ...metrics.Option) error

ReportSingleLabel single indicator report.

Jump to

Keyboard shortcuts

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