首页 > 其他分享 >prometheus + grafana对 springboot 项目进行监控

prometheus + grafana对 springboot 项目进行监控

时间:2023-03-03 22:46:19浏览次数:201  
标签:http springboot prometheus scrape grafana metrics job

1.prometheus接入springboot

prometheus安装后,在安装目录有一个默认的配置文件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 defaults to '/metrics'
    # scheme defaults to 'http'.

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

默认配置了一个job_name,监控prometheus本身。需要增加一个监控springboot项目

  - job_name: "custom_spring_boot"
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ["localhost:9595"]

  • metrics_path 默认采集metrics的路径是/metrics;需要改成/actuator/prometheus
  • scheme 默认是http;如果是https需要自定义配置
  • targets 获取metrics的地址和端口列表

2.访问prometheus

http://127.0.0.1:9090/

出现自定义需要监控的springboot端点列表

在首页,可以查询各种不同的指标

比如查询custom_http_request_time_seconds_count指标

3.grafana接入prometheus

访问

http://127.0.0.1:3000/

配置数据源

添加一个数据

选择prometheus

设置名称和prometheus服务地址

4.配置仪表盘

点击Add a new panel;新建一个Panel

平均时间查询

sum by(api) (rate(custom_http_request_time_seconds_count{job="custom_spring_boot", api="/order"}[5m]))

保存,最终显示

标签:http,springboot,prometheus,scrape,grafana,metrics,job
From: https://www.cnblogs.com/happyhuangjinjin/p/17177247.html

相关文章

  • 手把手教你搭建Windows 搭建Prometheus + Grafana + Jmeter可视化监控平台
    下载安装包Prometheuswindows_exporterGrafana下载地址:https://share.weiyun.com/D9sdiWoC工作原理Exporter监控工具,获取数据Prometheus普罗米修斯时序数据库......
  • Linux下安装prometheus & grafana
    1安装prometheus1.1下载prometheus下载地址https://prometheus.io/download/#prometheus下载wgethttps://github.com/prometheus/prometheus/releases/download/v......
  • SpringBoot中使用Kaptcha实现验证码
    1.首先,我们在pom.xml文件中引入kaptcha的maven依赖。1<dependency>2<groupId>com.github.penggle</groupId>3<artifactId>kaptch......
  • Apinto 网关 V0.11.1 版本发布,多协议互转,新增编码转换器,接入 Prometheus...
    憋了那么久,Eolink旗下Apinto开源网关再次更新啦~一起来看看是否有你期待的功能!1、协议转换功能上线之前发布的Apintov0.10.0已经支持了多协议的基本功能,实现多......
  • springboot 过滤器FilterRegistrationBean详解
    一:基础知识1.通过FilterRegistrationBean实例注册,该方法能够设置过滤器之间的优先级2.为了演示优先级,这里创建2个测试过滤器类:Test1Filter、Test2Filter通过实现javax.serv......
  • Springboot Controller接口默认自动填充 业务实体参数值
    前言今天看有小伙伴求救: 我还是一贯如此,有人不明白,没玩过HandlerMethodArgumentResolver。那么很可能不止他一个人,那么我就有必要出手。不多说,开搞。 正文快速模拟出......
  • springboot(三)
    1.热部署可以在不重启服务器的情况下重新加载更新后的程序.1.1实现原理①非springboot项目热部署实现原理开发非springboot项目时,我们要制作一个web工程并通过tomca......
  • SpringBoot接口返回统一格式
    packagecom.example.springboot.common;importorg.springframework.core.MethodParameter;importorg.springframework.http.MediaType;importorg.springframework......
  • springboot整合mybatis
    1,引入依赖<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.47</version><scope>runtime</scope></depend......
  • SpringBoot集成Knife4j
    转载自: SpringBoot集成Knife4j-hviger-博客园(cnblogs.com)Knife4j简介Knife4j官网地址:https://doc.xiaominfo.com/knife4j是为JavaMVC框架集成Swagger生成Ap......