当前位置:网站首页>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!
边栏推荐
- pytorch之数据类型tensor
- 第七篇,STM32串口通信编程
- Learning notes 5: ram and ROM
- 用tkinter做一个简单图形界面
- golang中的WaitGroup实现原理
- paddlehub应用出现paddle包报错的问题
- 深度学习简史(二)
- Oracle:CDB限制PDB资源实战
- Building a dream in the digital era, the Xi'an station of the city chain science and Technology Strategy Summit ended smoothly
- Part 7: STM32 serial communication programming
猜你喜欢

Set (generic & list & Set & custom sort)

Telerik UI 2022 R2 SP1 Retail-Not Crack
![[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](/img/a5/41d4cbc070d421093323dc189a05cf.png)
[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

迈动互联中标北京人寿保险,助推客户提升品牌价值

C9 colleges and universities, doctoral students make a statement of nature!

线段树(SegmentTree)
![[software reverse - solve flag] memory acquisition, inverse transformation operation, linear transformation, constraint solving](/img/16/71692f4cf89b7dc0fe62946e59ecd1.png)
[software reverse - solve flag] memory acquisition, inverse transformation operation, linear transformation, constraint solving

【JVM调优实战100例】04——方法区调优实战(上)
![Explain in detail the matrix normalization function normalize() of OpenCV [norm or value range of the scoped matrix (normalization)], and attach norm_ Example code in the case of minmax](/img/87/3fee9e6f687b0c3efe7208a25f07f1.png)
Explain in detail the matrix normalization function normalize() of OpenCV [norm or value range of the scoped matrix (normalization)], and attach norm_ Example code in the case of minmax

"Exquisite store manager" youth entrepreneurship incubation camp - the first phase of Shunde market has been successfully completed!
随机推荐
fastDFS数据迁移操作记录
Dell Notebook Periodic Flash Screen Fault
Tencent cloud webshell experience
What kind of experience is it to realize real-time collaboration in jupyter
UI控件Telerik UI for WinForms新主题——VS2022启发式主题
Dynamic planning idea "from getting started to giving up"
Atomic in golang, and cas Operations
Make a simple graphical interface with Tkinter
pyflink的安装和测试
from .cv2 import * ImportError: libGL.so.1: cannot open shared object file: No such file or direc
windows安装mysql8(5分钟)
再聊聊我常用的15个数据源网站
The printf function is realized through the serial port, and the serial port data reception is realized by interrupt
ARM裸板调试之JTAG调试体验
省市区三级坐标边界数据csv转JSON
Tensorflow GPU installation
Oracle:CDB限制PDB资源实战
View remote test data and records anytime, anywhere -- ipehub2 and ipemotion app
C9 colleges and universities, doctoral students make a statement of nature!
Threejs image deformation enlarge full screen animation JS special effect