当前位置:网站首页>Boot - Prometheus push gateway use
Boot - Prometheus push gateway use
2022-07-07 01:08:00 【iiaythi】
boot - prometheus-push gateway Use
scene
General , If you use prometheus Integrate boot application , Need stay prometheus Middle configuration A task , If the application quite a lot , This is not convenient , You can use prometheus push gateway
Data flow :
- prometheus push gateway Scheduled tasks from boot application Data collection
- prometheus towards push gateway Pull data regularly in
- grafana Do a data show
docker establish prometheus push gateway
docker-compose.yml The configuration file
version: '3.7'
networks:
monitor:
driver: bridge
services:
prometheus:
image: prom/prometheus
container_name: prometheus
hostname: prometheus
restart: always
user: root
volumes:
- ./prometheus/conf:/etc/prometheus
- ./prometheus/data:/prometheus
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
ports:
- "9090:9090"
networks:
- monitor
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
pushgateway:
image: prom/pushgateway
restart: always
ports:
- 9091:9091
volumes:
- ./pushgateway/data:/pushgateway
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
networks:
- monitor
alertmanager:
image: prom/alertmanager
container_name: alertmanager
hostname: alertmanager
user: root
restart: always
volumes:
- ./alertmanager/conf:/etc/alertmanager
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
ports:
- "9094:9093"
networks:
- monitor
grafana:
image: grafana/grafana
container_name: grafana
hostname: grafana
user: root
restart: always
ports:
- "3000:3000"
volumes:
- ./grafana/data:/var/lib/grafana
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
networks:
- monitor
node-exporter:
image: quay.io/prometheus/node-exporter
container_name: node-exporter
hostname: node-exporter
restart: always
user: root
ports:
- "9100:9100"
networks:
- monitor
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
To configure prometheus
prometheus.yaml
$ cat prometheus/conf/prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first.rules"
# - "second.rules"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus' # prometheus Address
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['192.xxx.xx.10:9090']
- job_name: 'pushgateway' # push-gateway Address
scrape_interval: 15s
static_configs:
- targets: ['192.xx.xx.10:9091']
boot Integrate prometheus gateway
Introduce dependencies
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient_pushgateway -->
// push gateway client
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_pushgateway</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
application.properties To configure
spring.application.name=boot-prometheus-gw
management.metrics.tags.application=${spring.application.name}
# expose promethues Endpoint
management.endpoints.web.exposure.include=*
management.endpoint.shutdown.enabled=true
management.endpoint.metrics.enabled=true
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true
## Appoint prometheus gateway Address
management.metrics.export.prometheus.pushgateway.base-url=192.1xx.x.10:9091
management.metrics.export.prometheus.pushgateway.push-rate=15s
## Escalation service name
management.metrics.export.prometheus.pushgateway.job=${spring.application.name}
management.metrics.export.prometheus.pushgateway.enabled=true
server.port=9998
Data statistics
@RestController
public class HelloController {
@Autowired
private MeterRegistry meterRegistry;
public HelloController(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
}
@GetMapping("/get")
public String get() throws InterruptedException {
Counter counter = Counter.builder("hello-counter").register(meterRegistry);
counter.increment();
TimeUnit.SECONDS.sleep(1);
return "Hello, counter = " + counter.count();
}
}
visit prometheus push gateway: http://localhost:9091
Look again grafana
good luck!
边栏推荐
- Trace tool for MySQL further implementation plan
- C9 colleges and universities, doctoral students make a statement of nature!
- Linear algebra of deep learning
- View remote test data and records anytime, anywhere -- ipehub2 and ipemotion app
- [force buckle]41 Missing first positive number
- 重上吹麻滩——段芝堂创始人翟立冬游记
- 【批处理DOS-CMD命令-汇总和小结】-跳转、循环、条件命令(goto、errorlevel、if、for[读取、切分、提取字符串]、)cmd命令错误汇总,cmd错误
- 动态规划思想《从入门到放弃》
- 深入探索编译插桩技术(四、ASM 探秘)
- There is an error in the paddehub application
猜你喜欢
Dell笔记本周期性闪屏故障
Equals() and hashcode()
UI control telerik UI for WinForms new theme - vs2022 heuristic theme
Installation and testing of pyflink
《安富莱嵌入式周报》第272期:2022.06.27--2022.07.03
Dell Notebook Periodic Flash Screen Fault
阿里云中mysql数据库被攻击了,最终数据找回来了
第六篇,STM32脉冲宽度调制(PWM)编程
[force buckle]41 Missing first positive number
[牛客] B-完全平方数
随机推荐
Configuring OSPF basic functions for Huawei devices
[batch dos-cmd command - summary and summary] - jump, cycle, condition commands (goto, errorlevel, if, for [read, segment, extract string]), CMD command error summary, CMD error
A brief history of deep learning (II)
.class文件的字节码结构
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such
Fastdfs data migration operation record
【批处理DOS-CMD命令-汇总和小结】-查看或修改文件属性(ATTRIB),查看、修改文件关联类型(assoc、ftype)
【js】获取当前时间的前后n天或前后n个月(时分秒年月日都可)
详解OpenCV的矩阵规范化函数normalize()【范围化矩阵的范数或值范围(归一化处理)】,并附NORM_MINMAX情况下的示例代码
View remote test data and records anytime, anywhere -- ipehub2 and ipemotion app
Deep understanding of distributed cache design
做微服务研发工程师的一年来的总结
How to get started and improve test development?
Installation of torch and torch vision in pytorch
boot - prometheus-push gateway 使用
Address information parsing in one line of code
Interface (interface related meaning, different abstract classes, interface callback)
ActiveReportsJS 3.1中文版|||ActiveReportsJS 3.1英文版
SuperSocket 1.6 创建一个简易的报文长度在头部的Socket服务器
《安富莱嵌入式周报》第272期:2022.06.27--2022.07.03