go go-metrics

 

 go-metrics introduced

go-metrics - Go for a service to do the monitoring application, do statistics, application-level monitoring and measurement.

Source:  https://github.com/rcrowley/go-metrics

Documentation: HTTP  :  //godoc.org/github.com/rcrowley/go-metrics .

Metrics metrics provide five basic types: Gauges, Counters, Histograms, Meters and Timers.

Gauge

Gauge is the simplest type of measure, only a simple return value,
he used to record some of the instantaneous value of an object or thing.
Similar to the program in the constant, constant value.

package main

import (
	"github.com/rcrowley/go-metrics"
)
func main(){
	g := metrics.NewGauge()
	metrics.Register("bar", g)
	g.Update(1)
	print(g.Value())//1
	g.Update(5)
	print(g.Value())//5
} 

Counter

Counter is a simple counter, you can increase and decrease.
Can make changes to the counter inc is by (), and On Dec () method.

package main

import (
	"github.com/rcrowley/go-metrics"
)
func main(){
	c := metrics.NewCounter()
	metrics.Register("foo", c)
	c.Inc(45)
	c.Dec(3)
	print(c.Count())/42
}

Meter

Meters used to measure the averaging process (request per second) a certain period of time, 5, 15 minutes per TPS. For example, a number of service requests, then by instantiating a metrics.meter Meter (), then meter.mark () method will be able to record this request. There are statistics the total number of requests, the average number of requests per second, and most recently 5, 15-minute average TPS.

Meters Tools will help the rate of one event of our statistical system. For example, the number of requests per second (TPS), the number of queries per second (QPS) and so on. This indicator can reflect current processing capacity of the system to help us determine whether resources have been insufficient. Meters Itself is an incrementing counter.
package main

import (
	"time"
	"os"
	"github.com/rcrowley/go-metrics"
	"log"
)

func main(){

	m := metrics.NewMeter()
	metrics.Register("quux", m)
	m.Mark(1)


	go metrics.Log(metrics.DefaultRegistry,
		1 * time.Second,
		log.New(os.Stdout, "metrics: ", log.Lmicroseconds))


	var j int64
	j = 1
	for true {
		time.Sleep(time.Second * 1)
		j++
		m.Mark(j)
	}
} 

Histrogram

Histrogram is used to measure the distribution of stream data of Value, Histrogram calculate the maximum / minimum value, average value, variance, percentile (e.g., median, or 95th percentile), e.g., 75%, 90%, 98 %, 99%, in which range the data.

Timer

Timer is a combination of Histogram with Meter, such as statistical rate and processing time to the current request.

 

Guess you like

Origin www.cnblogs.com/-wenli/p/12409018.html
Go