# Pushgateway-demo
**Repository Path**: code-demo-space/pushgateway-demo
## Basic Information
- **Project Name**: Pushgateway-demo
- **Description**: Pushgateway使用demo
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 3
- **Forks**: 1
- **Created**: 2021-04-16
- **Last Updated**: 2023-11-02
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Pushway-demo
# prometheus
参考:
> [Prometheus 中文文档](https://www.prometheus.wang)
>
> [springboot2.X 整合pushgateway推送到prometheus,最后以grafana展示](https://blog.csdn.net/gejiangbo222/article/details/111573828)
>
> [SpringBoot整合pushgateway、Alertmanager做监控报警](https://blog.csdn.net/qq_37598011/article/details/103591742)
>
> [SpringBoot进阶教程(七十一)详解Prometheus+Grafana](https://www.cnblogs.com/toutou/p/prometheus_grafana.html)
>
> [《Prometheus入门与实践》](https://developer.ibm.com/zh/articles/cl-lo-prometheus-getting-started-and-practice/)
>
> [Prometheus 使用 PushGateway 进行数据上报采集](https://blog.csdn.net/aixiaoyang168/article/details/102818289)
>
> - [Github PushGateway](https://github.com/prometheus/pushgateway)
> - [Github PushGateway client-java](https://github.com/prometheus/client_java#exporting-to-a-pushgateway)
> - [Prometheus Docs](https://prometheus.io/docs/prometheus/latest/configuration/configuration/)
## 使用
引入依赖:
```xml
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-actuator
io.micrometer
micrometer-registry-prometheus
runtime
```
配置application.yml
```yaml
server:
port: 18088
spring:
application:
name: pushway-demo
management:
endpoints:
web:
exposure:
include: prometheus
```
启动后,访问:http://localhost:18088/actuator/prometheus
**注意:开启actuator后要注意要防护,开启actuator的服务千万不能直接对外。常见的方法可以新增一个过滤器对**` /actuator `**路径过滤,只允许内网IP地址访问**
## Metric
### 理解时间序列
Prometheus会将所有采集到的样本数据以时间序列(time-series)的方式保存在内存的TSDB(时序数据库)中,并且定时保存到硬盘上。time-series是按照时间戳和值的序列顺序存放的,我们称之为向量(vector). 每条time-series通过指标名称(metrics name)和一组标签集(labelset)命名。
在time-series中的每一个点称为一个样本(sample),样本由以下三部分组成:
- 指标(metric):metric name和描述当前样本特征的labelsets;
- 时间戳(timestamp):一个精确到毫秒的时间戳;
- 样本值(value): 一个float64的浮点型数据表示当前样本的值。
```
<--------------- metric ---------------------><-timestamp -><-value->
http_request_total{status="200", method="GET"}@1434417560938 => 94355
http_request_total{status="200", method="GET"}@1434417561287 => 94334
http_request_total{status="404", method="GET"}@1434417560938 => 38473
http_request_total{status="404", method="GET"}@1434417561287 => 38544
http_request_total{status="200", method="POST"}@1434417560938 => 4748
http_request_total{status="200", method="POST"}@1434417561287 => 4785
```
### 指标(Metric)
在形式上,所有的指标(Metric)都通过如下格式标示:
```
{