搭建Grafana+Prometheus监控Spring Boot应用

news/2024/5/18 22:21:45 标签: grafana, prometheus, spring boot

Spring项目改造

maven依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

Spring配置

management.endpoints.web.exposure.include=*
management.metrics.tags.application=${spring.application.name}

prometheus_21">搭建prometheus

下载Prometheus镜像

docker pull prom/prometheus

prometheus_26">创建prometheus配置

/opt/docker/prometheus/config目录下创建prometheus.yml

# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
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: '/actuator/prometheus'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["10.10.10.10:9090"]

targets配置目标java应用的ip端口,例如10.10.10.10:9090

启动Prometheus

docker run -d -p 9090:9090 --name prom \
-v /opt/docker/prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus

可以查看容器启动日志确认是否启动成功:

docker logs xxxx

访问http://xxxxxxxxxx:9090即可
在这里插入图片描述

搭建Grafana

docker pull grafana/grafana
docker run -d --name grafana -p 3000:3000 grafana/grafana

访问http://localhost:3000
在这里插入图片描述

prometheus_84">配置prometheus数据源

在这里插入图片描述

配置Dashboards

下载模板

Dashboards模板下载地址:https://grafana.com/grafana/dashboards/

导入模板

在这里插入图片描述


http://www.niftyadmin.cn/n/5478895.html

相关文章

STC89C52学习笔记(七)

STC89C52学习笔记&#xff08;七&#xff09; 综述&#xff1a;本文介绍了串口以及讲述了串口相关寄存器如何配置并给予相关代码。 一、修改代码注意事项 在修改代码时不要一次性加入一堆代码&#xff0c;不利于定位错误。可以先注释一些代码&#xff0c;待解决完毕问题后再…

vscode 配置文件settings.json和c_cpp_properties.json的作用

前言 在 Visual Studio Code (VSCode) 中&#xff0c;settings.json 和 c_cpp_properties.json 都是配置文件&#xff0c;它们分别用于不同的目的。 settings.json settings.json 文件是 VSCode 的用户或工作区设置文件。它允许你自定义 VSCode 的各种行为和外观。 用户设置…

unity学习笔记 UnityWebRequest使用心得

unity学习笔记 UnityWebRequest使用心得 UnityWebRequest隐藏用法功能使用方式 UnityWebRequest隐藏用法 功能 用于调用POST&#xff0c;但请求头为octet-stream的请求&#xff0c;并且在返回的数据中不断地对数据进行处理Restsharp插件能做到的&#xff0c;UnityWebRequest也…

数据检索的优化之道:B树与B+树的深度解析与应用探索

1、引言 在信息时代&#xff0c;数据检索的速度和效率对于任何依赖数据处理的系统来说都至关重要。无论是在线搜索引擎、数据库管理系统还是文件存储系统&#xff0c;快速准确地检索所需数据都是核心需求。传统的线性数据结构在处理大规模数据集时往往力不从心&#xff0c;因此…

Selenium+Chrome Driver 爬取搜狐页面信息

进行selenium包和chromedriver驱动的安装 安装selenium包 在命令行或者anaconda prompt 中输入 pip install Selenium 安装 chromedriver 先查看chrome浏览器的版本 这里是 123.0.6312.106 版 然后在http://npm.taobao.org/mirrors/chromedriver/或者https://googlechrom…

探索ChatGPT应用:学术写作实践与经验分享

ChatGPT无限次数:点击直达 探索ChatGPT应用&#xff1a;学术写作实践与经验分享 引言 随着人工智能技术的快速发展&#xff0c;自然语言处理模型在各个领域的应用也日益普及。其中&#xff0c;ChatGPT作为一款强大的文本生成模型&#xff0c;正在被越来越多的学术写作者用于提…

ArcGIS Server 10发布要素服务时遇到的数据库注册问题总结(一)

工作环境&#xff1a; Windows 7 64 位旗舰版 ArcGIS Server 10.1 ArcGIS Desktop 10.1 IIS 7.0 开始的时候以为10.1发布要素服务和10.0一样&#xff0c;需要安装ArcSDE&#xff0c;后来查阅资料发现不需要&#xff0c;数据库直连方式就可以了。 首先我来说一下发布要素服…

题目:学习使用按位取反~。

题目&#xff1a;学习使用按位取反~。  There is no nutrition in the blog content. After reading it, you will not only suffer from malnutrition, but also impotence. The blog content is all parallel goods. Those who are worried about being cheated should leav…