monitor

package
v0.0.0-...-432d548 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeGauge   = "gauge"
	TypeSummary = "summary"
	TypeCounter = "counter"
)

The concrete monitor metric type

Variables

This section is empty.

Functions

func Inc

func Inc(fullname string, lvs ...string)

Inc reports a `inc` metric.

func Register

func Register(t Type, fullname string, lbls ...string) error

Register regists a metric.

func Report

func Report(fullname string, v float64, lvs ...string)

Report reports a value for a metric.

func ReportTime

func ReportTime(fullname string, lvs ...string) func()

ReportTime is a util function to report a `used time', e.g: defer ReportTime(xxx)()

Types

type Config

type Config struct {
	Address string
	Port    int
	Service string
	Tags    map[string]string
}

Config is the config to start monitor/metric.

type Counter

type Counter interface {
	Inc()
	Add(float64)
	Set(float64)
}

Counter metric (Gauge&Counter)

type CurryMetric

type CurryMetric struct {
	Func func(lbls ...string) GenericMetric
}

CurryMetric wraps generic metrics. Usage:

counterVec := prometheus.NewCounterVec(...)
factory.Register("count_metric_name", CurryMetric{func (lbls ...string) GenericMetric {
    return counterVec.WithLabelValues(lbls...)
}})

func (CurryMetric) Add

func (c CurryMetric) Add(v float64, lbls ...string)

Add increments the metric by `v`.

func (CurryMetric) Elapsed

func (c CurryMetric) Elapsed(start time.Time, lbls ...string)

Elapsed report an elapsed time in micro-seconds since `start`

func (CurryMetric) Inc

func (c CurryMetric) Inc(lbls ...string)

Inc increments the metric by 1.

func (CurryMetric) Observe

func (c CurryMetric) Observe(f float64, lbls ...string)

Observe set the value.

func (CurryMetric) Set

func (c CurryMetric) Set(v float64, lbls ...string)

Set set the metric value as `v`.

type GenericMetric

type GenericMetric interface{}

GenericMetric generic metric

type MetricFactory

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

MetricFactory provides api to get prometheus metrics by string name.

func NewMetricFactory

func NewMetricFactory() *MetricFactory

NewMetricFactory constructs a new metric factory.

func (*MetricFactory) Get

func (f *MetricFactory) Get(name string) CurryMetric

Get get a metric, return a dummy metric if not existed

func (*MetricFactory) Must

func (f *MetricFactory) Must(name string) CurryMetric

Must get a metric, panic if not existed.

func (*MetricFactory) Register

func (f *MetricFactory) Register(name string, m CurryMetric)

Register registers a metric in this factory.

type Observer

type Observer interface {
	Observe(float64)
}

Observer for Summary metric.

type Type

type Type string

Type Monitor type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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