当前位置:网站首页>14.1.1 promethues monitoring, four data types metrics, pushgateway
14.1.1 promethues monitoring, four data types metrics, pushgateway
2022-06-26 00:05:00 【Loves_ dccBigData】
1、4 Common use Metrics
1)Counter
Continuously increasing a counter that does not decrease , It can be used to record types that only increase but not decrease , for example : Number of visitors to the site , System running time, etc .
about Counter Indicators of type , Contains only one inc() Methods , It's used for counters +1.
generally speaking ,Counter Type of metric Indicators are used in the dark _total end , Such as http_requests_total.
2)Gauge
A dashboard that can be added or subtracted , diagram
For such indicators that can be increased or decreased , Used to reflect the current state of the application .
For example, when monitoring the host , The current idle memory size of the host , Available memory size, etc .
about Gauge The object of the indicator contains two main methods inc() and dec(), Used to increase and decrease counts .
3)Histogram
It is mainly used to count the distribution of data , This is a special metrics data type , Represents an approximate percentage estimate , Count the times of all discrete indicator data in each value range . for example : We want to make statistics for a period of time http The request response is less than 0.005 second 、 Less than 0.01 second 、 Less than 0.025 Second data distribution . So use Histogram Every acquisition http Requested time , Simultaneous setting bucket.
4)Summary
Summary and Histogram Very similar , You can count the number or size of events , And its distribution , They all provide a count of time _count And a summary of the values _sum, It also provides the function of calculating the distribution of statistical samples , The difference is Histogram Can pass histogram_quantile The quantile() function calculates the quantile on the server . and Sumamry The quantile of is defined directly on the client . So for the quantile calculation ,Summary Through PromQL Better performance when querying , and Histogram It will consume more resources , But relative to the client Histogram Less resources are consumed . You can use either , It can be adjusted freely according to the actual scene .
2、 be based on SpringBoot Write a simple exporter
1)pom.xml The configuration is as follows
4 individual prometheus The dependent package and two pushgateway The dependency package of
<!-- Prometheus relied on -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_spring_boot</artifactId>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_servlet</artifactId>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_pushgateway</artifactId>
<version>0.4.0</version>
</dependency>
<!--springboot-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
2)Application Class annotation
add to @EnableScheduling Annotations mainly add scheduled tasks , Used to dynamically simulate changes in data , You will see the application later
@SpringBootApplication
@EnableScheduling
@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
public class ExporterDemoApplication{
public static void main(String[] args) {
SpringApplication.run(ExporterDemoApplication.class, args);
}
}
3)CounterTest
Define a Counter Type of metrics, generally speaking ,Counter Type of metrics In the naming of indicators, we use _total end .
@RestController
public class CounterTest {
/* * Use Counter.build() establish Counter Type of monitoring indicators , And through name() Method defines the name of the monitoring indicator network_traffic_input * , adopt labelNames() Define the labels included in this indicator . Finally through register() Register the indicator to Collector Of defaultRegistry in */
static final Counter counterDemo = Counter.build()
.name("counterChanger_job").labelNames("ddd","ccc","unit")
.help("Counter example ").register();
// Indicators buried point , The timer will cause Prometheus to be out of sync with the local data timestamp , Try not to use this way , The timer in the example is for data demonstration
@Scheduled(cron="0/5 * * * * ?")
@RequestMapping("/changeCounter")
public void changeCounter(){
counterDemo.labels(" label 1"," label 2","seconds").inc();// The index value increases
}
}
Here every 5 Seconds will be executed automatically changeCounter Used to simulate changes in data
4)GaugeTest
@RestController
public class GaugeTest {
/** Indicator registration * name Set the index name * labelNames Set the name of each indicator * help Set indicator description */
static final Gauge gaugeDemo = Gauge.build()
.name("gaugeDemo")
.labelNames("label1","label2","label3","label4","label5")
.help("gauge example ").register();
// Indicators buried point
@Scheduled(cron="0/5 * * * * ?")
@RequestMapping("/changeGauge")
public void changeGauge() {
gaugeDemo.labels("1","2","3","4","5").inc(); // Index value plus 1
gaugeDemo.labels("1","2","3","4","5").dec(); // The index value is reduced by one
gaugeDemo.labels("1","2","3","4","5").set(19.00); // The indicator value is directly assigned
}
}
Gauge Type of metrics Data can be added 、 Reduction and direct assignment . This type is more common in practical applications
5)HistogramTest
@RestController
public class HistogramTest
{
/** * register * Registration time buckets() Set interval value , The following settings 100、200、300 Three interval values */
static final Histogram histogramDemo = Histogram.build()
.labelNames("label1", "label2", "label3", "label4", "label5")
.name("histogramDemo")
.buckets(100, 200, 300)
.help("Histogram example ")
.register();
// Indicators buried point
@Scheduled(cron = "0/5 * * * * ?")
public void changeHistogram()
{
/** * The index value implemented this time * Set as 150, Every time , Less than 200 Interval and less than 300 Interval plus 1, Less than 100 Interval invariant */
histogramDemo.labels("1", "2", "3", "4", "5").observe(150);
}
}
6)SummaryTest
@RestController
public class SummaryTest {
// register
static final Summary summaryDemo = Summary.build()
.quantile(0.5, 0.01) // add to 50% quantile , Allow 5% The error of the , Equivalent to finding the median
.quantile(0.9, 0.01) // add to 90% quantile , Allow 1% The error of the
.name("summaryDemo").labelNames("label1","label2","label3","label4","label5")
.help("Summary example ").register();
// Indicators buried point
@Scheduled(cron="0/5 * * * * ?")
public void changeSummary(){
summaryDemo.labels("1","2","3","4","5").observe(1);
}
}
stay prometheus Of Graph View through summaryDemo、summaryDemo_count、summaryDemo_sum View the corresponding results
7)pushgateway
@Component
public class PrometheusConfig
{
public static final Counter counterDemo = Counter.build()
.name("push_way_counter")
.labelNames("wy","zxjr","ocs","xxjf","unit","instance")
.help("Counter example ")
.register();
// Test send
public static void main(String[] args)
{
PushGateway prometheusPush = new PushGateway("localhost:9091");
try
{
for(int i=0;i<50;i++){
counterDemo.labels(" Network element "," Online access ","OCS"," Message billing ","byte","localhsot:9091").inc();
prometheusPush.push(counterDemo,"sp-getway");
Thread.sleep(5000);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
reference :
边栏推荐
- Understanding of pseudo classes
- Realize the conversion between analog quantity value and engineering quantity value in STEP7_ Old bear passing by_ Sina blog
- 10.2.3、Kylin_kylin的使用,维度必选
- STEP7 master station and remote i/o networking_ Old bear passing by_ Sina blog
- redis之集群
- 记录一下刷LeetCode瞬间有思路的一道简单题——剑指 Offer 09. 用两个栈实现队列
- [reprint]rslogix 5000 instance tutorial
- 11.1.2、flink概述_Wordcount案例
- JS中的数字数组去重
- postman如何测试需要登录的接口
猜你喜欢

Redis之跳跃表

Unsigned and signed vernacular

Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or

Connecting MySQL database with VBScript_ Old bear passing by_ Sina blog

Lazy people teach you to use kiwi fruit to lose 16 kg in a month_ Old bear passing by_ Sina blog

STEP7主站与远程I/O组网_过路老熊_新浪博客

10.4.1、数据中台

《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)

Studio5k v28安装及破解_过路老熊_新浪博客
![寻找翻转数组的最小值[抽象二分]](/img/b9/1e0c6196e6dc51ae2c48f6c5e83289.png)
寻找翻转数组的最小值[抽象二分]
随机推荐
寻找翻转数组的最小值[抽象二分]
About Simple Data Visualization
Tensorflow中CSV文件数据读取
How to configure SQL Server 2008 Manager_ Old bear passing by_ Sina blog
Raspberry pie sends hotspot for remote login
在win10下使用visual studio2015链接mysql数据库
常用的几款富文本编辑器
PHP interprocess pass file descriptor
如何配置SQL Server 2008管理器_过路老熊_新浪博客
Literature research (II): quantitative evaluation of building energy efficiency performance based on short-term energy prediction
[wechat official account H5] generates a QR code with parameters to enter the official account attention page to listen to user-defined menu bar for official account events (server)
final和static
Studio5k V28 installation and cracking_ Old bear passing by_ Sina blog
【微信公众号H5】 生成带参数进入公众号关注页的二维码 监听用户关注公众号事件 自定义菜单栏 (服务端)
关于scrapy爬虫时,由spider文件将item传递到管道的方法注意事项
搜索旋转数组II[抽象二分练习]
手工制作 pl-2303hx 的USB转TTL电平串口的电路_过路老熊_新浪博客
Circuit de fabrication manuelle d'un port série de niveau USB à TTL pour PL - 2303hx Old bear passing Sina blog
Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or
Recommended system design