Springboot 集成Prometheus 数据采集 使用grafana 监控报告告警 邮件配置

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

目录

Springboot 相关

Pom

重点包

如果有需要可以增加安全包-一般内部机房没啥事-(非必选)

Application.yml配置文件-(非必选)

Application.properties

management.endpoints.web.exposure.include介绍

启动类

查看监控信息

Prometheus

Prometheus.yml 配置

如果使用类安全包-(非必选)

启动就可以看到了

Grafana 模板 12900

一、报告模板内容

二、设置告警邮件接收人

三、邮箱发送人配置(找个自己常用的邮箱开启smtp相关权限配置即可)

然后专门配置几个告警规则 走走测试验证下即可


 

Springboot 相关

Pom


<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent>

       <groupId>org.springframework.boot</groupId>

       <artifactId>spring-boot-starter-parent</artifactId>

       <version>2.2.4.RELEASE</version>

       <relativePath/> <!-- lookup parent from repository -->

    </parent>

    <groupId>com.example</groupId>

    <artifactId>springboot2demo</artifactId>

    <version>0.0.1-SNAPSHOT</version>

    <name>springboot2demo</name>

    <description>Demo project for Spring Boot</description>



    <properties>

       <java.version>1.8</java.version>

    </properties>



    <dependencies>

       <dependency>

           <groupId>org.springframework.boot</groupId>

           <artifactId>spring-boot-starter-actuator</artifactId>

       </dependency>

       <dependency>

           <groupId>org.springframework.boot</groupId>

           <artifactId>spring-boot-starter-web</artifactId>

       </dependency>

       <dependency>

           <groupId>io.micrometer</groupId>

           <artifactId>micrometer-registry-prometheus</artifactId>

           <version>1.1.4</version>

       </dependency>



       <dependency>

           <groupId>org.springframework.boot</groupId>

           <artifactId>spring-boot-starter-test</artifactId>

           <scope>test</scope>

           <exclusions>

              <exclusion>

                  <groupId>org.junit.vintage</groupId>

                  <artifactId>junit-vintage-engine</artifactId>

              </exclusion>

           </exclusions>

       </dependency>

    </dependencies>



    <build>

       <plugins>

           <plugin>

              <groupId>org.springframework.boot</groupId>

              <artifactId>spring-boot-maven-plugin</artifactId>

           </plugin>

       </plugins>

    </build>



</project>

重点包

<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>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-security</artifactId>

        </dependency>

Application.yml配置文件-(非必选)

security: 
  user: 
    name: admin 
    password: 1234 
  basic: 
    enabled: true 
    # 安全路径列表,逗号分隔,此处只针对/actuator路径进行认证 
    path: /actuator
 

Application.properties

server.port=8101

spring.application.name=springBootDemo

# 打开所有 Actuator 服务

management.endpoints.web.exposure.include=*

# 将应用名称添加到计量器的 tag 中去

# 以便 Prometheus 根据应用名区分不同服务

management.metrics.tags.application=${spring.application.name}

management.endpoints.web.exposure.include介绍

路径    描述

/autoconfig   提供了一份自动配置报告,记录哪些自动配置条件通过了,哪些没通过

/beans 描述应用程序上下文里全部的Bean,以及它们的关系

/env    获取全部环境属性

/configprops 描述配置属性(包含默认值)如何注入Bean

/dump 获取线程活动的快照

/health     报告应用程序的健康指标,这些值由HealthIndicator的实现类提供

/info    获取应用程序的定制信息,这些信息由info打头的属性提供

/mappings     描述全部的URI路径,以及它们和控制器(包含Actuator端点)的映射关系

/metrics    报告各种应用程序度量信息,比如内存用量和HTTP请求计数

/shutdown     关闭应用程序,要求endpoints.shutdown.enabled设置为true

/trace  提供基本的HTTP请求跟踪信息(时间戳、HTTP头等)

/prometheus

启动类

package com.example.springboot2demo;



import io.micrometer.core.instrument.MeterRegistry;

import org.springframework.beans.factory.annotation.Value;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.context.annotation.Bean;



@SpringBootApplication

public class Springboot2demoApplication {



    public static void main(String[] args) {

        SpringApplication.run(Springboot2demoApplication.class, args);

    }



    @Bean

    MeterRegistryCustomizer<MeterRegistry> configurer(

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

        return (registry) -> registry.config().commonTags("application", applicationName);

    }

}

查看监控信息

http://localhost:8101/actuator/prometheus

 

Prometheus

Prometheus.yml 配置

- job_name: " actuator-demo"

    metrics_path: "/actuator/prometheus"

    static_configs:

      - targets: ["localhost:8101"]

如果使用类安全包-(非必选)

- job_name: 'monitor-demo'

    scrape_interval: 5s # 刮取的时间间隔

    scrape_timeout: 5s 

    metrics_path: /actuator/prometheus

    scheme: http 

    basic_auth: #认证信息

      username: admin

      password: 1234

    static_configs:

      - targets:

        - 127.0.0.1: 8101 #此处填写 Spring Boot 应用的 IP + 端口号

启动就可以看到了

 

Grafana 模板 12900

一、报告模板内容

程序运行  Jvm   tomcat 请求响应  日志

 

 

 

 

 

 

 

 

 

二、设置告警邮件接收人

 

三、邮箱发送人配置(找个自己常用的邮箱开启smtp相关权限配置即可)

Grafana默认使用conf目录下defaults.ini作为配置文件运行 在这直接改就ok

 

#################################### SMTP / Emailing #####################

[smtp]

enabled = true

host = smtp.exmail.qq.com:465

user = xxxx@ininin.com

# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""

password = XXX

cert_file =

key_file =

skip_verify = true

from_address = xxxx@ininin.com

from_name = Grafana

ehlo_identity = ininin.com

然后专门配置几个告警规则 走走测试验证下即可

 

 

ok

持续更新

 


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

相关文章

Hive(17):Hive Show显示语法

Show相关的语句提供了一种查询Hive metastore的方法。可以帮助用户查询相关信息。 1 显示所有数据库 SCHEMAS和DATABASES的用法 功能一样 show databases; show schemas; 2 显示当前数据库所有表/视图/物化视图/分区/索引 show tables; SHOW TABLES [IN database_name]; --指…

2023年6月随笔暨半年总结

1. 回头看 日更坚持了181天。 读《改变未来的九大算法》更新完成 读《发布&#xff01;设计与部署稳定的分布式系统》持续更新中 读《数据压缩入门》零星更新中 学信息系统项目管理师第4版系列制作中 6月码字45812字&#xff0c;日均码字数1527字&#xff0c;累计码字287…

EasyDSS视频直播点播平台视频回看列表显示为ID的排查与优化

视频直播点播EasyDSS平台具备灵活的视频能力&#xff0c;包括直播、点播、转码、管理、录像、检索、时移回看等&#xff0c;平台支持音视频采集、视频推拉流、播放H.265编码视频、存储、分发等能力服务&#xff0c;可应用在无人机推流、在线直播、虚拟直播、远程培训等场景中。…

JumpServer开源堡垒机页面配置

JumpServer开源堡垒机页面配置 一、登录二、功能模块2.1、控制台2.1.1、用户管理2.1.1.1、用户列表2.1.1.2、用户组 2.1.2、资产管理2.1.2.1、资产列表2.1.2.1.1、创建服务器链接2.1.2.1.2、创建数据库MySQL链接 2.1.2.2、网域列表2.1.2.3、平台列表2.1.2.4、标签列表 2.1.3、账…

机器学习优化器和SGD和SGDM实验对比(编程实现SGD和SGDM)

机器学习优化器和SGD和SGDM实验对比 博主最近在学习优化器&#xff0c;于是呢&#xff0c;就做了一个SGD和SGDM的实验对比&#xff0c;可谓是不做不知道&#xff0c;一做吓一跳&#xff0c;这两个算法最终对结果的影响还是挺大的&#xff0c;在实验中SGDM明星要比SGD效果好太多…

#10043. 「一本通 2.2 例 1」剪花布条

题目 题目描述 一块花布条&#xff0c;里面有些图案&#xff0c;另有一块直接可用的小饰条&#xff0c;里面也有一些图案。对于给定的花布条和小饰条&#xff0c;计算一下能从花布条中尽可能剪出几块小饰条来呢&#xff1f; 输入格式 输入数据为多组数据&#xff0c;读取到…

gRPC的四种rpc服务接口定义方式

1.说明 在gRPC的服务中定义接口的时候&#xff0c; 请求参数和响应参数可以设置为非Stream或者是Stream方式。 Stream流方式&#xff0c;即操作者可以任意的读写流数据&#xff0c; 直到关闭流&#xff0c; 而非Stream方式在写入或者读取后&#xff0c; 数据是不能改变的。 这…