prom

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MetricSeconds = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Namespace: "server",
		Subsystem: "requests",
		Name:      "duration_ms",
		Help:      "server requests duration(ms).",
		Buckets:   []float64{5, 10, 25, 50, 100, 250, 500, 1000},
	}, []string{"kind", "operation"})

	MetricRequests = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: "client",
		Subsystem: "requests",
		Name:      "code_total",
		Help:      "The total number of processed requests",
	}, []string{"kind", "operation", "code", "reason"})

	// 这个变量需要改代码
	MetricCPU = NewXCollector(XCollectorOpts{})
)
View Source
var (
	// LibClient for mc redis and db client.
	LibClient = New().WithTimer("go_lib_client", []string{"method"}).WithState("go_lib_client_state", []string{"method", "name"}).WithCounter("go_lib_client_code", []string{"method", "code"})
	// RPCClient rpc client
	RPCClient = New().WithTimer("go_rpc_client", []string{"method"}).WithState("go_rpc_client_state", []string{"method", "name"}).WithCounter("go_rpc_client_code", []string{"method", "code"})
	// HTTPClient http client
	HTTPClient = New().WithTimer("go_http_client", []string{"method"}).WithState("go_http_client_state", []string{"method", "name"}).WithCounter("go_http_client_code", []string{"method", "code"})
	// HTTPServer for http server
	HTTPServer = New().WithTimer("go_http_server", []string{"user", "method"}).WithCounter("go_http_server_code", []string{"user", "method", "code"})
	// RPCServer for rpc server
	RPCServer = New().WithTimer("go_rpc_server", []string{"user", "method"}).WithCounter("go_rpc_server_code", []string{"user", "method", "code"})
	// BusinessErrCount for business err count
	BusinessErrCount = New().WithCounter("go_business_err_count", []string{"name"}).WithState("go_business_err_state", []string{"name"})
	// BusinessInfoCount for business info count
	BusinessInfoCount = New().WithCounter("go_business_info_count", []string{"name"}).WithState("go_business_info_state", []string{"name"})
	// CacheHit for cache hit
	CacheHit = New().WithCounter("go_cache_hit", []string{"name"})
	// CacheMiss for cache miss
	CacheMiss = New().WithCounter("go_cache_miss", []string{"name"})
)

Functions

func NewXCollector

func NewXCollector(opts XCollectorOpts) prometheus.Collector

NewProcessCollector returns a collector which exports the current state of process metrics including CPU, memory and file descriptor usage as well as the process start time. The detailed behavior is defined by the provided ProcessCollectorOpts. The zero value of ProcessCollectorOpts creates a collector for the current process with an empty namespace string and no error reporting.

The collector only works on operating systems with a Linux-style proc filesystem and on Microsoft Windows. On other operating systems, it will not collect any metrics.

Types

type Prom

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

Prom struct info

func New

func New() *Prom

New creates a Prom instance.

func (*Prom) Add

func (p *Prom) Add(name string, v int64, extra ...string)

Add add count v must > 0

func (*Prom) Decr

func (p *Prom) Decr(name string, extra ...string)

Decr decrements one stat counter without sampling

func (*Prom) Incr

func (p *Prom) Incr(name string, extra ...string)

Incr increments one stat counter without sampling

func (*Prom) State

func (p *Prom) State(name string, v int64, extra ...string)

State set state

func (*Prom) Timing

func (p *Prom) Timing(name string, time int64, extra ...string)

Timing log timing information (in milliseconds) without sampling

func (*Prom) WithCounter

func (p *Prom) WithCounter(name string, labels []string) *Prom

WithCounter sets counter.

func (*Prom) WithState

func (p *Prom) WithState(name string, labels []string) *Prom

WithState sets state.

func (*Prom) WithTimer

func (p *Prom) WithTimer(name string, labels []string) *Prom

WithTimer with summary timer

type XCollectorOpts

type XCollectorOpts struct {
	// PidFn returns the PID of the process the collector collects metrics
	// for. It is called upon each collection. By default, the PID of the
	// current process is used, as determined on construction time by
	// calling os.Getpid().
	PidFn func() (int, error)
	// If non-empty, each of the collected metrics is prefixed by the
	// provided string and an underscore ("_").
	Namespace string
	// If true, any error encountered during collection is reported as an
	// invalid metric (see NewInvalidMetric). Otherwise, errors are ignored
	// and the collected metrics will be incomplete. (Possibly, no metrics
	// will be collected at all.) While that's usually not desired, it is
	// appropriate for the common "mix-in" of process metrics, where process
	// metrics are nice to have, but failing to collect them should not
	// disrupt the collection of the remaining metrics.
	ReportErrors bool
}

ProcessCollectorOpts defines the behavior of a process metrics collector created with NewProcessCollector.

Jump to

Keyboard shortcuts

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