metrics

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: May 25, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

README

监控

package main

import (
    "github.com/joshqu1985/fireman/configor"
    "github.com/joshqu1985/fireman/metrics"
)

type Config struct {
    Metrics  metrics.Config
}

var (
    Conf Config
)

func init() {
    if err := configor.Load("./configs/conf.toml", &Conf); err != nil {
        panic(err)
    }

    // 第二个参数用于设置自定义监控项
    if err := metrics.Init(Conf.Metrics); err != nil {
        panic(err)
    }
}

func main() {

    // 增加计数
    metrics.IncrCounterVec("http_client_count", []string{"method", "code"}, 1, []string{"list", "200"})
    metrics.IncrCounterVec("http_client_count", []string{"method", "code"}, 2, []string{"list", "400"})
 
    // 统计时间
    metrics.ObserveHistogramVec("http_client_time", []string{"method"}, 13, []string{"list"})
}
//conf.toml
[metrics]
    pull_port = 9191
    push_url  = ""
    push_name = ""
    interval  = 60 * 1000 # ms

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultInterval = time.Duration(60 * time.Second)
)

Functions

func IncrCounterVec

func IncrCounterVec(name string, labels []string, val float64, lvs []string)

func Init

func Init(conf Config) (err error)

func ObserveHistogramVec

func ObserveHistogramVec(name string, labels []string, val float64, lvs []string)

func SetGaugeVec

func SetGaugeVec(name string, labels []string, val float64, lvs []string)

Types

type Config

type Config struct {
	PullPort int64  `toml:"pull_port"`
	PushName string `toml:"push_name"`
	PushURL  string `toml:"push_url"`
	Interval int64  `toml:"interval"` // ms
}

type PrometheusMetric

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

func NewPrometheusMetric

func NewPrometheusMetric(expire time.Duration) (*PrometheusMetric, error)

func (*PrometheusMetric) Collect

func (p *PrometheusMetric) Collect(c chan<- prometheus.Metric)

func (*PrometheusMetric) Describe

func (p *PrometheusMetric) Describe(c chan<- *prometheus.Desc)

func (*PrometheusMetric) IncrCounterVec

func (p *PrometheusMetric) IncrCounterVec(name string, labels []string, val float64, lvs []string)

func (*PrometheusMetric) ObserveHistogramVec

func (p *PrometheusMetric) ObserveHistogramVec(name string, labels []string, val float64, lvs []string)

func (*PrometheusMetric) SetGaugeVec

func (p *PrometheusMetric) SetGaugeVec(name string, labels []string, val float64, lvs []string)

Jump to

Keyboard shortcuts

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