LoginSignup
1
2

More than 5 years have passed since last update.

CyberPowerのUPSをLinux(Fedora 25)に導入してmuninでグラフ化する

Last updated at Posted at 2017-10-31

UPSのセットアップ

環境は下記の通り。muninは既に動いているものがあるという前提で進める

sh-4.3# cat /etc/redhat-release
Fedora release 25 (Twenty Five)
sh-4.3# uname -a
Linux tndl.net 4.11.3-202.fc25.x86_64 #1 SMP Mon Jun 5 16:38:21 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
sh-4.3# rpm -qa | grep munin
munin-common-2.0.33-1.fc25.noarch
munin-nginx-2.0.33-1.fc25.noarch
munin-2.0.33-1.fc25.noarch
munin-node-2.0.33-1.fc25.noarch

マニュアルに従って下記の順番で設置を行う
3については、付属する日本語マニュアルには載っていないため、CPJ500用のダウンロードページから英語マニュアルとrpmファイルをダウンロードして、インストールを行う

  1. 8時間以上の充電
  2. UPSのコンセントへPC(Server)を接続
  3. 管理用ツールのインストール
  4. USBケーブルの接続

セットアップが正常に完了していれば、pwrstatコマンドでUPSの状態を取得できる

sh-4.3# pwrstat -status

The UPS information shows as following:

    Properties:
        Model Name................... CPJ500
        Rating Voltage............... 100 V
        Rating Power................. 300 Watt(500 VA)

    Current UPS status:
        State........................ Normal
        Power Supply by.............. Utility Power
        Utility Voltage.............. 100 V
        Output Voltage............... 100 V
        Battery Capacity............. 100 %
        Remaining Runtime............ 27 min.
        Load......................... 93 Watt(31 %)
        Line Interaction............. None
        Test Result.................. Unknown
        Last Power Event............. Blackout at 2017/10/23 02:13:16

Muninでのグラフ化

pwrstatで見た感じLoadの消費電力くらいしかグラフ化するものがないので、それ用にテキトーにスクリプトを仕立てる

/etc/munin/plugin-conf.d/wattage
[wattage]
user root
/etc/munin/plugins/wattage
#!/bin/bash

if [ "$1" = "autoconf" ]; then
  echo yes
  exit 0
fi

if [ "$1" = "config" ]; then

  echo 'graph_title Server wattage'
  echo 'graph_args --base 1000 -l 0'
  echo 'graph_vlabel Wattage'

  echo 'graph_scale no'
  echo 'graph_category sensors'

  echo 'wattage.label Server'
  print_warning wattage
  print_critical wattage

  echo 'graph_info Server wattage'
  echo 'wattage.info /sbin/pwrstat'

  # Last, if run with the "config"-parameter, quit here (don't
  # display any data)
  exit 0
fi

echo -n "wattage.value "
pwrstat -status | grep Load | cut -d' ' -f2

/etc/munin/plugins/wattageは実行できるよう実行権限を付与しておく

sh-4.3# chmod +x /etc/munin/plugins/wattage
sh-4.3# ls -la /etc/munin/plugins/wattage
-rwxr-xr-x 1 root root 578 10月 31 21:11 /etc/munin/plugins/wattage

munin-nodeを念のためリロードしておく

sh-4.3# systemctl restart munin-node.service

うまく行けば下記のようなグラフが生成される

wattage-day.png

wattage-week.png

Sun 29 Octの消費電力の上がりは、mdadmのcheckによるもの。HDDがぶん回ると30Wほど消費電力が高くなるのがよく分かる

余談

UPSを購入後のテスト以降特に出番が無かったと思ったが、先日の台風の際に長時間停電していたようで、ログを見たところそれ以前にも何度か瞬断的なUPSの出番があったようだ

/var/log/pwrstatd.log
sh-4.3# cat /var/log/pwrstatd.log
2017/07/21 16:29:14 PM  Daemon startups.
2017/07/21 16:30:26 PM  Communication is established.
2017/07/21 16:34:57 PM  Utility failed.
2017/07/21 16:35:07 PM  Battery capacity is low.
2017/07/21 16:35:07 PM  The UPS will be turned off at 10 min., 0 sec. later.
2017/07/21 16:35:07 PM  Begin to shutdown PC immediately!
2017/07/21 16:37:01 PM  Daemon startups.
2017/07/21 16:37:03 PM  Communication is established.
2017/07/21 16:48:55 PM  Daemon startups.
2017/07/21 17:25:17 PM  Daemon stops its service.
2017/07/21 17:33:08 PM  Daemon startups.
2017/07/21 17:33:10 PM  Communication is established.
2017/07/21 17:47:09 PM  Daemon stops its service.
2017/07/21 17:47:09 PM  Daemon startups.
2017/07/21 17:47:09 PM  Communication is established.
2017/07/21 17:49:24 PM  Utility failed.
2017/07/21 17:49:32 PM  Utility restored.
2017/08/19 16:16:10 PM  Utility failed.
2017/08/19 16:16:27 PM  Utility restored.
2017/08/19 16:16:33 PM  Utility failed.
2017/08/19 16:16:36 PM  Utility restored.
2017/08/19 16:23:13 PM  Utility failed.
2017/08/19 16:23:33 PM  Utility restored.
2017/08/19 16:27:31 PM  Utility failed.
2017/08/19 16:27:52 PM  Utility restored.
2017/08/19 16:27:55 PM  Utility failed.
2017/08/19 16:27:58 PM  Utility restored.
2017/08/19 16:44:34 PM  Daemon stops its service.
2017/08/19 16:45:42 PM  Daemon startups.
2017/08/19 16:45:44 PM  Communication is established.
2017/10/23 02:13:16 AM  Utility failed.
2017/10/23 02:14:17 AM  The UPS will be turned off at 10 min., 0 sec. later.
2017/10/23 02:14:17 AM  Begin to shutdown PC immediately!
2017/10/24 16:52:04 PM  Daemon startups.
2017/10/24 16:52:05 PM  Communication is established.

7/21が導入日
8/19に何度か瞬断かUSBの接続不良でもあった?
10/23が台風による停電

1
2
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
1
2