[ Spring ] Integrate Spring Boot Service Monitor Prometheus and Grafana

文章目录

          • Install Prometheus Server
          • Install Grafana Server
          • Spring Prometheus Project
          • Spring Prometheus Properties
          • Spring Prometheus Application
          • Spring Prometheus Configuration
          • Spring Prometheus Controller
          • Configure Grafana Dash Board

Install Prometheus Server
# download package
https://github.com/prometheus/prometheus/releases/download/v3.1.0/prometheus-3.1.0.linux-amd64.tar.gz
# edit prometheus config
prometheus-linux-amd64/prometheus.yml
scrape_configs:- job_name: "prometheus"metrics_path: '/actuator/prometheus'scheme: 'http'static_configs:- targets: ["localhost:10003"]
# run server
sudo ./prometheus
# visit admin page
http://localhost:9090
Install Grafana Server
# download package
https://dl.grafana.com/enterprise/release/grafana-enterprise-11.5.0.linux-amd64.tar.gz
# run server
sudo bin/grafana server
# visit admin page
http://localhost:3000 admin/admin
Spring Prometheus Project
pluginManagement {repositories {gradlePluginPortal()google()mavenCentral()}
}dependencyResolutionManagement {repositoriesMode = RepositoriesMode.PREFER_SETTINGSrepositories {gradlePluginPortal()google()mavenCentral()}
}buildscript {repositories {gradlePluginPortal()google()mavenCentral()}
}plugins {id("org.jetbrains.kotlin.jvm") version "2.0.21" apply falseid("org.jetbrains.kotlin.kapt") version "2.0.21" apply falseid("org.jetbrains.kotlin.plugin.spring") version "2.0.21" apply falseid("org.springframework.boot") version "3.4.1" apply false
}include("prometheus-app")
Spring Prometheus Properties
# service
server.port=10003
spring.application.name=prometheus-app
spring.profiles.active=dev
spring.devtools.add-properties=false
management.endpoints.web.exposure.include=*
# prometheus
management.prometheus.metrics.export.enabled=true
Spring Prometheus Application
package x.spring.helloimport org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication@SpringBootApplication
class PrometheusApplicationfun main(args: Array<String>) {runApplication<PrometheusApplication>(*args)
}
Spring Prometheus Configuration
package x.spring.hello.componentimport io.micrometer.core.instrument.Counter
import io.micrometer.core.instrument.MeterRegistry
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.stereotype.Component@Component
class MetricsProvider {@Bean(name = ["count"])fun getCounterMetrics(registry: MeterRegistry,@Value("\${spring.application.name}") name: String): Counter {return registry.counter("count_api_calling_times", "application", name)}
}
Spring Prometheus Controller
package x.spring.hello.controllerimport io.micrometer.core.instrument.Counter
import jakarta.annotation.Resource
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController@RestController
class MetricsController {@Resource(name = "count")private lateinit var counterMetrics: Counter@GetMapping("/count")fun count(): String {counterMetrics.increment()return "count_api_calling_times_total +1"}
}
Configure Grafana Dash Board
# add data source
Connections -> Data Sources -> Add Data Source -> Prometheus
settings.name=prometheus
connection.url=http://localhost:9090
# create dash board
Dashboards -> Create Dashboard -> Add Visualization -> Add Queries -> Run Queries
datasource=prometheus
metrics=count_api_calling_times_total

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

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

相关文章

“现代C++ RAII库:设计、优化及实战应用“

文章目录 代码 示例raii 类的使用示例代码&#xff1a;解释&#xff1a; raii_var 类的使用示例代码&#xff1a;解释&#xff1a; 结合线程使用示例代码&#xff1a;解释&#xff1a; make_raii 函数签名&#xff1a;示例&#xff1a;解释&#xff1a; raii_bind_var 函数签名…

代码随想录day06

242.有效的字母异位词 刚学哈希表想着使用unordered_set来实现&#xff0c;结果无法通过&#xff0c;原因是对字母异位词理解有问题&#xff0c;字母异位词是通过重新排列不同单词或短语的字母而形成的单词或短语&#xff0c;并使用所有原字母一次。对字母出现的次数有要求&am…

Java_双列集合

双列集合特点 存放的是键值对对象&#xff08;Entry&#xff09; Map 因为都是继承Map&#xff0c;所以要学会这些API&#xff0c;后面的类就都知道了 put 有两个操作&#xff0c;添加&#xff08;并返回null&#xff09;或者覆盖&#xff08;返回被覆盖的值&#xff09…

MHTML文件如何在前端页面展示

MHTML文件如何在前端页面展示 需求背景&#xff1a; 目前在给证券公司做项目&#xff0c;但是在使用新系统的过程中&#xff0c;甲方还希望之前之前系统的历史记录可以看到。 最初制定的计划是项目组里面做数据的把原系统页面爬取下来&#xff0c;转成图片&#xff0c;直接给…

解决bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException

解决Spring Boot中MySQL数据库报错“Bad SQL Grammar”的问题 目录 解决Spring Boot中MySQL数据库报错“Bad SQL Grammar”的问题 问题描述解决步骤解决方案结论附&#xff1a;MySql常用配置参数及使用场景 在使用Spring Boot连接MySQL数据库时&#xff0c;有时候会遇到“B…

【AI日记】25.02.08

【AI论文解读】【AI知识点】【AI小项目】【AI战略思考】【AI日记】【读书与思考】【AI应用】 探索 AI 应用探索周二有个面试&#xff0c;明后天打算好好准备一下&#xff0c;我打算主要研究下 AI 如何在该行业赋能和应用&#xff0c;以及该行业未来的发展前景和公司痛点&#…

【AI学习】关于 DeepSeek-R1的几个流程图

遇见关于DeepSeek-R1的几个流程图&#xff0c;清晰易懂形象直观&#xff0c;记录于此。 流程图一 来自文章《Understanding Reasoning LLMs》&#xff0c; 文章链接&#xff1a;https://magazine.sebastianraschka.com/p/understanding-reasoning-llms?continueFlagaf07b1a0…

零基础都可以本地部署Deepseek R1

文章目录 一、硬件配置需求二、详细部署步骤1. 安装 Ollama 工具2. 部署 DeepSeek-R1 模型3. API使用4. 配置图形化交互界面&#xff08;可选&#xff09;5. 使用与注意事项 一、硬件配置需求 不同版本的 DeepSeek-R1 模型参数量不同&#xff0c;对硬件资源的要求也不尽相同。…

索引失效的场景

chatGpt 7. 使用 DISTINCT 或 GROUP BY 当查询中涉及 DISTINCT 或 GROUP BY 时&#xff0c;如果查询没有合适的索引支持&#xff0c;可能会导致性能问题&#xff0c;虽然不完全是索引失效&#xff0c;但会影响查询效率。 sql SELECT DISTINCT department_id FROM employees;…

Node.js中http模块(二)

一、http模块 http 模块是 Node.js 官方提供的、用来创建 web 服务器的模块。通过 http 模块提供的 http.createServer0) 方法&#xff0c;就能方便的把一台普通的电脑&#xff0c;变成一台 Web 服务器&#xff0c;从而对外提供 Web 资源服务。 二、域名和域名服务器 尽管 I…

Dockerfile 文件详解

在平常的开发工作中&#xff0c;我们经常需要部署项目&#xff0c;一个项目开发完成后&#xff0c;使用 Docker 方式部署&#xff0c;那么首先得构造镜像&#xff0c;构造镜像最主要的就是 Dockerfile 文件的编写&#xff0c;今天简单来总结下 Dockerfile 文件的编写以及有哪些…

Git提交错误解决:missing Change-Id in message footer

问题现象&#xff1a; 提交的commit中没有插入change id导致push代码失败。 问题解决&#xff1a; 针对该错误&#xff0c;Git已经给出了解决方案&#xff1a; 1、to automatically insert a Change-Id, install the hook: gitdir$(git rev-parse --git-dir); scp -p -P 2…

第四十一章:沪上逐梦:适应新环境的挑战

2022 年底&#xff0c;凛冽的寒风裹挟着岁末的清冷&#xff0c;毫无保留地席卷了整个华夏大地。上海&#xff0c;这座屹立在东方的繁华都市&#xff0c;在这冰寒彻骨的冬日里&#xff0c;愈发显得冷峻而深沉。小冷怀揣着对新工作的满心期待&#xff0c;以及对未来的无限憧憬&am…

多租户架构设计与实现:基于 PostgreSQL 和 Node.js

多租户架构设计与实现:基于 PostgreSQL 和 Node.js 引言 多租户架构(Multi-tenancy)是现代 SaaS(Software as a Service)应用的核心设计模式之一。它允许多个租户共享同一套应用实例,同时确保数据隔离和安全性。本文将详细介绍多租户架构的设计方案,并基于 PostgreSQL…

顺丰java面试题_顺丰java开发面试分享,顺丰java面试经面试题

今天要给大家分享的是一个小伙伴的顺丰java开发面试过程&#xff0c;其中包括了面试流程&#xff0c;面试题目&#xff0c;和回答&#xff0c;感兴趣的朋友可以来了解一下哈。 一、面试流程 是中午进行的面试&#xff0c;首先是做自我介绍&#xff0c;之后就是讲一下项目&…

天津三石峰科技——汽车生产厂的设备振动检测项目案例

汽车产线有很多传动设备需要长期在线运行&#xff0c;会出现老化、疲劳、磨损等 问题&#xff0c;为了避免意外停机造成损失&#xff0c;需要加装一些健康监测设备&#xff0c;监测设备运 行状态。天津三石峰科技采用 12 通道振动信号采集卡&#xff08;下图 1&#xff09;对…

SpringBoot教程(十四) SpringBoot之集成Redis

SpringBoot教程&#xff08;十四&#xff09; | SpringBoot之集成Redis 一、Redis集成简介二、集成步骤 2.1 添加依赖2.2 添加配置2.3 项目中使用之简单使用 &#xff08;举例讲解&#xff09;2.4 项目中使用之工具类封装 &#xff08;正式用这个&#xff09;2.5 序列化 &…

多智能体协作架构模式:驱动传统公司向AI智能公司转型

前言 在数字化浪潮的席卷下&#xff0c;传统公司的运营模式正面临着前所未有的挑战。随着市场竞争的日益激烈&#xff0c;客户需求的快速变化以及业务复杂度的不断攀升&#xff0c;传统公司在缺乏 AI 技术支撑的情况下&#xff0c;暴露出诸多痛点。在决策层面&#xff0c;由于…

rBits.exe服务备份

Program.cs using System; using System.Collections.Generic; using System.Linq; using System.ServiceProcess; using System.Text; using System.Threading.Tasks;namespace rBits {internal static class Program{/// <summary>/// 应用程序的主入口点。/// </s…

边缘计算网关驱动智慧煤矿智能升级——实时预警、低延时决策与数字孪生护航矿山安全高效运营

迈向智能化煤矿管理新时代 工业物联网和边缘计算技术的迅猛发展&#xff0c;煤矿安全生产与高效运营正迎来全新变革。传统煤矿监控模式由于现场环境复杂、数据采集和传输延时较高&#xff0c;已难以满足当下高标准的安全管理要求。为此&#xff0c;借助边缘计算网关的实时数据…