1. An overview of the

Indicator statistics are the basis for Application Performance Management (APM). By collecting statistics and reporting indicators, we can learn about the running status of programs, discover program problems in time, and predict system bottlenecks in advance. Metrics is currently implemented as metrics, which is a Java implementation that can be imported directly into the program as a library. See Go-metrics for the implementation of go language. In addition, indicators are only processed and calculated in memory here. If we want to display, we need to throw the data out, which can be thrown into the log or into the timing database. Therefore, this article will explain the meaning of each indicator and how to throw the calculated data into the monitoring open-Falcon

2. Statistical method of indicators

2.1 Meters

Used in the measurement, calculation over a period of time is usually used to calculate the interface call frequency, such as the QPS (the number of times per second), mainly divides into rateMean, Rate1 / Rate5 / Rate15 target.

  • The number of RateMean occurrences per unit time, such as 100 deliveries per minute, the value is 100/60.
  • Rate1/Rate5/Rate15 Moving Average in 1 minute /5 minutes /15 minutes,

2.2 Gauges

The e scale is used to measure the instantaneous values. For example, if the memory consumption is measured and reported after a period of time, all data points are the memory values at the corresponding time points, while the evacuation scale has only value indicators. That is, whatever is reported is what is reported.

2.3 the Counter

Counting class statistics, can be added or subtracted, can also be zero operations, all operations are based on the old value. Here you can count the number of registered users for each day by setting it to zero and then incrementing the number of new registered users by 1.

2.4 Histograms

It is used to collect statistics on the value distribution in the data set. The typical application scenario is interface time. Each invocation of an interface generates time. Therefore, the time consumption of the interface in a period of time is regarded as a data set, and indicators such as Count, Min, Max, Mean, Median, 75%, 95% and 99% are collected. Reflect the true state of the data set as much as possible with relatively little resource consumption.

  • Count is the number of samples generated since the last cleanup.
  • Min the minimum value in the sample
  • Max The maximum value in the sample
  • Mean Indicates the Mean of all samples
  • Median Specifies the value in the middle of the sample.
  • The value at %75 in 75% of the sample.
  • The value of the %95 position in the 95% sample.
  • The value of the %99 position in 99% of the sample.

1.5 Timers

The call frequency and call time of a certain code module are counted. Indicators are a combination of Histograms and Meters.

3. Usage

See the Go-Metric documentation for more details

3.1 the Counter

c := metrics.NewCounter()
metrics.Register("foo", c)
// Perform the add operation
c.Inc(47)

// Subtract
c.Dec(1)

// Get the value
c.Count()

Copy the code

3.2 the Gauge

g := metrics.NewGauge()
metrics.Register("bar", g)
// Update the instantaneous value
g.Update(47)

// Get the instantaneous value
g.Value()
Copy the code

3.3 Meters


m := metrics.NewMeter()
metrics.Register("quux", m)
// Write to the data set
m.Mark(47)
// Get a snapshot of the data set
m := metric.Snapshot()
// Data set size
m.Count()
//1 minute moving average
m.Rate1()
// 5-minute moving average
m.Rate5()
// 15-minute moving average
m.Rate15()
/ / the mean
m.RateMean()

Copy the code

3.4 Histograms

h := metrics.NewHistogram(s)
metrics.Register("baz", h)
// Write to the data set
h.Update(47)
// Get a snapshot of the data set
h := metric.Snapshot()
// Data set size
h.Count()
/ / the minimum
h.Min()
/ / Max
h.Max()
/ / the mean
h.Mean()
ps := h.Percentiles([]float64{0.5.0.75.0.95.0.99})
/ / the median
ps[0]
/ / the number of 75%
ps[1]
/ / the number of 95%
ps[2]
/ / the number of 99%
ps[3]

Copy the code

3.5 the Timer

t := metrics.NewTimer()
metrics.Register("bang", t)

t.Time(func(a) {
    //do some thing
})
t.Update(47)

// Use the same method as meter and Histograms
Copy the code

4. Report indicators to open-Falcon

4.1 Reporting Method

See Go-metrics-Falcon for the code and usage

To achieve data reporting to Open-Falcon, you only need to take out all data and report it in open-Falcon format. Here is the definition of JSON reporting, as follows.

{
	"endpoint": "$endpoint"."metric": "$name"."value": 2.2."step": 60."counterType": "GAUGE"."tags": "project=$projectName,metricType=meter,valueType=ratemean"."timestamp": 1524724608
}
Copy the code

Endpoint: This is usually the host hostname, which is used to mark which machine it is. Metric: user-defined indicator name Value: indicator value step: report time period counterType: report type. Open-falcon supports only GAUGE and COUNTER, so GAUGE is used. The tag is used for a specific indicator, including the indicator type, value type, and item name. Timestamp: indicates the timestamp reported by an indicator, in seconds.

4.2 the effect

As shown in the figure, enter the endpoint and then enter the item name in the counter section to filter out all metrics reported by the item.

Click the indicator to enter the larger picture of querying the indicator.

At the same time, we can set up monitoring indicators, as described in open-Falcon documentation.

Reference 5.

metrics

go-metric

APM

open-falcon