使用prometheus和grafana监控springboot应用

使用prometheus和grafana监控springboot应用

springboot 应用配置

Gradle

//        monitoring
implementation 'org.springframework.boot:spring-boot-starter-actuator:2.3.4.RELEASE'
compile 'io.micrometer:micrometer-registry-prometheus'
compile 'io.micrometer:micrometer-core'

Maven

      	<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-core</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
        </dependency>

在application.yml里

#monitoring
management:
  endpoint:
    metrics:
      enabled: true
    #启用prometheus
    prometheus:
      enabled: true
  endpoints:
    web:
      exposure:
      	# '*' 表示所有,也可以指定如:health,info等
        include: '*'
        exclude: env,beans
  metrics:
    export:
      prometheus:
        enabled: true
  #监控中以使用独立的端口
  server:
    port: 8081 

运行检查

查看springboot健康指标

http://localhost:8081/actuator/health

在这里插入图片描述

up正常,down异常

查看prometheus指标

http://localhost:8081/actuator/prometheus

在这里插入图片描述

配置prometheus

prometheus的配置文件
prometheus.yml

scrape_configs:
  # 可随意指定
  - job_name: 'spring-boot'
    # 多久采集一次数据
    scrape_interval: 15s
    # 采集时的超时时间
    scrape_timeout: 10s
    # 采集的路径
    metrics_path: '/actuator/prometheus'
    # 采集服务的地址,设置成Springboot应用所在服务器的具体地址
    static_configs:
      - targets: ['192.168.100.12:8081']

其中192.168.100.12为本机的ip,注意使用docker运行时,ip不要使用localhost,docker的网卡是独立的。

使用docker运行prometheus

docker run -d -p 9090:9090 -v ~/spring-boot-on-kubernetes/docker/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml

-v 参数,挂载本地~/spring-boot-on-kubernetes/docker/prometheus.yml

grafana配置

配置prometheus
在这里插入图片描述

配置模板
下载grafana模板:https://grafana.com/grafana/dashboards/10280
导入
在这里插入图片描述
展示
在这里插入图片描述
** 使用docker安装 **

docker run -d -p 3001:3000 --link vibrant_meninsky:prometheus grafana/grafana

其中vibrant_meninsky为prometheus 的docker名字

配置prometheus时使用

http://prometheus:9090

在这里插入图片描述

参考
https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-enabling

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/100336.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • [Hadoop in China 2011] 邵铮:揭秘FaceBook Puma演变及发展

    [Hadoop in China 2011] 邵铮:揭秘FaceBook Puma演变及发展

    2021年6月20日
  • could not initialize proxy – no Session

    could not initialize proxy – no Session

    2021年8月13日
  • CCriticalSection的使用

    CCriticalSection的使用CCriticalSection是对关键段CRITICAL_SECTION的封装。 关键段(critivalsection)是一小段代码,他在执行之前需要独占对一些共享资源的访问权。这种方式可以让多行代码以“原子方式”来对资源进行操控。这里的“原子方式”,指的是代码知道除了当前线程之外没有其他任何线程会同时访问该资源。当然,系统仍然可以暂停当前线程去调度其他线程。但是,在当前线程离开关键

    2022年7月20日
  • typescript 函数_MID函数

    typescript 函数_MID函数函数函数是JavaScript应用程序的基础,它帮助你实现抽象层,模拟类,信息隐藏和模块。在TypeScript里,虽然已经支持类,命名空间和模块,但函数仍然是主要的定义行为的地方。Type

    2022年7月29日
  • [core]-ARMV7-A、ARMV8-A、ARMV9-A 架构简介「建议收藏」

    Armv9-AarchitectureArmv9-A架构建立在Armv8-A架构的基础上并向前兼容。Armv9-A架构构成了Arm基础系统架构的基础——该规范概述了一种标准,可确保硬件和固件在系统级的广泛应用中具有兼容性。Armv9-A架构引入了一些主要的新特性:SVE2:extendingthebenefitofscalablevectorstomanymoreusecasesRealmManagementExtension(RME):extend

    2022年4月15日
  • BusyBox下载安装教程

    BusyBox下载安装教程文章目录BusyBox下载安装教程简介下载压缩包开始安装BusyBox下载安装教程简介BusyBox是一个集成了三百多个最常用Linux命令和工具的软件。BusyBox包含了一些简单的工具,例如ls、cat和echo等等,还包含了一些更大、更复杂的工具,例grep、find、mount以及telnet。有些人将BusyBox称为Linux工具里的瑞士军刀。简单的说BusyBox就好像是个大工具箱,它集成压缩了Linux的许多工具和命令,也包含了Linux系统的自带的shell。B

    2022年7月25日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号