prometheus+grafana替代Zabbix监控springboot

本文涉及的产品
可观测可视化 Grafana 版,10个用户账号 1个月
简介: prometheus+grafana替代Zabbix监控springboot


image.png

1.下载可视化模板

通过上文可知grafana为显示页面,所以本文提供一份监控springboot的json页面供大家下载。

链接:https://pan.baidu.com/s/1h5yrTsqUKj-Kq3GuHtNWow

提取码:ehbv

2.配置SpringBoot

1.修改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 http://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.1.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <groupId>com.dalaoyang</groupId>
  <artifactId>springboot2_prometheus</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>springboot2_prometheus</name>
  <description>springboot2_prometheus</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>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-registry-prometheus</artifactId>
      <version>1.1.3</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
</project>

2.修改application.yml

management:
  endpoints:
    web:
      exposure:
        include: '*'
  metrics:
    tags:
      application: ${spring.application.name}
  health:
    redis:
      enabled: false

3.设置application

在启动问价中加入以下代码。

image.png

    @Bean
    MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName) {
        return (registry) -> registry.config().commonTags("application", applicationName);
    }

SpringBoot项目到这里就配置完成了,启动项目,访问http://ip:8080/actuator/prometheus即可看到返回值,这些值就是spring boot返回在前台页面的信息。

image.png

3.Prometheus配置

在prometheus配置监控我们的SpringBoot应用,完整配置如下所示。找到配置文件替换即可。

# 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'
    static_configs:
    - targets: ['localhost:9090']
  - job_name: 'springboot_system' #监控任务名称
    scrape_interval: 5s
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['localhost:8088']    #springboot端口号

启动Prometheus ,访问 ip:9090,然后按照下图操作,即可看到已经注册到Prometheus 的监控任务。

image.png

4.Grafana配置

输入ip:3000,可以进入grafana的可视化界面。

1.配置prometheus数据源 (ip:9090)

image.png

image.png

上图填写你prometheus地址,端口切记填写9090,点击save后,如果失败会有提示 。

2.导入可视化模板

然后导入上文下载好的可视化界面模板。

image.png

选择上文配置好的数据源,prometheus选项就是上文配置的数据源。

image.png

3.验证

image.png

出现以上画面 配置完成!


相关文章
|
14天前
|
Prometheus 监控 Cloud Native
Ubantu docker学习笔记(九)容器监控 自带的监控+sysdig+scope+cAdvisor+prometheus
Ubantu docker学习笔记(九)容器监控 自带的监控+sysdig+scope+cAdvisor+prometheus
|
15天前
|
弹性计算 Prometheus 监控
基于 Prometheus 的超算弹性计算场景下主机监控最佳实践
超算快速弹性伸缩场景下,如何构建一套准确、快速、可靠的监控体系成为关键点。阿里云在超算场景的主机监控落地实践,解决超算场景面临的挑战,交付一套可靠和全面的主机监控体系。
59748 13
|
15天前
|
Prometheus 监控 Cloud Native
Prometheus监控平台配置--监控集群资源信息
在scrape_configs 配置项下添加Linux 监控的job,其中 IP 修改为上面部署node_exporter机器的ip,端口号为9100,需要注意缩进。
176 6
|
22天前
|
Prometheus 监控 Cloud Native
应用监控(Prometheus + Grafana)
应用监控(Prometheus + Grafana)
189 2
|
22天前
|
开发框架 监控 Java
深入探索Spring Boot的监控、管理和测试功能及实战应用
【5月更文挑战第14天】Spring Boot是一个快速开发框架,提供了一系列的功能模块,包括监控、管理和测试等。本文将深入探讨Spring Boot中监控、管理和测试功能的原理与应用,并提供实际应用场景的示例。
21 2
|
22天前
|
Prometheus 监控 Cloud Native
使用Prometheus配置监控与报警
通过以上步骤,你可以使用Prometheus和Alertmanager实现监控和报警配置,以确保系统在出现性能问题或故障时能够及时通知相关人员。欢迎关注威哥爱编程,一起学习成长。
144 0
|
22天前
|
缓存 监控 Java
SpringBoot健康监控
SpringBoot健康监控
11 1
|
22天前
|
Prometheus 监控 Cloud Native
Spring Boot 应用可视化监控
Spring Boot 应用可视化监控
29 0
|
22天前
|
数据采集 监控 数据库
请问OceanBase社区版能否通过zabbix监控,然后将报错信息展现到grafana?
【2月更文挑战第25天】请问OceanBase社区版能否通过zabbix监控,然后将报错信息展现到grafana?
29 2
|
22天前
|
监控 druid Java
Spring Boot3整合Druid(监控功能)
Spring Boot3整合Druid(监控功能)
101 1