当前位置:网站首页>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!
边栏推荐
- 做微服务研发工程师的一年来的总结
- C9 colleges and universities, doctoral students make a statement of nature!
- 线段树(SegmentTree)
- Atomic in golang, and cas Operations
- MySQL中回表的代价
- 斗地主游戏的案例开发
- Let's talk about 15 data source websites I often use
- 深入探索编译插桩技术(四、ASM 探秘)
- 【批處理DOS-CMD命令-匯總和小結】-字符串搜索、查找、篩選命令(find、findstr),Find和findstr的區別和辨析
- [Batch dos - cmd Command - Summary and Summary] - String search, find, Filter Commands (FIND, findstr), differentiation and Analysis of Find and findstr
猜你喜欢

Periodic flash screen failure of Dell notebook

批量获取中国所有行政区域经边界纬度坐标(到县区级别)

【批处理DOS-CMD命令-汇总和小结】-字符串搜索、查找、筛选命令(find、findstr),Find和findstr的区别和辨析

Batch obtain the latitude coordinates of all administrative regions in China (to the county level)

第五篇,STM32系统定时器和通用定时器编程
![[100 cases of JVM tuning practice] 05 - Method area tuning practice (Part 2)](/img/40/dc45df3cd3ee7642277eff899bc6aa.png)
[100 cases of JVM tuning practice] 05 - Method area tuning practice (Part 2)

Configuring OSPF basic functions for Huawei devices

ESP Arduino (IV) PWM waveform control output

Threejs image deformation enlarge full screen animation JS special effect

动态规划思想《从入门到放弃》
随机推荐
from . cv2 import * ImportError: libGL. so. 1: cannot open shared object file: No such file or direc
【案例分享】网络环路检测基本功能配置
随时随地查看远程试验数据与记录——IPEhub2与IPEmotion APP
一行代码实现地址信息解析
批量获取中国所有行政区域经边界纬度坐标(到县区级别)
boot - prometheus-push gateway 使用
ESP Arduino (IV) PWM waveform control output
[HFCTF2020]BabyUpload session解析引擎
UI控件Telerik UI for WinForms新主题——VS2022启发式主题
[Batch dos - cmd Command - Summary and Summary] - String search, find, Filter Commands (FIND, findstr), differentiation and Analysis of Find and findstr
[batch dos-cmd command - summary and summary] - string search, search, and filter commands (find, findstr), and the difference and discrimination between find and findstr
Maidong Internet won the bid of Beijing life insurance to boost customers' brand value
C9 colleges and universities, doctoral students make a statement of nature!
深度学习框架TF安装
Summary of being a microservice R & D Engineer in the past year
详解OpenCV的矩阵规范化函数normalize()【范围化矩阵的范数或值范围(归一化处理)】,并附NORM_MINMAX情况下的示例代码
Dynamic planning idea "from getting started to giving up"
Openjudge noi 1.7 10: simple password
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?
深度学习简史(一)