当前位置:网站首页>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!
边栏推荐
- How to get started and improve test development?
- NEON优化:性能优化经验总结
- Dynamic planning idea "from getting started to giving up"
- [batch dos-cmd command - summary and summary] - string search, search, and filter commands (find, findstr), and the difference and discrimination between find and findstr
- 【js】获取当前时间的前后n天或前后n个月(时分秒年月日都可)
- golang中的Mutex原理解析
- Dr selection of OSPF configuration for Huawei devices
- Provincial and urban level three coordinate boundary data CSV to JSON
- 再聊聊我常用的15个数据源网站
- 第六篇,STM32脉冲宽度调制(PWM)编程
猜你喜欢
批量获取中国所有行政区域经边界纬度坐标(到县区级别)
动态规划思想《从入门到放弃》
Provincial and urban level three coordinate boundary data CSV to JSON
「精致店主理人」青年创业孵化营·首期顺德场圆满结束!
Building a dream in the digital era, the Xi'an station of the city chain science and Technology Strategy Summit ended smoothly
Learn to use code to generate beautiful interface documents!!!
做微服务研发工程师的一年来的总结
资产安全问题或制约加密行业发展 风控+合规成为平台破局关键
[HFCTF2020]BabyUpload session解析引擎
windows安装mysql8(5分钟)
随机推荐
[software reverse - solve flag] memory acquisition, inverse transformation operation, linear transformation, constraint solving
pytorch之数据类型tensor
fastDFS数据迁移操作记录
pyflink的安装和测试
【批处理DOS-CMD命令-汇总和小结】-查看或修改文件属性(ATTRIB),查看、修改文件关联类型(assoc、ftype)
Grc: personal information protection law, personal privacy, corporate risk compliance governance
In rails, when the resource creation operation fails and render: new is called, why must the URL be changed to the index URL of the resource?
Openjudge noi 1.7 08: character substitution
Come on, don't spread it out. Fashion cloud secretly takes you to collect "cloud" wool, and then secretly builds a personal website to be the king of scrolls, hehe
【JVM调优实战100例】04——方法区调优实战(上)
资产安全问题或制约加密行业发展 风控+合规成为平台破局关键
What is time
新手如何入门学习PostgreSQL?
阿里云中mysql数据库被攻击了,最终数据找回来了
批量获取中国所有行政区域经边界纬度坐标(到县区级别)
Do you understand this patch of the interface control devaxpress WinForms skin editor?
.class文件的字节码结构
斗地主游戏的案例开发
Fastdfs data migration operation record
[Batch dos - cmd Command - Summary and Summary] - String search, find, Filter Commands (FIND, findstr), differentiation and Analysis of Find and findstr