[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

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爷来辣

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值