metrics

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

README

metrics

metrics为监控服务提供了统一的调用接口,主要包括counter,gauge,summary.而且为一些流行的metrics服务提供了适配器.

usage

install:

go get -v -u github.com/bj-wangjia/mtggokit/metrics/metrics

counter usage:

#path: /project/conf/counter.yaml
Open:
    Log: true
    Prometheus: false
    Elasticsearch: true
MonitorSystem:
    Default:
        Namespace: "Test"
        Subsystem: "testCount"
        Help: "just a test"
        Name: "test"
    Elasticsearch:
        Host: "xxxxx.com"
        Port: "8000"
        Index: "metric"
        Type: "metric_test"
        Interval: "10" #时间间隔
    Log:
        LogPath : "./.metricsLog"
        Interval: "10"
import (
    "time"
    "github.com/bj-wangjia/mtggokit/metrics"
)
func main() {
    var logger *log.Logger
    var counter metrics.Counter
    lables := []string{"httpCode", "httpMethod"}
    counter = multi.NewCounter("/project/conf/counter.yaml", lables)
    counter.With({"httpCode":"200","httpMethod":"POST"}).Add(1)
    counter.With({"httpCode":"200","httpMethod":"GET"}).Add(2)
    counter.With({"httpCode":"200","httpMethod":"POST"}).Add(3)
    time.Sleep(1000*time.Second)
}

summary usage:

#path: /project/conf/summary.yaml
Open:
    Log: true
    Prometheus: false
    Elasticsearch: false
MonitorSystem:
    Default:
        Namespace: "summary"
        Subsystem: "summary test"
        Help: "just a test"
        Name: "test"
Metrics:
    Summary:
        Quantile50: 5 #对应分位数的误差
        Quantile90: 2 
        Quantile99: 1 
import (
    "time"
    "github.com/bj-wangjia/mtggokit/metrics"
)
func main() {
    lables := []string{"score"}
    summaries := metrics.NewSummary("/project/conf/summary.yaml", lables)
    summaries.With("score","math").Observe(100)
    summaries.With("score","math").Observe(98)
    summaries.With("score","math").Observe(30)
    summaries.With("score","computer").Observe(30)
    summaries.With("score","computer").Observe(300)
    summaries.With("score","computer").Observe(200)
    time.Sleep(1000*time.Second)
}

Documentation

Overview

Package multi provides adapters that send observations to multiple metrics simultaneously. This is useful if your service needs to emit to multiple instrumentation systems at the same time, for example if your organization is transitioning from one system to another.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

type Counter []metrics.Counter

Counter collects multiple individual counters and treats them as a unit.

func NewCounter

func NewCounter(fileName string, lables []string) Counter

NewCounter returns a multi-counter, wrapping the passed counters.

func (Counter) Add

func (c Counter) Add(delta float64)

Add implements counter.

func (Counter) With

func (c Counter) With(labelValues ...string) metrics.Counter

With implements counter.

type Gauge

type Gauge []metrics.Gauge

Gauge collects multiple individual gauges and treats them as a unit.

func NewGauge

func NewGauge(fileName string, lables []string) Gauge

NewGauge returns a multi-gauge, wrapping the passed gauges.

func (Gauge) Add

func (g Gauge) Add(delta float64)

Add implements metrics.Gauge.

func (Gauge) Set

func (g Gauge) Set(value float64)

Set implements Gauge.

func (Gauge) With

func (g Gauge) With(labelValues ...string) metrics.Gauge

With implements gauge.

type Summary

type Summary []metrics.Histogram

Summary collects multiple individual summaries and treats them as a unit.

func NewSummary

func NewSummary(fileName string, lables []string) Summary

NewSummary returns a multi-summary, wrapping the passed summary.

func (Summary) Observe

func (s Summary) Observe(value float64)

Observe implements Histogram.

func (Summary) With

func (s Summary) With(labelValues ...string) metrics.Histogram

With implements histogram.

Directories

Path Synopsis
internal
lv
Package prometheus provides Prometheus implementations for metrics.
Package prometheus provides Prometheus implementations for metrics.

Jump to

Keyboard shortcuts

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