日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

golang通過node_exporter監控GPU及cpu頻率、溫度的代碼_Golang

作者:爺來辣 ? 更新時間: 2022-07-02 編程語言

導語:通過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

原文鏈接:https://blog.csdn.net/xujiamin0022016/article/details/124648395

欄目分類
最近更新