搭建Promethues + grafana +alertManager+blakbox 监控springboot 健康和接口情况

news2024/10/5 17:16:03

一。概述

架构图:

拓扑图:

prometheus 是一个开源系统,用于构建监控和报警的工具包。

Prometheus 收集其指标并将其存储为时间序列数据,即指标信息与记录它的时间戳一起存储,以及称为标签的可选键值对。

特点:

  • 具有由指标名称和键/值对标识的时间序列数据的多维数据模型
  • PromQL,一种灵活的查询语言,可利用此维度
  • 不依赖分布式存储;单服务器节点是自治的
  • 时序收集通过 HTTP 上的拉取模型进行
  • 通过中间网关支持推送时间序列
  • 通过服务发现或静态配置发现目标
  • 多种图形和仪表板支持模式

  如上图所示:采集层负责数据的获取 ,支持多种exporters   Download | Prometheus支持什么可以去官网查看  应用层支持报表展示和报警发出

二。部署

部署prometheus

        (1) docker 部署 我这个是windows环境后面也可以是linux 一样的 或者去下载安装包

Download | Prometheus

        

docker run -p 9090:9090  -d  -v C:/Users/E2/Desktop/dockerv/prometheus:/opt/bitnami/prometheus/conf  bitnami/prometheus

 在docker 挂载目录添加配置文件prometheus.yml :

# my global config
global:
  scrape_interval:     15s # 设置多久获取一次数据
  evaluation_interval: 15s # 多久更新一次 报警规则
  # scrape_timeout is set to the global default (10s).

# Alertmanager 配置
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      #alertManager 服务因为我这个alertManager 没有容器部署放到本地所以这样
      - host.docker.internal:9093

# 加载报警规则文件
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'

    # 监管自身 
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']
  #springboot的监控  
  - job_name: guanwang-service
    metrics_path: /actuator/prometheus
 # spring boot 项目地址和端口注意下监控 
    static_configs:
    - targets: ['host.docker.internal:2020']
      labels:
        applicaton: guanwang-kelk
        env: dev
 # 黑盒测试配置文件这个只使用了http_2xx 来测接口可用性 
  - job_name: 'http_status'
    metrics_path: /probe
    params:
      module: [http_2xx]
    file_sd_configs:
      - files:
        - '/opt/bitnami/prometheus/conf/job_web.yaml'
        refresh_interval: 30s
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - target_label: __address__
        #blackbox_exporter 的服务端口
        replacement: host.docker.internal:9115
  #云场站admin模块
  - job_name: yun-admin-service
    metrics_path: /sys/actuator/prometheus
    static_configs:
    - targets: ['host.docker.internal:8080']
      labels:
        applicaton: yun-admin-service
        env: dev      
        
        
        
        
        
        
        

     添加报警规则 (这个需要 alertManager 服务的支持 安装在后面说明 )配置文件 就是上一个配置文件引入的那个 first_rules.yml 其他的可以看看文档自己去判断筛选和数值 

groups:
- name: 生产GIS接口监控
  rules:
  - alert: geoServer接口功能报警
    #筛选数据 查出来就会报警 这个判断黑盒测试的接口状态不为200 的
    expr: probe_http_status_code{project="geoserver"} !=200
    for: 15s
    labels:
      severity: 严重
    annotations:  
      description: "接口出现异常:{{ $labels.project }}"
      summary: "Web 访问异常:{{ $labels.desc }}:已无法访问"
  

添加黑盒测试配置文件 (这个需要你去下载 blackbox_exporter 安装支持可以帮你去测试接口可用性和接口时间) job_web.yaml

- targets:
  - https://*/geoserver/ows?service=WFS&version=1.1.0&request=GetFeature&typeName=ne%3Acloud_pipe_line_1&startIndex=0&propertyName=shape%2Cconduit_material%2Cconduit_type%2Cconduit_id%2Csection_no%2Cburying_type%2Csection_length%2Cstart_burying%2Cend_burying&outputFormat=application%2Fjson&maxFeatures=5000&srsName=EPSG%3A4326&cql_filter=tenant_id%3D871009%20and%20conduit_id%20IS%20NULL&_t=1688970060542
  labels:
    env: test
    app: web
    project: geoserver
    desc: geoserver要素查询
- targets:
  - https://*/geoserver/ow?service=WFS&version=2.0.0&request=GetFeature&typeName=ne%3Acloud_customer_1&propertyName=shape%2Ccustomer_name%2Ccustomer_type%2Ctelephone%2Ccustomer_addr%2Cdoc_number&outputFormat=application%2Fjson&maxFeatures=100000&srsName=EPSG%3A4326&startIndex=0&service=WFS&version=2.0.0&request=GetFeature&typeName=ne%3Acloud_customer_1&propertyName=shape%2Ccustomer_name%2Ccustomer_type%2Ctelephone%2Ccustomer_addr%2Cdoc_number&outputFormat=application%2Fjson&maxFeatures=100000&srsName=EPSG%3A4326&startIndex=0
  labels:
    env: test
    app: web
    project: geoserver
    desc: geoserver爆管分析
    not_200: yes # 这个自定义标签是为了标识某些地址在正常情况下不是返回200状态码

2.搭建 blackBox_exproter 先去官网下载 完成后启动项目 默认的配置文件

modules:
  http_2xx:
    prober: http
    http:
      preferred_ip_protocol: "ip4"
  http_post_2xx:
    prober: http
    http:
      method: POST
  tcp_connect:
    prober: tcp
  pop3s_banner:
    prober: tcp
    tcp:
      query_response:
      - expect: "^+OK"
      tls: true
      tls_config:
        insecure_skip_verify: false
  grpc:
    prober: grpc
    grpc:
      tls: true
      preferred_ip_protocol: "ip4"
  grpc_plain:
    prober: grpc
    grpc:
      tls: false
      service: "service1"
  ssh_banner:
    prober: tcp
    tcp:
      query_response:
      - expect: "^SSH-2.0-"
      - send: "SSH-2.0-blackbox-ssh-check"
  irc_banner:
    prober: tcp
    tcp:
      query_response:
      - send: "NICK prober"
      - send: "USER prober prober prober :prober"
      - expect: "PING :([^ ]+)"
        send: "PONG ${1}"
      - expect: "^:[^ ]+ 001"
  icmp:
    prober: icmp
  icmp_ttl5:
    prober: icmp
    timeout: 5s
    icmp:
      ttl: 5

代表黑盒测试支持那些类型的测试一般不用改,之前有dns 测试需要添加额外的配置

3.搭建alertManager 也是去官方下载 启动  修改配置文件 

global:
  smtp_smarthost: 'smtp.163.com:25'
  smtp_from: 'XX@163.com'
  smtp_auth_username: 'XX@163.com'
  smtp_auth_password: 'XX'
  smtp_require_tls: false
templates:
  - 'C:/Users/E2/Desktop/dockerv/alertmanager-0.25.0.windows-amd64/alertmanager-0.25.0.windows-amd64/data/tml/*.tmpl' 
route:
  group_by: ['alertname']
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 1h
  receiver: 'mail'
receivers:
  - name: 'mail'
    email_configs:
        #可以配置多个用,链接
      - to: 'XX@qq.com'
        send_resolved: true
        html: '{{ template "email.tmpl" . }}'
inhibit_rules:
  - source_match:
      severity: 'critical'
    target_match:
      severity: 'warning'
    equal: ['alertname', 'dev', 'instance']

我这面只配置了邮件 默认是web_hook 需要你自己去实现接口还支持企业微信这个要自己去看下怎么选择和配置了

配置邮件发送显示的模版 :

{{ define "email.tmpl" }}
{{ range .Alerts }}
 <pre>
实例: {{ .Labels.instance }}
信息: {{ .Annotations.summary }}
详情: {{ .Annotations.description }}
时间: {{ .StartsAt.Format "2006-01-02 15:04:05" }}
 </pre>
{{ end }}
{{ end }}
 

C:/Users/E2/Desktop/dockerv/alertmanager-0.25.0.windows-amd64/alertmanager-0.25.0.windows-amd64/data/tml/*.tmpl 我的放置路径文件当中也有配置

4.spring boot 接入  刚刚prometheus.yml 配置了一个spring boot项目的监管,现在项目需要做支持

引入依赖 项目

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

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

使用了springfox swagger 可能会报错 要通过代码配置暴露所有

    @Bean
    public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(
            WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier,
            ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes,
            CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, Environment environment) {
        List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
        Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
        allEndpoints.addAll(webEndpoints);
        allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
        allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
        String basePath = webEndpointProperties.getBasePath();
        EndpointMapping endpointMapping = new EndpointMapping(basePath);
        boolean shouldRegisterLinksMapping = webEndpointProperties.getDiscovery().isEnabled() &&
                (StringUtils.hasText(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
        return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes,
                corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath),
                shouldRegisterLinksMapping, null);
    }
/**
 * @author chenkang
 * @date 2023/7/11 16:02
 */
@Configuration
public class PrometheusConfig {
    @Resource
    private ModuleConfig moduleConfig;

    @Bean
    MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
        return registry -> registry.config().commonTags("application",moduleConfig.getName());
    }
}

不然yaml 配置就可以:

management:
  endpoint:
    prometheus:
      enabled: true
    metrics:
      enabled: true
  metrics:
    export:
      prometheus:
        enabled: true
    tags:
      #这个尽量去配置不然你用好多面板模版的时候 会只认这个标签 
      application: menhu-guanwang

5.安装 grafana 也是docker  这面--link 了刚刚安装的prometheus 不然连不上

docker run -d --name grafana -p 3000:3000  -v C:/Users/E2/Desktop/dockerv/grafana/data:/var/lib/grafana --link d13cacf78b0ecd41271542c3bd393948aee07b31ebfe880d4b4ad5b73e66d02f:prometheus grafana/grafana 

启动后访问3000 默认的账号密码是admin/admin 登陆后修改密码 现在启动所有项目

 选择创建数据源:

 因为我这个是docker装的host 就是填写link 起的别名如果你是安装包直接填写ip 我的是最新版本所以版本

 链接成功了就:

6.配置grafana 面板

官方已经做好了很多的面板模版 不用你自己配置,自己想配置也行  官方的模版地址

Dashboards | Grafana Labs

spring boot 那块:

我用的模版ID 10280

仪表盘选择导入选择 模版ID 点击确定 

想监管服务的响应时间 可以使用 micrometer-registry-prometheus @Timed注解 和 @Counted 注解 不然也是会带的 只不过不细分

黑盒测试:新增一个面板  

模版ID 找不到了 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/743245.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

003.PADS VX2.4选项设置及显示颜色设置

文章目录 一、PADS颜色设置及选项设置二、选项设置1.全局2.设计3.栅格和捕获4.显示5.布线选项页6.覆铜平面选项页7.文本和线选项页8.文本和线选项页9.过孔样式选项页 一、PADS颜色设置及选项设置 一、颜色设置 1&#xff0e;点击设置—显示颜色&#xff09;&#xff08;快捷键…

Kkfileview | Docker | 文件预览kkfile配置

文章目录 简介DockerRedis部署 简介 kkFileView为文件文档在线预览解决方案&#xff0c;该项目使用流行的spring boot搭建&#xff0c;易上手和部署&#xff0c;基本支持主流办公文档的在线预览&#xff0c;如doc,docx,xls,xlsx,ppt,pptx,pdf,txt,zip,rar,图片,视频,音频等等 …

SQLSERVER 临时表 和 表变量 有区别吗

一&#xff1a;背景 1. 讲故事 今天和大家聊一套面试中经常被问到的高频题&#xff0c;对&#xff0c;就是 临时表 和 表变量 这俩玩意&#xff0c;如果有朋友在面试中回答的不好&#xff0c;可以尝试看下这篇能不能帮你成功迈过。 二&#xff1a;到底有什么区别 1. 前置思…

十五、flex弹性元素的样式

目录&#xff1a; 1. 基本布局 2. 弹性元素的属性&#xff1a;flex-grow 3. 弹性元素的属性&#xff1a;flex-shrink 4. 弹性元素的属性&#xff1a;flex-basis 5. flex 统一设置这3个属性&#xff08;常用&#xff09; 6. order 一、基本布局 <style>*{margin: 0;paddin…

【Maven】类或者包提示找不到,报红

背景 使用IDEA&#xff0c;类或者包提示找不到&#xff0c;报红 解决方法 1. maven reload 2. 检查profiles是否对 3. 不要选中offline模式 4. 检查本地仓库位置 5. 清掉idea缓存 6. 到本地maven仓库删掉出错的包然后重新maven reload 7. update本地仓库 8. 排查是不是别人没…

智慧用电安全监控管理系统

智慧用电安全监控管理系统是一种基于物联网技术的用电安全管理系统&#xff0c;它通过远程通信技术和云计算平台&#xff0c;实现了对电气设备的实时监控、数据采集、费用计算、远程控制等功能。该系统不仅可以提高用电安全管理的效率&#xff0c;还可以为用户提供更加便捷、可…

Linux(centos 7)将 ens33 改为 eth0

背景&#xff1a; 先说明一下 eth0 与 ens33 的关系&#xff0c;目前的主流网卡为使用以太网络协定所开发出来的以太网卡&#xff08;Ethernet)&#xff0c;因此我们 Linux 就称呼这种网络接口为 ethN (N为数字)。 举个例子&#xff1a;就是说主机上面有一张以太网卡&#xff0…

C++线性表、单链表

概述 在先说链表前&#xff0c;我们先来理清几个概念。 什么是线性表、顺序表和链表&#xff1f;三者有什么关系&#xff1f; 线性表&#xff1a;元素线性排列&#xff0c;在逻辑上具有次序的存储结构。 顺序表&#xff1a;线性表的顺序存储称为线性表。它是用一组地址连续(逻…

抖音短视频seo源码开发部署-技术分享(四)

一、 抖音短视频seo源码开发流程 抖音短视频SEO源码开发流程如下&#xff1a; 1.分析需求&#xff1a;首先需要明确你的SEO目标。分析竞争对手&#xff0c;了解抖音短视频平台的规则&#xff0c;选定目标关键词和主题。 2.编写代码&#xff1a;根据需求编写代码&#xff0c;…

docker 安装向量数据库 Milvus

Miluvs 官网为 www.milvus.io/ Milvus 向量数据库能够帮助用户轻松应对海量非结构化数据&#xff08;图片 / 视频 / 语音 / 文本&#xff09;检索。单节点 Milvus 可以在秒内完成十亿级的向量搜索&#xff08;请参考&#xff1a;在线教程&#xff09;&#xff0c;分布式架构亦…

This application failed to start?

大家好&#xff0c;最近在搞一个定制的图像分割项目&#xff0c;其中需要自己构建数据集。 这里我用到了基于paddle开发高效智能的交互式分割标注软件 EISeg(Efficient Interactive Segmentation)。 它涵盖了通用、人像、遥感、医疗、视频等不同方向的高质量交互式分割模型。另…

低代码——现代数字化人才培养的创新引擎

如今&#xff0c;随着数字时代的蓬勃发展&#xff0c;催生了各行各业数字化转型的浪潮。如果说技术是衍生数字时代的基石&#xff0c;那数字化人才一定是这场浪潮中不可或缺的推动力量。 随着新兴技术的不断创新和应用&#xff0c;全行业对于复合型、创新型的优秀数字化人才需…

四种常见分布式限流算法实现!

大家好&#xff0c;我是老三&#xff0c;最近公司在搞年终大促&#xff0c;随着各种营销活动“组合拳”打出&#xff0c;进站流量时不时会有一个小波峰&#xff0c;一般情况下&#xff0c;当然是流量越多越好&#xff0c;前提是系统能杠地住。大家都知道&#xff0c;一个分布式…

css 网页色调变为黑白

在html的css中加入 filter: grayscale(1);

Java Springboot设置MySQL的ssl连接访问

一、需求背景 需要修改应用程序通过SSL连接mysql数据库。 环境配置 数据库&#xff1a;MySQL 8.0.21 &#xff08;enabled SSL&#xff09; Java版本&#xff1a;openjdk version "1.8.0_332" Springboot版本&#xff1a;v2.5.3 二、生成证书 下面是MySQL数据库服…

提升1Panel的安全性:在Armbian上设置个性化SSL证书

文章目录 基础知识OpenSSLOpenSSL常用命令SSL证书与DDoS攻击SSL证书常见办法机构 armbian安装OpenSSLOpenSSL下载和安装生成私钥和证书生成私钥和证书提示信息的解释challenge password 可能遇到的错误 安装完成后的思考完整的操作演示 基础知识 OpenSSL OpenSSL是一个开源的…

软件工程——第11章面向对象设计知识点整理

本专栏是博主个人笔记&#xff0c;主要目的是利用碎片化的时间来记忆软工知识点&#xff0c;特此声明&#xff01; 文章目录 1.什么是面向对象设计&#xff08;OOD&#xff09;&#xff1f; 2.优秀设计的主要特点是&#xff1f; 3.面向对象设计应遵循的准则有哪些&#xff1f…

检验样本正态性

简介 在统计学中很多推论与正态分布有关&#xff0c;并且很多统计量构造为满足正态分布的形式&#xff0c;很多分布在特定条件近似于正态分布。因此&#xff0c;在统计推断中经常需要判断样本的正态性。本文介绍一些常用的方法。 环境和数据准备&#xff1a; import numpy a…

CCLINK IE FIELD BASIC转MODBUS-TCP网关modbus tcp与tcp/ip的区别

协议的不同&#xff0c;数据读取困难&#xff0c;这是很多生产管理系统的难题。但是现在&#xff0c;远创智控YC-CCLKIE-TCP通讯网关&#xff0c;让这个问题变得非常简单。这款通讯网关可以将各种MODBUS-TCP设备接入到CCLINK IE FIELD BASIC网络中&#xff0c;连接到MODBUS-TCP…

在 Jetpack Compose 中使用 BottomDrawer

简介 Jetpack Compose 是一个现代化的&#xff0c;声明式的 UI 工具包&#xff0c;它让我们可以更方便地构建原生 Android UI。在本篇文章中&#xff0c;我们将会讨论如何在 Jetpack Compose 中使用 BottomDrawer。 什么是 BottomDrawer? BottomDrawer 是一种 UI 元素&…