首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
30 篇文章
1
Prometheus配置企业微信告警
2
云原生监控配置自建alertmanager实现告警
3
K8S 中的 CPUThrottlingHigh 到底是个什么鬼?
4
Kubernetes集群安装kube-prometheus后无法执行kubectl top node
5
Prometheus Operator 使用 AlertmanagerConfig 进行报警配置
6
在 Grafana 中可视化 Alertmanager 报警
7
Prometheus Operator 常用指标
8
使用 Thanos 实现 Prometheus 的高可用
9
Kubenretes上运行Prometheus联邦集群
10
prometheus2.0 联邦的配置
11
Prometheus监控学习笔记之prometheus的远端存储
12
别再乱用 Prometheus 联邦了,分享一个 Prometheus 高可用新方案
13
使用prometheus监控多k8s集群
14
Kubernetes K8S之kube-prometheus概述与部署 Prometheus的关键特性架构图基本原理服务过程kube-prometheus下载与配置修
15
Prometheus BlackBox简单监控
16
如何使用Prometheus配置自定义告警规则
17
使用prometheus operator监控envoy
18
使用 Prometheus-Operator 监控 Calico
19
TKE 1.20.6搭建Kube-Prometheus(prometheus-oprator)
20
云原生监控通过blackbox_exporter监控网站
21
一文带你了解 Prometheus
22
使用 Thanos 和 Prometheus 打造一个高可用的 Kubernetes 监控系统
23
prometheus监控springboot应用
24
搭建prometheus+grafana监控SpringBoot应用入门
25
用prometheus监控java应用
26
Prometheus Operator 监控 Traefik V2.4
27
Prometheus指标优化
28
使用 Prometheus Operator 监控 Kubernetes
29
装X神器,让你的grafana看板变得炫酷起来
30
​prometheus中使用python手写webhook完成告警

搭建prometheus+grafana监控SpringBoot应用入门

搭建prometheus+grafana监控SpringBoot应用入门

1. springBoot 应用准备

pom.xml依赖

代码语言:javascript
复制
      <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!--prometheus-->
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
            <version>1.0.3</version>
        </dependency>

并且主动向prometheus 上报application名.

代码语言:javascript
复制
   /**
     * 上报application 到 Prometheus
     */
    @Bean
    MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
        return registry -> registry.config().commonTags("application", "yourappName");
    }

SpringBoot actuator端开启 (自行调整,我这里全部开启):

代码语言:javascript
复制
management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: always
    prometheus:
      enabled: true

最好启动一下查看端点暴露的情况,尤其检查 /actuator/prometheus 是否成功暴露

2. 下载并安装prometheus

最新下载地址 : https://prometheus.io/download/

配置prometheus.yml(安装完成后的目录下面有)

重点是配置好基础的job_name,metrics_path,还有应用的ip和端口号,例如 :

代码语言:javascript
复制
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']
    
  - job_name: 'test-application'
    metrics_path: '/actuator/prometheus'
    static_configs:
    - targets: ['localhost:9527']

配置好之后,可以启动prometheus,并且访问prometheus,默认访问地址 http://localhost:9090

此时可以看到prometheus的情况,点击Status的targets,查看应用实例情况

3. 下载并安装grafana(windows的安装过程中最好关闭杀毒软件,可能导致安装失败)

最新下载地址 : https://grafana.com/grafana/download

运行启动grafana,默认访问地址 : http://localhost:3000, 默认用户名/密码 admin/admin

配置datasource(Configuration里面),选择Prometheus,配置好prometheus,本机运行的prometheus,则access选择Server即可。然后点击Save&Test

配置Dashboard,可以定制,可以自选(种类繁多,花样不胜枚举),这里直接选造好的SpringBoot的Dashboard导入(拿来即用)

直接地址栏输入 https://grafana.com/grafana/dashboards/6756 或者 6756,然后点击load。

此时点击Dashboard :

下一篇
举报
领券