macOS编译和运行prometheus2.54

欢迎访问我的GitHub

这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos

本篇概览

  • 本文详述了在macOS(M2芯片)上编译和运行prometheus2.54版本的过程,以及安装node_exporter和grafana并使用prometheus指标进行展示

本地环境

  • 操作系统:macOS Sonoma(14.6.1)
  • go版本:1.23.0
  • prometheus:2.54

准备工作

  • 首先要装好npm,官方编译命令会用到,我这里是用brew安装的
brew install npm
  • 执行npm version命令验证是否安装成功
npm version
{npm: '10.8.3',node: '22.9.0',acorn: '8.12.1',ada: '2.9.0',amaro: '0.1.8',ares: '1.33.1',brotli: '1.1.0',cjs_module_lexer: '1.4.1',cldr: '44.1',icu: '74.2',llhttp: '9.2.1',modules: '127',napi: '9',nbytes: '0.1.1',ncrypto: '0.0.1',nghttp2: '1.63.0',openssl: '3.3.2',simdjson: '3.10.0',simdutf: '5.5.0',sqlite: '3.46.1',tz: '2023c',undici: '6.19.8',unicode: '15.1',uv: '1.49.0',uvwasi: '0.0.21',v8: '12.4.254.21-node.19',zlib: '1.2.12'
}
  • 在编译开源项目时,本地go版本与项目的go版本经常不一致,这时最好有工具能在本地管理多个go版本,如此用到哪个就切换到哪个,我这里用的是gvm,安装方式如下
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
  • 安装成功后,执行gvm listall查看所有可以安装的go版本
gvm listallgvm gos (available)go1go1.0.1go1.0.2go1.0.3go1.1go1.1rc2go1.1rc3......
  • 根据prometheus项目的go.mod中的版本信息,要用到1.23.0版本,这里用gvm来安装,要注意的是gvm支持两种方式:下载源码本地编译、直接下载二进制文件,前一种执行以下命令
gvm install go1.23.0
  • 注意这种方式对已有go版本有一定要求,例如编译1.23就有要求本地必须要有1.20,如果您嫌麻烦,可以选择第二种方式,即直接下载编译好的二进制文件,命令如下,可见是多了个-B参数
gvm install go1.23.0 -B
  • 安装完成后,执行gvm use go1.23.0命令使用
gvm use go1.23.0
Now using version go1.23.0
  • 再检查,版本已经切换成功
go version
go version go1.23.0 darwin/arm64

下载promethus源码

  • 在prometheus的发布页面选择合适的版本,然后下载源码
  • 我这里选择的是2.54.1
    在这里插入图片描述

编译

  • 下载源码后解压,再进入解压后的目录prometheus-2.54.1
  • 执行make build开始编译prometheus源码,控制台只要不报错就是成功,最后输出的是一些依赖包的下载信息
go: downloading github.com/mattn/go-colorable v0.1.13
go: downloading github.com/hashicorp/go-immutable-radix v1.3.1
go: downloading github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
go: downloading github.com/emicklei/go-restful/v3 v3.11.0
go: downloading github.com/hashicorp/golang-lru v0.6.0>   promtool
go: downloading github.com/google/pprof v0.0.0-20240711041743-f6c9dda6c6da
go: downloading github.com/nsf/jsondiff v0.0.0-20230430225905-43f6cf3098c1
  • 查看当前目录,通过更新时间发现新生成了两个文件,这就是编译结果
    在这里插入图片描述
  • 现在编译已经完成,接下来验证这个新编译的prometheus是否可用

部署node_exporter

  • 验证prometheus是否可用的方法是通过prometheus采集当前电脑的机器指标,然后在prometheus页面上查看
  • 首先下载node_exporter,在发布页面选择适合自己电脑的版本,我这里是M2芯片的macOS,因此选择darwin和arm的组合
    在这里插入图片描述
  • 下载后解压,进入node_exporter目录,执行
./node_exporter
  • 在mac系统中这样的文件会比阻止运行,需要手动放开限制
    在这里插入图片描述
  • 启动后控制台输出如下,可见有很多个collector,cpu、磁盘、内存等等
./node_exporter
ts=2024-10-04T11:56:36.515Z caller=node_exporter.go:193 level=info msg="Starting node_exporter" version="(version=1.8.2, branch=HEAD, revision=f1e0e8360aa60b6cb5e5cc1560bed348fc2c1895)"
ts=2024-10-04T11:56:36.515Z caller=node_exporter.go:194 level=info msg="Build context" build_context="(go=go1.22.5, platform=darwin/arm64, user=root@dc3a6de96cb1, date=20240714-11:56:30, tags=unknown)"
ts=2024-10-04T11:56:36.516Z caller=filesystem_common.go:111 level=info collector=filesystem msg="Parsed flag --collector.filesystem.mount-points-exclude" flag=^/(dev)($|/)
ts=2024-10-04T11:56:36.516Z caller=filesystem_common.go:113 level=info collector=filesystem msg="Parsed flag --collector.filesystem.fs-types-exclude" flag=^devfs$
ts=2024-10-04T11:56:36.516Z caller=node_exporter.go:111 level=info msg="Enabled collectors"
ts=2024-10-04T11:56:36.516Z caller=node_exporter.go:118 level=info collector=boottime
ts=2024-10-04T11:56:36.516Z caller=node_exporter.go:118 level=info collector=cpu
ts=2024-10-04T11:56:36.516Z caller=node_exporter.go:118 level=info collector=diskstats
ts=2024-10-04T11:56:36.516Z caller=node_exporter.go:118 level=info collector=filesystem
ts=2024-10-04T11:56:36.516Z caller=node_exporter.go:118 level=info collector=loadavg
ts=2024-10-04T11:56:36.516Z caller=node_exporter.go:118 level=info collector=meminfo
ts=2024-10-04T11:56:36.516Z caller=node_exporter.go:118 level=info collector=netdev
ts=2024-10-04T11:56:36.516Z caller=node_exporter.go:118 level=info collector=os
ts=2024-10-04T11:56:36.516Z caller=node_exporter.go:118 level=info collector=powersupplyclass
ts=2024-10-04T11:56:36.516Z caller=node_exporter.go:118 level=info collector=textfile
ts=2024-10-04T11:56:36.516Z caller=node_exporter.go:118 level=info collector=thermal
ts=2024-10-04T11:56:36.516Z caller=node_exporter.go:118 level=info collector=time
ts=2024-10-04T11:56:36.516Z caller=node_exporter.go:118 level=info collector=uname
ts=2024-10-04T11:56:36.517Z caller=tls_config.go:313 level=info msg="Listening on" address=[::]:9100
ts=2024-10-04T11:56:36.517Z caller=tls_config.go:316 level=info msg="TLS is disabled." http2=false address=[::]:9100

prometheus配置

  • 现在node_exporter已经启动,就等着prometheus来采集数据了,启动prometheus前先准备好对应的配置文件
  • 在构建好的prometheus文件所在目录下,新增config.yml,内容如下
# 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:# 第一个任务是采集prometheus自己的数据- job_name: "prometheus"static_configs:- targets: ["localhost:9090"]# 第二个任务是采集node_exporter的数据- job_name: "my_computer"static_configs:- targets: ["localhost:9100"]

启动prometheus

  • 执行启动命令,并且指定刚才创建的配置文件
./prometheus --config.file=config.yml
  • 启动时控制台输出如下
~/temp/202410/04/prometheus-2.54.1  ./prometheus --config.file=config.yml
ts=2024-10-04T12:21:47.809Z caller=main.go:601 level=info msg="No time or size retention was set so using the default time retention" duration=15d
ts=2024-10-04T12:21:47.809Z caller=main.go:645 level=info msg="Starting Prometheus Server" mode=server version="(version=2.54.1, branch=non-git, revision=non-git)"
ts=2024-10-04T12:21:47.809Z caller=main.go:650 level=info build_context="(go=go1.23.0, platform=darwin/arm64, user=will@willdeAir, date=20241004-10:01:51, tags=netgo,builtinassets,stringlabels)"
ts=2024-10-04T12:21:47.809Z caller=main.go:651 level=info host_details=(darwin)
ts=2024-10-04T12:21:47.809Z caller=main.go:652 level=info fd_limits="(soft=10240, hard=unlimited)"
ts=2024-10-04T12:21:47.809Z caller=main.go:653 level=info vm_limits="(soft=unlimited, hard=unlimited)"
ts=2024-10-04T12:21:47.811Z caller=web.go:571 level=info component=web msg="Start listening for connections" address=0.0.0.0:9090
ts=2024-10-04T12:21:47.812Z caller=main.go:1160 level=info msg="Starting TSDB ..."
ts=2024-10-04T12:21:47.813Z caller=tls_config.go:313 level=info component=web msg="Listening on" address=[::]:9090
ts=2024-10-04T12:21:47.813Z caller=tls_config.go:316 level=info component=web msg="TLS is disabled." http2=false address=[::]:9090
ts=2024-10-04T12:21:47.814Z caller=head.go:626 level=info component=tsdb msg="Replaying on-disk memory mappable chunks if any"
ts=2024-10-04T12:21:47.814Z caller=head.go:713 level=info component=tsdb msg="On-disk memory mappable chunks replay completed" duration=24.958µs
ts=2024-10-04T12:21:47.814Z caller=head.go:721 level=info component=tsdb msg="Replaying WAL, this may take a while"
ts=2024-10-04T12:21:47.815Z caller=head.go:793 level=info component=tsdb msg="WAL segment loaded" segment=0 maxSegment=0
ts=2024-10-04T12:21:47.815Z caller=head.go:830 level=info component=tsdb msg="WAL replay completed" checkpoint_replay_duration=42.209µs wal_replay_duration=547.125µs wbl_replay_duration=42ns chunk_snapshot_load_duration=0s mmap_chunk_replay_duration=24.958µs total_replay_duration=628.75µs
ts=2024-10-04T12:21:47.816Z caller=main.go:1181 level=info fs_type=1a
ts=2024-10-04T12:21:47.816Z caller=main.go:1184 level=info msg="TSDB started"
ts=2024-10-04T12:21:47.816Z caller=main.go:1367 level=info msg="Loading configuration file" filename=config.yml
ts=2024-10-04T12:21:47.830Z caller=main.go:1404 level=info msg="updated GOGC" old=100 new=75
ts=2024-10-04T12:21:47.830Z caller=main.go:1415 level=info msg="Completed loading of configuration file" filename=config.yml totalDuration=13.984667ms db_storage=459ns remote_storage=750ns web_handler=292ns query_engine=375ns scrape=13.677291ms scrape_sd=44.25µs notify=28µs notify_sd=3.417µs rules=1.458µs tracing=12.166µs
ts=2024-10-04T12:21:47.830Z caller=main.go:1145 level=info msg="Server is ready to receive web requests."
ts=2024-10-04T12:21:47.830Z caller=manager.go:164 level=info component="rule manager" msg="Starting rule manager..."

验证prometheus

  • 浏览器打开http://localhost:9090/
    在这里插入图片描述
  • 随意选一个指标查看,这里用的是node_load1,含义是系统一分钟内的负载
    在这里插入图片描述

部署grafana

  • 其实此刻prometheus的验证已经完成了,但如果想了解更多prometheus指标和PromQL的信息,可以部署grafana,然后去查看一些经典视图的详情
  • 先去下载Grafana,在下载页面可以看到各下载链接,需要根据自己电脑的实情下载
    在这里插入图片描述
  • 下载完毕后解压,得到新文件夹grafana-v11.1.7,进入后执行以下命令即可启动grafana
./bin/grafana server
  • 启动成功后控制台信息
INFO [10-04|21:24:36] HTTP Server Listen                       logger=http.server address=[::]:3000 protocol=http subUrl= socket=
ERROR[10-04|21:24:36] Could not get process start time, could not read "/proc": stat /proc: no such file or directory logger=grafana-apiserver
INFO [10-04|21:24:36] Adding GroupVersion playlist.grafana.app v0alpha1 to ResourceManager logger=grafana-apiserver
INFO [10-04|21:24:36] Adding GroupVersion featuretoggle.grafana.app v0alpha1 to ResourceManager logger=grafana-apiserver
INFO [10-04|21:24:39] Update check succeeded                   logger=plugins.update.checker duration=2.81132025s
INFO [10-04|21:24:39] Update check succeeded                   logger=grafana.update.checker duration=2.811167917s
INFO [10-04|21:25:11] Request Completed                        logger=context userId=0 orgId=0 uname= method=GET path=/ status=302 remote_addr=[::1] time_ms=1 duration=1.309584ms size=29 referer= handler=/ status_source=server
INFO [10-04|21:25:21] Usage stats are ready to report          logger=infra.usagestats
  • 现在grafana已经启动,可以在浏览器打开了,地址:http://localhost:3000/
  • 登录页面如下,账号密码都是admin
    在这里插入图片描述
  • 登录后需要配置数据源,这样才能展示prometheus的数据
    在这里插入图片描述
  • 选择Prometheus
    在这里插入图片描述
  • 在配置页面只需填写prometheus地址
    在这里插入图片描述
  • 然后点击底部的Save & test按钮
    在这里插入图片描述
  • 这样就配置好了数据源,接下来去看看有哪些优秀的dashboard值得学习
  • 打开网页https://grafana.com/grafana/dashboards/
  • 因为现在只有node_exporter的指标,所以要做一下过滤
    在这里插入图片描述
  • 这里选择第一个Node Exporter Full,进入详情页后点击下图黄色剪头的按钮,得到这个视图的ID
    在这里插入图片描述
  • 拿到了视图ID,接下来可以去grafana导入了,操作如下,箭头3指向的1860就是视图ID
    在这里插入图片描述
  • 接下来的页面中,选择prometheus数据源,然后导入
    在这里插入图片描述
  • 导入成功后,可以看到机器的各项指标
    在这里插入图片描述
  • 需要注意的是内存指标无法展示,这是因为mac电脑的内存指标与视图中用的不同所致
  • 选一个视图细看,这里选择了网络监控Network Traffic
    在这里插入图片描述
  • 如下图操作,进入编辑页面,可以看到更多详情
    在这里插入图片描述
  • 在编辑页面,可以看到grafana视图是如何使用prometheus指标的,后续我们的开发和配置都能从这里获取参考信息
    在这里插入图片描述
  • 把上面的表达式放到prometheus页面也能展现相同效果
    在这里插入图片描述
  • 至此,整个编译和验证过程已经完成,如果您也在编译和使用prometheus,希望本文能给您一些参考

你不孤单,欣宸原创一路相伴

  1. Java系列
  2. Spring系列
  3. Docker系列
  4. kubernetes系列
  5. 数据库+中间件系列
  6. DevOps系列

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

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

相关文章

openpnp - 底部相机高级校正的参数设置

文章目录 openpnp - 底部相机高级校正的参数设置概述笔记修改 “Radial Lines Per Calibration Z” 的方法不同 “Radial Lines Per Calibration Z”的校验结果不同 “Radial Lines Per Calibration Z”的设备校验动作的比较总结备注END openpnp - 底部相机高级校正的参数设置 …

根据给定的相机和镜头参数,估算相机的内参。

1. 相机分辨率和传感器尺寸 最高分辨率&#xff1a;6000 4000 像素传感器尺寸&#xff1a;22.3 mm 14.9 mm 2. 计算像素大小 需要计算每个像素对应的实际尺寸&#xff08;mm/pixel&#xff09;&#xff1a; 水平方向像素大小&#xff1a; 垂直方向像素大小&#xff1a; …

国外电商系统开发-运维系统批量添加服务器

您可以把您准备的txt文件&#xff0c;安装要求的格式&#xff0c;复制粘贴到里面就可以了。注意格式&#xff01; 如果是“#” 开头的&#xff0c;则表示注释&#xff01;

在掌控板中加载人教版信息科技教学指南中的educore库

掌控板中加载educore库 人教信息科技数字资源平台&#xff08;https://ebook.mypep.cn/free&#xff09;中的《信息科技教学指南硬件编程代码说明》文件中提到“本程序说明主要供教学参考。需要可编程主控板须支持运行MicroPython 脚本程序。希望有更多的主控板在固件中支持ed…

(JAVA)浅尝关于 “栈” 数据结构

1. 栈的概述&#xff1a; 1.1 生活中的栈 存储货物或供旅客住宿的地方&#xff0c;可引申为仓库、中转站。例如酒店&#xff0c;在古时候叫客栈&#xff0c;是供旅客休息的地方&#xff0c;旅客可以进客栈休息&#xff0c;休息完毕后就离开客栈 1.2计算机中的栈 将生活中的…

有些硬盘录像机接入视频汇聚平台EasyCVR后通道不显示/显示不全,该如何处理?

EasyCVR视频监控汇聚管理平台是一款针对大中型项目设计的跨区域网络化视频监控集中管理平台。该平台不仅具备视频资源管理、设备管理、用户管理、运维管理和安全管理等功能&#xff0c;还支持多种主流标准协议&#xff0c;如GB28181、RTSP/Onvif、RTMP、部标JT808、GA/T 1400协…

Pikachu-Sql Inject-数字型注入(GET)

一、、破解 SQL 查询语句中的字段数 ?id1 order by 3 -- // -- 是注释&#xff0c; 加号 在MySQL中会转成空格 order by 1 &#xff0c;by 数字几&#xff0c;就是按照第几列进行排序&#xff1b;如果没有这一行&#xff0c;则报错 如&#xff1a;以下语句&#xff0c;根据…

RabbitMQ(死信队列)

一、本文抒写背景 前面我也在延迟队列篇章提到过死信队列&#xff0c;也提到过一些应用场景&#xff01; 今天呢&#xff0c;这篇文章&#xff0c;主要就是实战一个业务场景的小Demo流程&#xff0c;哈哈&#xff0c;那就是延迟关闭订单。 二、开始啦&#xff01;letgo! 首…

Qt系统学习篇(6)-QMainWindow

QMainWindow是一个为用户提供主窗口程序的类&#xff0c;包含一个菜单栏(menu bar)、多个工具栏(tool bars)、多个锚接部件(dock widgets)、一个状态栏(status bar)及一个中心部件(central widget)&#xff0c;是许多应用程序的基础&#xff0c;如文本编辑器&#xff0c;图片编…

MyBatisPlus——学习笔记

MyBatisPlus 一、导入依赖 <!-- MyBatisPlus --><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.2</version></dependency><!-- MySql --><de…

【AIGC】VoiceControl for ChatGPT指南:轻松开启ChatGPT语音对话模式

博客主页&#xff1a; [小ᶻZ࿆] 本文专栏: AIGC | ChatGPT 文章目录 &#x1f4af;前言&#x1f4af;安装VoiceControl for ChatGPT插件&#x1f4af;如何使用VoiceControl for ChatGPT进行语音输入VoiceControl for ChatGPT快捷键注意点 &#x1f4af;VoiceControl for C…

mfc140u.dll缺失?快速解决方法全解析,解决mfc140u.dll错误

当你的电脑出现找不到mfc140u.dll的问题&#xff0c;不少用户在使用电脑时陷入了困扰。这个错误提示就像一道屏障&#xff0c;阻挡了用户正常使用某些软件。无论是办公软件、游戏还是专业的设计工具&#xff0c;一旦出现这个问题&#xff0c;都会导致软件无法正常运行。如果您也…

webGL入门(六)图形旋转

效果&#xff1a; 代码&#xff1a; <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>Document</…

ndb9300public-ndb2excel简介

1 引言 ndb9300是一个自己定义的机载导航数据库劳作&#xff08;不敢称为项目&#xff09;代号&#xff0c;其中3表示是第3种数据库。 多年前&#xff0c;对在役民航客机中的某型机载导航数据库的二进制文件进行分析&#xff0c;弄明白它的数据结构后做了几个工具&#xff0c…

Redis-持久化机制

Redis持久化方式 rdb -> 全量 aof -> 增量 也可以两种同时开启&#xff0c;混合持久化(4.0 后) rdb 简介 配置文件 redis 6.0.16 及其以下 redis 6.2 7.0 配置说明 有两种触发方式&#xff1a;手动&#xff0c;自动 修改 save 5 2dir /myredis/dump (储存的文件夹需…

【机器学习】探索GRU:深度学习中门控循环单元的魅力

目录 &#x1f354; GRU介绍 &#x1f354; GRU的内部结构图 2.1 GRU结构分析 2.2 GRU工作原理 2.4 Bi-GRU介绍 2.3 使用Pytorch构建GRU模型 2.5 GRU优缺点 &#x1f354; 小结 学习目标 &#x1f340; 了解GRU内部结构及计算公式. &#x1f340; 掌握Pytorch中GRU工具…

1000题-计算机网络系统概述

术语定义与其他术语的关系SDU&#xff08;服务数据单元&#xff09;相邻层间交换的数据单元&#xff0c;是服务原语的表现形式。在OSI模型中&#xff0c;SDU是某一层待传送和处理的数据单元&#xff0c;即该层接口数据的总和。 - SDU是某一层的数据集&#xff0c;准备传递给下一…

【开源免费】基于SpringBoot+Vue.JS洗衣店订单管理系统(JAVA毕业设计)

本文项目编号 T 068 &#xff0c;文末自助获取源码 \color{red}{T068&#xff0c;文末自助获取源码} T068&#xff0c;文末自助获取源码 目录 一、系统介绍二、演示录屏三、启动教程四、功能截图五、文案资料5.1 选题背景5.2 国内外研究现状5.3 可行性分析 六、核心代码6.1 顾…

vue框架学习 -- 日历控件 FullCalendar 使用总结

最近在项目中要实现日期排班的功能&#xff0c;正好要用到日历视图的控件&#xff0c;经过对比发现&#xff0c;vue 中 使用 FullCalendar 可以实现相关需求&#xff0c;下面对使用过程做一个总结。 一. 引入 FullCalendar 控件 package.json 中添加相关依赖 "dependen…

【CSS in Depth 2 精译_043】6.5 CSS 中的粘性定位技术 + 本章小结

当前内容所在位置&#xff08;可进入专栏查看其他译好的章节内容&#xff09; 第一章 层叠、优先级与继承&#xff08;已完结&#xff09;第二章 相对单位&#xff08;已完结&#xff09;第三章 文档流与盒模型&#xff08;已完结&#xff09;第四章 Flexbox 布局&#xff08;已…