首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >搭建Prometheus+Grafana实时监控平台监控Java应用服务

搭建Prometheus+Grafana实时监控平台监控Java应用服务

作者头像
程序员云帆哥
发布2022-05-12 11:10:26
发布2022-05-12 11:10:26
2.5K0
举报
文章被收录于专栏:程序员云帆哥程序员云帆哥

文章目录

一、Prometheus简介

官网是这样介绍的:

Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. Since its inception in 2012, many companies and organizations have adopted Prometheus, and the project has a very active developer and user community. It is now a standalone open source project and maintained independently of any company. To emphasize this, and to clarify the project’s governance structure, Prometheus joined the Cloud Native Computing Foundation in 2016 as the second hosted project, after Kubernetes. 翻译:Prometheus是一个开源系统监控和警报工具包,最初由SoundCloud构建。自2012年成立以来,许多公司和组织都采用了普罗米修斯,该项目拥有一个非常活跃的开发人员和用户社区。它现在是一个独立的开源项目,独立于任何公司进行维护。为了强调这一点,并澄清项目的治理结构,普罗米修斯加入云计算基金会2016作为第二托管项目,继Kubernetes。

1、Docker安装Prometheus

代码语言:javascript
复制
docker run --name prometheus -p 9090:9090 -d bitnami/prometheus

2、修改配置文件

代码语言:javascript
复制
docker exec -it ${容器id} /bin/bash
vi conf/prometheus.yml

修改配置文件的scrape_configs,上面的Job是prometheus自身的,下面的Job是我们新增的,用来监控我们的服务器的(192.168.1.3)。

代码语言:javascript
复制
scrape_configs:
  - job_name: "prometheus"
    static_configs:
            - targets: ["localhost:9090"]

  - job_name: "pro_test"     
    metrics_path: /actuator/prometheus
    static_configs:
            - targets: ["192.168.1.3:8086"]

3、重启容器

代码语言:javascript
复制
docker restart ${容器id}

4、浏览器访问

地址:http://IP地址:9090/

5、查看Targets

二、Grafana

   Grafana是一个跨平台的开源的度量分析和可视化工具,可以通过将采集的数据查询然后可视化的展示,并及时通知。它主要有以下六大特点:

  • 展示方式:快速灵活的客户端图表,面板插件有许多不同方式的可视化指标和日志,官方库中具有丰富的仪表盘插件,比如热图、折线图、图表等多种展示方式;
  • 数据源:Graphite,InfluxDB,OpenTSDB,Prometheus,Elasticsearch,CloudWatch和KairosDB等;
  • 通知提醒:以可视方式定义最重要指标的警报规则,Grafana将不断计算并发送通知,在数据达到阈值时通过Slack、PagerDuty等获得通知;
  • 混合展示:在同一图表中混合使用不同的数据源,可以基于每个查询指定数据源,甚至自定义数据源;
  • 注释:使用来自不同数据源的丰富事件注释图表,将鼠标悬停在事件上会显示完整的事件元数据和标记;
  • 过滤器:Ad-hoc过滤器允许动态创建新的键/值过滤器,这些过滤器会自动应用于使用该数据源的所有查询。

1、Docker安装Grafana

代码语言:javascript
复制
docker run -d --name=grafana -p 3000:3000 grafana/grafana

2、浏览器访问

http://IP地址:3000/ 用户名密码都是admin。

3、配置数据源

咱们用的Prometheus,如图位置找到并添加Prometheus数据源。

三、Java应用接入监控

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>

2、修改配置文件

增加如下配置

代码语言:javascript
复制
management:
  endpoint:
    prometheus:
      enabled: true
  endpoints:
    web:
      exposure:
        include: '*'
  metrics:
    export:
      prometheus:
        enabled: true

别忘了修改prometheus的配置文件,让它监控我们应用,上面prometheus.yml我已经写了,再发一下。

代码语言:javascript
复制
- job_name: "pro_test"     
    metrics_path: /actuator/prometheus
    static_configs:
            - targets: ["192.168.1.3:8086"]

3、启动服务并查看Grafana监控台

   Grafana查看需要新建Dashboard,就是自定义显示的数据,还是比较灵活的。这里我们也可以去Grafana官网下载,有很多好看的。我这里用的Spring Boot Statistics & Endpoint Metrics。    来看下效果。

好了,大兄dei,你学废了么?

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-12-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文章目录
  • 一、Prometheus简介
    • 1、Docker安装Prometheus
    • 2、修改配置文件
    • 3、重启容器
    • 4、浏览器访问
    • 5、查看Targets
  • 二、Grafana
    • 1、Docker安装Grafana
    • 2、浏览器访问
    • 3、配置数据源
  • 三、Java应用接入监控
    • 1、项目引入依赖
    • 2、修改配置文件
    • 3、启动服务并查看Grafana监控台
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档