Prometheus PushGateway Grafana SpringBoot k8s
做监控:用 PushGateway 不用在k8s里创建复杂操作相关,rancher管理的k8s已经存在promethus了prometheus 端口 9090 configMap 挂在/etc/prometheus/prometheus.yml 覆盖global:scrape_interval:5s##5秒抓取evaluation_interval: 5s##5秒报警scrape_configs:
·
做监控:
用 PushGateway 不用在k8s里创建复杂操作相关,rancher管理的k8s已经存在promethus了
prometheus 端口 9090 configMap 挂在
/etc/prometheus/prometheus.yml 覆盖
global:
scrape_interval: 5s ##5秒抓取
evaluation_interval: 5s ##5秒报警
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
labels:
instance: prometheus
- job_name: pushgateway
honor_labels: true ## pushgateway 防止jobname和gateway覆盖
static_configs:
- targets: ['10.43.1.113:9091'] ## pushgateway ip 地址
labels:
instance: pushgateway
pushgateway 9091
springboot 添加
manve
<!--actuator-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!-- The client -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.12.0</version>
</dependency>
<!-- Hotspot JVM metrics-->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
<version>0.12.0</version>
</dependency>
<!-- Exposition HTTPServer-->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_httpserver</artifactId>
<version>0.12.0</version>
</dependency>
<!-- Pushgateway exposition-->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_pushgateway</artifactId>
<version>0.12.0</version>
</dependency>
yml 添加
management:
endpoints:
web:
exposure:
include: '*'
metrics:
distribution:
percentiles-histogram:
http.server.requests: true
sla:
http.server.requests: 50ms
export:
prometheus:
enabled: true
pushgateway:
enabled: true
baseUrl: http://pushgateway:9091
pushRate: 5s ##推送时间5秒一次
job: test ##工程名
groupingKey:
application: test ##工程名
instance: ${HOSTNAME:工程名} ##HOSTNAME是k8s创建容器添加的环境变量k8s里pod的唯一标识
java 代码添加程序被意外销毁或重新部署时,删除pushgateway冗余过期数据
@Bean
public DisposableBean exitCodeGenerator(PrometheusProperties prometheusProperties)
throws Exception {
PushGateway pushGateway = new PushGateway(new URL(prometheusProperties.getPushgateway().getBaseUrl()));
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
pushGateway.delete(prometheusProperties.getPushgateway().getJob(), prometheusProperties.getPushgateway().getGroupingKey());
} catch (IOException e) {
e.printStackTrace();
}
}));
return () -> pushGateway.delete(prometheusProperties.getPushgateway().getJob(), prometheusProperties.getPushgateway().getGroupingKey());
}
grafana 3000
环境变量添加,免登录使用报表
GF_AUTH_ANONYMOUS_ENABLED = true
GF_AUTH_PROXY_ENABLED= true
GF_SECURITY_ALLOW_EMBEDDING = true
模板id 4701 , 5373, 10289 参数有可能需要修改因为自己可能没有模板的监控指标
语句修改参考
更多推荐
已为社区贡献3条内容
所有评论(0)