当前位置:网站首页>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 :
边栏推荐
- Common methods of object class
- Using Google protobuf protocol environment configuration in PHP
- keil编译运行错误,缺少error:#5:#includecore_cm3.h_过路老熊_新浪博客
- Oracle writes a trigger that inserts a piece of data first and updates a field in the data
- Studio5k V28 installation and cracking_ Old bear passing by_ Sina blog
- P3052 [USACO12MAR]Cows in a Skyscraper G
- dhcp复习
- Format the number. If the number is not enough, fill in 0, for example, 1:0001,25:0025
- postman如何测试需要登录的接口
- redis之详解
猜你喜欢
![[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)](/img/d9/935bad29005e5846dc514c966e3b0e.png)
[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)

DNS复习
![Bit Compressor [蓝桥杯题目训练]](/img/d5/231d20bf4104cc2619b2a4f19b605c.png)
Bit Compressor [蓝桥杯题目训练]

Building cloud computers with FRP

Line height for small use

文獻調研(三):數據驅動的建築能耗預測模型綜述

手工制作 pl-2303hx 的USB轉TTL電平串口的電路_過路老熊_新浪博客

Installation of third-party library iGraph for social network visualization

unsigned与signed之大白话

Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or
随机推荐
用frp搭建云电脑
记录一下刷LeetCode瞬间有思路的一道简单题——剑指 Offer 09. 用两个栈实现队列
SSM整合学习笔记(主要是思路)
搜索旋转数组II[抽象二分练习]
JS中常用知识点
懒人教你用猕猴桃一月饱减16斤_过路老熊_新浪博客
Literature research (IV): Hourly building power consumption prediction based on case-based reasoning, Ann and PCA
Using Google protobuf protocol environment configuration in PHP
About the solution to prompt modulenotfounderror: no module named'pymongo 'when running the scratch project
Some common operation methods of array
huibian
10.3.1、FineBI_finebi的安装
Studio5k V28 installation and cracking_ Old bear passing by_ Sina blog
step7和wincc联合仿真_过路老熊_新浪博客
Building cloud computers with FRP
Installation of third-party library iGraph for social network visualization
Prototype chain test questions in JS --foo and getname
Literature research (III): overview of data-driven building energy consumption prediction models
Unable to start debugging. Unexpected GDB output from command “-environment -cd xxx“ No such file or
Redis之跳跃表