Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use go to monitor the statsd of a solution

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to use the statsd of go monitoring scheme". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Statsd

Statsd is also a data acquisition tool.

In a narrow sense, statsd is actually a daemon that listens to UDP (default) or TCP, collects data sent by statsd clients according to a simple protocol, aggregates it, and then regularly pushes it to the backend, such as graphite and influxdb, and then displays it through grafana.

Statsd actually has a lot of third-party packages to collect data, but statsd supports fewer types and only four metrics, so I only use statsd as the transport protocol for data transfer. Therefore, we do not directly use the four third-party packages described below.

Git officially introduces four kinds, address: https://github.com/statsd/statsd/wiki#client-implementations

Statsd

Statsd: https://github.com/alexcesaro/statsd

Statsd: https://github.com/quipo/statsd

G2s: https://github.com/peterbourgon/g2s

Go-statsd-client: https://github.com/cactus/go-statsd-client (use this recommended directly)

Protocol: | [| @ sample_rate]

Bucket is an identity of metric and can be regarded as a variable of metric.

Value: the value of metric, usually a number.

There are usually four types of metric: timer, counter, gauge and set.

Sample_rate

Sample_rate

If the amount of data reported is too large, it is easy to overflow statsd. So appropriately reduce the sampling, reduce the server load.

The client reduces the frequency of data reporting, and then adds a sampling frequency, such as 0.1, to the transmitted data. After statsd server receives the reported data, such as cnt=10, it is known that the data is sampled, and then when flush, the data is recovered according to the sampling frequency and sent to backend, that is, when flush, the data is cnt=10/0.1=100, rather than the easily misunderstood 10: 0.1 / 1.

The main function of this parameter is to reduce the transmission bandwidth of the network. For example, 0.5 means that the UDP packet is reduced by half, at the expense of reduced accuracy. For the client, if 0.5 is set, it means that the statistics are sent only 50% of the time before; on the server side, some corrections are made based on the sampling value, which is simply multiplied by 2.

In fact, the sending probability is calculated each time the sending interface is called on the client.

UDP and TCP

Statsd can be configured with the corresponding server of UDP and TCP. Default is UDP

UDP does not need to establish a connection, is very fast, and does not affect the performance of the application.

The "fire-and-forget" mechanism, even if the statsd server fails, does not cause the application to crash.

UDP is more suitable for scenarios with high reporting frequency. It doesn't matter if you lose a few packets. For some scenarios that have been reported in a day, any packet loss will have a great impact.

Scenarios with poor network environment are suitable for TCP, and will be retransmitted accordingly to ensure reliable data.

UDP is recommended. TCP still has many drawbacks. Default port

By default, statsd listens to 8125 to collect udp packages.

Port: 8125 indicator metric

Data types supported by statsd:

Metric_types

Counting: gorets:1 | cSampling: gorets:1 | c | @ 0.1Timing: glork:320 | ms | @ 0.1Gauges: gaugor:333 | gSets: uniques:765 | s

Multi-Metric Packets

Gorets:1 | c\ nglork:320 | ms\ ngaugor:333 | g\ nuniques:765 | sCounting

An indicator of the counter type, used to count. Add up the reported values in a flush range. The value can be positive or negative.

User.logins:10 | c / / user.logins + 10user.logins:-1 | c / / user.logins-1 user.logins:10 | c | @ 0.1 / / user.logins + 100 / / users.logins = 10-1+100=109Timing

Timers is used to record the time (in ms) of an operation. Statsd records the average value (mean), maximum value (upper), minimum value (lower), cumulative value (sum), sum of squares (sum_squares), number (count), and some percentage values.

Rpt:100 | g

The following is that during a flush, a timer value of 100 for a rpt is sent. The following are the recorded values.

Count_80: 1, mean_80: 100,upper_80: 100,sum_80: 100,sum_squares _ 80: 10000, std: 0,upper: 100,lower: 100,count: 1,count_ps: 0.1,sum: 100,sum_squares: 10000,mean: 100,median: 100Gauges

Gauge is an arbitrary one-dimensional scalar value. The gague value will not be cleared to zero at flush like other types, but will remain the original value. Statsd only sends the last value in the flush range to the backend. In addition, if the value is preceded by a symbol, it will be accumulated with the previous value.

Age:10 | g / / age is 10age:+1 | g / / age is 10 + 1 = 11age:-1 | g / / age is 11-1 = 10age:5 | g / / age is 5, replacing the previous value Sets

Record values that are not duplicated during flush.

Statistics can be made for a certain set to count how many kinds of values have appeared.

Request:1 | s / / user 1request:2 | s / / user1 user2request:1 | s / / user1 user2 "how to use the statsd of go Monitoring solution" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report