iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > GO >golang通过node_exporter监控GPU及cpu频率、温度的代码
  • 311
分享到

golang通过node_exporter监控GPU及cpu频率、温度的代码

2024-04-02 19:04:59 311人浏览 薄情痞子
摘要

导语:通过node_exporter监控GPU以及cpu频率、温度,不想用一个node_exporter再加一个dcgm,分开监控。我这里监控的是热区的温度。如果需要监控各个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

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的可执行文件。

这个版本添加了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 给出。

$ 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 个内核):

.../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的温度 需要

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频率温度内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

您可能感兴趣的文档:

--结束END--

本文标题: golang通过node_exporter监控GPU及cpu频率、温度的代码

本文链接: https://www.lsjlt.com/news/148309.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作