prometheus

package
v0.0.0-...-e86600b Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 1 Imported by: 0

README

prometheus

1. 配置

// 添加配置
prometheus:
  addr: :12112      # 监听地址
  path: /metrics    # metrics路径

2. 代码

1. 读取配置
import "github.com/Baal19905/playground/pkg/prometheus"

// 在配置中添加Prometheus对象
type Config struct {
    // ...
    Prometheus prometheus.Prometheus `mapstructure:"prometheus"`
    // ...
}

// load config
2. 启动Prometheus agent
import "github.com/Baal19905/playground/pkg/prometheus"

// 加载配置后
func Run() {
    // ...
    if prom.HasPrometheus() {
		ctx.C.Prometheus.Start()
    }
    // ...
}
3. 记录指标
import "github.com/Baal19905/playground/pkg/prometheus"

// 初始化指标
func (j *job) Init() {
    // ...
    j.c = prometheus.NewCounter("name","help", "label1","label2")
    // ...
}

// 记录指标
func (j *job) Run() {
    // ...
    j.c.Inc("value1", "value2")
    // ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Addr string `mapstructure:"addr"`
	Path string `mapstructure:"path"`
}

type Counter

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

func NewCounter

func NewCounter(name, help string, label ...string) *Counter

func (*Counter) Add

func (c *Counter) Add(val float64, labelVal ...string)

func (*Counter) Inc

func (c *Counter) Inc(labelVal ...string)

func (*Counter) Unregister

func (c *Counter) Unregister()

type Gauge

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

func NewGauge

func NewGauge(name, help string, label ...string) *Gauge

func (*Gauge) Add

func (g *Gauge) Add(val float64, labelValue ...string)

func (*Gauge) Dec

func (g *Gauge) Dec(labelValue ...string)

func (*Gauge) Inc

func (g *Gauge) Inc(labelValue ...string)

func (*Gauge) Sub

func (g *Gauge) Sub(val float64, labelValue ...string)

func (*Gauge) Unregister

func (g *Gauge) Unregister()

type Histogram

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

func NewHistogram

func NewHistogram(name, help string, label ...string) *Histogram

func (*Histogram) Observe

func (h *Histogram) Observe(val float64, labelValue ...string)

func (*Histogram) Unregister

func (h *Histogram) Unregister()

type Summary

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

func NewSummary

func NewSummary(name, help string, label ...string) *Summary

func (*Summary) Observe

func (s *Summary) Observe(val float64, labelValue ...string)

func (*Summary) Unregister

func (s *Summary) Unregister()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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