0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MackerelでRaspberry PiのCPUクロックの遷移をグラフ表示する

Posted at

Raspberry Piの現在のCPUクロック設定の取得方法

以下のファイルに、現在のCPUクロック設定が格納されています。単位はKHz。

$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq 
600000

MackerelでRaspberry Piのクロックを記録する

Mackerelとは、はてなが提供しているサーバー監視サービスで、無料プランでも5台まで監視できるのでRaspberry Piの監視にちょうどいいです。問題発生時にメールだけでなくLINEに通知するようにもできます。
監視だけでなく、温度などを記録してグラフ表示することができるので、CPUのクロックも表示してみます。

基本的な設定はこちらを参考:Raspberry Pi を Mackerel で監視する

※64bit OSの場合は、mackerel-agent_linux_arm.tar.gzではなくmackerel-agent_linux_arm64.tar.gzを利用します。

CPUクロック設定の表示スクリプトを作る

/home/pi/bin/cpufreq.sh
#!/bin/bash
SECONDS=`date '+%s'`

cpufreq () {
    NAME='freq.'`basename $1`
    FREQ=`cat $1/cpufreq/scaling_cur_freq`
    VALUE=`echo $(($FREQ/1000))`
    echo -e "${NAME}\t${VALUE}\t${SECONDS}"
}


for cpu in `echo /sys/devices/system/cpu/cpu0`; do
    cpufreq $cpu
done

これfor文になってますが、最初は4つのCPUの設定クロックを個別に取得していました。しかし、Raspberry Piの場合、全CPU同一クロック設定だということがわかり、cpu0のみチェックするようにしています。

Macherelのチェック項目として追加

/etc/mackerel-agent/mackerel-agent.conf
[plugin.metrics.cpufreq]
command                 = "/home/pi/bin/cpufreq.sh"

スクリプトの実行によりCPUクロックが上昇する可能性があるので、追加する場所はなるべく先頭のほうがおすすめです。

Mackerel agent再起動

sudo systemctl start mackerel-agent

Mackerelでの表示例

NASとしても使われているRaspberry Piなので、それなりに忙しそうです。

スクリーンショット 2022-02-26 15.39.54.png

関連記事

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?