前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >集成prometheus+Grafana可视化监控

集成prometheus+Grafana可视化监控

作者头像
BUG弄潮儿
发布2023-02-24 15:11:16
7470
发布2023-02-24 15:11:16
举报
文章被收录于专栏:JAVA乐园

Prometheus介绍

Prometheus是一个开源的系统监控和报警系统,现在已经加入到CNCF基金会,成为继k8s之后第二个在CNCF托管的项目,在kubernetes容器管理系统中,通常会搭配prometheus进行监控,同时也支持多种exporter采集数据,还支持pushgateway进行数据上报,Prometheus性能足够支撑上万台规模的集群。

实现效果

Prometheus的整合

1、添加依赖

代码语言:javascript
复制
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
    <groupId>io.github.mweirauch</groupId>
    <artifactId>micrometer-jvm-extras</artifactId>
    <version>0.2.0</version>
</dependency>

2、修改配置文件

代码语言:javascript
复制
# actuator+prometheus+grafana+springboot2监控集成配置
management:
  endpoints:
   web:
     exposure:
      include: '*' # 暴露/actuator/prometheus
  metrics:
    tags:
     application: ${spring.application.name} # 暴露的数据中添加application label

3、启动类添加

代码语言:javascript
复制
@SpringBootApplication
@MapperScan("com.qingfeng.*.mapper")
@EnableMyRedis
@EnableMyProtect
@ServletComponentScan("com.qingfeng.framework.servlet")
public class QingfengApplication {

@Value("${spring.application.name}")
private  String application;

     public static void main(String[] args) {
        SpringApplication.run(QingfengApplication.class, args);
    }

    @Bean
    MeterRegistryCustomizer<MeterRegistry> configurer() {
         return (registry) -> registry.config().commonTags("application", application);
    }

}

4、启动验证是否集成成功

启动后,在浏览器访问:http://localhost:8090/actuator/prometheus

出现如下信息,说明 集成成功。

安装配置Prometheus

下载安装

代码语言:javascript
复制
下载地址:https://prometheus.io/download/

Prometheus会将所有采集到的样本数据以时间序列(time-series)的方式保存在内存数据库中,并且定时保存到硬盘上。

下载后,将项目解压,解压目录如下:

修改prometheus.yml

在最后加上SpringBootPrometheus

代码语言:javascript
复制
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
      - targets: ["localhost:9090"]
  - job_name: "SpringBootPrometheus"
    scrape_interval: 5s
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ["127.0.0.1:8090"]
  • SpringBoot官方配置:https://docs.spring.io/spring-boot/docs/2.1.3.RELEASE/reference/htmlsingle/
  • prometheus官方文档:https://prometheus.io/docs/introduction/overview/
  • Prometheus-配置解析: https://www.cnblogs.com/liujiliang/p/10080849.html

启动Prometheus

windows下直接双击:prometheus.exe 进行启动。

Linux启动方式:

代码语言:javascript
复制
nohup ./prometheus &

浏览器访问:http://localhost:9090

查看Prometheus监控的应用

查看具体的监控指标

安装配置Grafana下载安装启动 下载地址:https://grafana.com/grafana/download

下载后,解压

双击启动grafana-server.exe 启动

代码语言:javascript
复制
Linux启动方式:nohup ./grafana&

浏览器访问:http://127.0.0.1:3000/login账号和密码都是:admin

添加数据源 在Data Sources选项中添加数据源

设置数据源的名称(唯一的,可添加多个数据源)和Prometheus的访问地址,如果Prometheus有设置账号密码才可以访问,则需要在Auth模块勾选Basuc Auth设置账号密码

导入仪表盘模板 ●模板地址:https://grafana.com/dashboards ●在搜索框中搜索Spring Boot会检索出相关的模板,我们使用:SpringBoot APM Dashboard

拷贝模板id,此处的模板id为:12900

模板导入 输入模板ID 点击Load

配置

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-02-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 BUG弄潮儿 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Prometheus介绍
  • 实现效果
  • Prometheus的整合
    • 1、添加依赖
      • 2、修改配置文件
        • 3、启动类添加
          • 4、启动验证是否集成成功
          • 安装配置Prometheus
            • 下载安装
              • 修改prometheus.yml
              相关产品与服务
              Prometheus 监控服务
              Prometheus 监控服务(TencentCloud Managed Service for Prometheus,TMP)是基于开源 Prometheus 构建的高可用、全托管的服务,与腾讯云容器服务(TKE)高度集成,兼容开源生态丰富多样的应用组件,结合腾讯云可观测平台-告警管理和 Prometheus Alertmanager 能力,为您提供免搭建的高效运维能力,减少开发及运维成本。
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档