我是靠谱客的博主 心灵美大船,这篇文章主要介绍golang通过node_exporter监控GPU及cpu频率、温度的代码,现在分享给大家,希望可以做个参考。

导语:通过node_exporter监控GPU以及cpu频率、温度,不想用一个node_exporter再加一个dcgm,分开监控。我这里监控的是热区的温度。如果需要监控各个cpu核心的温度需要修改一下代码。

结合了https://gitee.com/kevinliu_CQ/node_exporter监控GPU的代码。

加入了cpu的2项自定义监控https://gitee.com/jiaminxu/self_node_exporter

安装一下go

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
wget https://dl.google.com/go/go1.16.5.linux-amd64.tar.gz tar -xvf go1.16.5.linux-amd64.tar.gz cp -r ./go /usr/local cd /usr/local/go/bin cp -r * /usr/bin mkdir -p $HOME/go echo "export GOROOT=$HOME/go" >> /etc/profile echo "export GOPATH=$HOME/gopath" >> /etc/profile echo "export PATH=$PATH:$GOROOT/bin:$GOPATH/bin" >> /etc/profile echo "export env -w GO111MODULE=on" >> /etc/profile echo "export env -w GOPROXY=https://goproxy.io,direct" >> /etc/profile source /etc/profile cd /srv/ git clone https://gitee.com/kevinliu_CQ/node_exporter.git cd node_exporter/ # cp自己的go文件到collector/下 mkdir -p /usr/local/cuda/include cp -p nvml.h /usr/local/cuda/include export GOPROXY=https://goproxy.cn go build

编译完直接使用./node_exporter二进制文件即可。

gitee中已经编译好了amd64的可执行文件。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
这个版本添加了Nvidia GPU信息的抓取,所以编译的时候需要nvml.h 复制到/usr/local/cuda/include 目录里面 1. 复制依赖 ​```bash mkdir -p /usr/local/cuda/include cp -p nvml.h /usr/local/cuda/include ​``` 2. 定义GOPROXY变量 ​```bash export GOPROXY=https://goproxy.cn ​``` 3. 编译项目 ​```bash cd /root/gitee_node_exporter go build 如果报错kit相关需要替换"github.com/go-kit/log"为"github.com/go-kit/kit/log" ​``` 4. 在如果一切正常在目录中会生成node_exporter的可执行二进制文件 5. 运行即可 ​```bash ./node_exporter --web.listen-address=":19200" ​``` 6. 打包arm64架构的方法 * apt install gcc-aarch64-linux-gnu * env CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC_FOR_TARGET=gcc-aarch64-linux-gnu CC=aarch64-linux-gnu-gcc go build

CPU 温度(最热的核心)由 x86_pkg_temp 给出。

复制代码
1
2
$ cat /sys/class/thermal/thermal_zone10/type x86_pkg_temp

然后/sys/class/thermal/thermal_zone10/temp是应该在 i3 状态栏中使用的文件。

附带说明一下,每个内核的温度都可以temp*_input/sys/devices/platform/coretemp.0/hwmon/hwmon*/. 关联temp*_label显示哪个文件与哪个内核相关(在我的例子中是 4 个内核):

复制代码
1
2
3
4
5
6
.../hwmon*/$ grep "" temp*_label temp1_label:Physical id 0 temp2_label:Core 0 temp3_label:Core 1 temp4_label:Core 2 temp5_label:Core 3

该文件temp1_input对应于内核的最热值。

如果要获取对应每个cpu的温度 需要

复制代码
1
cat /sys/devices/platform/coretemp.0/hwmon/hwmon2/temp1_input

参考

https://qa.1r1g.cn/unix/ask/21339181/

https://cloud.tencent.com/developer/article/1820706

到此这篇关于golang通过node_exporter监控GPU及cpu频率、温度的文章就介绍到这了,更多相关golang监控GPU频率温度内容请搜索靠谱客以前的文章或继续浏览下面的相关文章希望大家以后多多支持靠谱客!

最后

以上就是心灵美大船最近收集整理的关于golang通过node_exporter监控GPU及cpu频率、温度的代码的全部内容,更多相关golang通过node_exporter监控GPU及cpu频率、温度内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(103)

评论列表共有 0 条评论

立即
投稿
返回
顶部