当前位置:网站首页>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!
边栏推荐
- Deep learning environment configuration jupyter notebook
- 【JokerのZYNQ7020】AXI_ EMC。
- 阿里云中mysql数据库被攻击了,最终数据找回来了
- Configuring the stub area of OSPF for Huawei devices
- Dell笔记本周期性闪屏故障
- 《安富莱嵌入式周报》第272期:2022.06.27--2022.07.03
- 迈动互联中标北京人寿保险,助推客户提升品牌价值
- golang中的atomic,以及CAS操作
- Dynamic planning idea "from getting started to giving up"
- LLDP兼容CDP功能配置
猜你喜欢
[Niuke] b-complete square
[software reverse automation] complete collection of reverse tools
Batch obtain the latitude coordinates of all administrative regions in China (to the county level)
详解OpenCV的矩阵规范化函数normalize()【范围化矩阵的范数或值范围(归一化处理)】,并附NORM_MINMAX情况下的示例代码
[hfctf2020]babyupload session parsing engine
界面控件DevExpress WinForms皮肤编辑器的这个补丁,你了解了吗?
Learn self 3D representation like ray tracing ego3rt
pytorch之数据类型tensor
做微服务研发工程师的一年来的总结
[牛客] [NOIP2015]跳石头
随机推荐
Batch obtain the latitude coordinates of all administrative regions in China (to the county level)
[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
The printf function is realized through the serial port, and the serial port data reception is realized by interrupt
Dynamic planning idea "from getting started to giving up"
Configuring the stub area of OSPF for Huawei devices
[牛客] [NOIP2015]跳石头
Part IV: STM32 interrupt control programming
Link sharing of STM32 development materials
What is time
在jupyter中实现实时协同是一种什么体验
Address information parsing in one line of code
重上吹麻滩——段芝堂创始人翟立冬游记
界面控件DevExpress WinForms皮肤编辑器的这个补丁,你了解了吗?
[Niuke] [noip2015] jumping stone
通过串口实现printf函数,中断实现串口数据接收
【JVM调优实战100例】05——方法区调优实战(下)
第五篇,STM32系统定时器和通用定时器编程
Periodic flash screen failure of Dell notebook
View remote test data and records anytime, anywhere -- ipehub2 and ipemotion app
NEON优化:性能优化经验总结