背景
実家は太陽光発電を備えている。 ただ、商用電源と太陽光発電の切り替えの際に一瞬電気が落ちる。この時にコンピュータの電源も落ちる。これがいやなのでUPSを買った。 しかし、UPSをリモートモニタリングできないことが判明した。 USBでUPSに接続して、専用のソフトをインストールしないとモニタリングできないことがわかった。 なので、UPSモニタリングをするためのサーバを導入する。 ラズパイで監視する。
1. NUTをインストール
sudo apt update
sudo apt install nut -y
2. UPSのUSB接続を確認
UPSがUSBで認識されているか確認します。
pi@alpha:/etc/nut $ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 0764:0601 Cyber Power System, Inc. PR1500LCDRT2U UPS
Bus 001 Device 003: ID 0c45:1202 Microdia
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Cyber Powerが接続されていることがわかる。
3. /etc/nut/ups.confの設定
sudo vim /etc/nut/ups.conf
以下を追加
[cyberpower]
driver = usbhid-ups
port = auto
desc = "CyberPower UPS"
4. /etc/nut/nut.confの設定
以下を追記
MODE=standalone
⚠ MODE=none では動かないので standalone にする!
5 /etc/nut/upsd.confの設定
以下をコメントアウト
LISTEN 127.0.0.1 3493
6. サービスの起動
sudo systemctl restart nut-server nut-driver
sudo systemctl enable nut-server
sudo systemctl enable nut-driver
upsの状態を確認
upsc cyberpower@localhost
出力レイ
pi@alpha:/etc/nut $ upsc cyberpower@localhost
Init SSL without certificate database
battery.charge: 100
battery.charge.low: 10
battery.charge.warning: 20
battery.mfr.date: CPS
battery.runtime: 11425
battery.runtime.low: 300
battery.type: PbAcid
battery.voltage: 27.2
battery.voltage.nominal: 24
device.mfr: CPS
device.model: CP1200PFCLCD JP
device.serial: BHZPY2000203
device.type: ups
driver.name: usbhid-ups
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.synchronous: no
driver.version: 2.7.4
driver.version.data: CyberPower HID 0.4
driver.version.internal: 0.41
input.voltage: 100.0
input.voltage.nominal: 100
output.voltage: 100.0
ups.beeper.status: enabled
ups.delay.shutdown: 20
ups.delay.start: 30
ups.load: 0
ups.mfr: CPS
ups.model: CP1200PFCLCD JP
ups.productid: 0601
ups.realpower.nominal: 780
ups.serial: BHZPY2000203
ups.status: OL
ups.test.result: No test initiated
ups.timer.shutdown: -60
ups.timer.start: -60
ups.vendorid: 0764
おまけ
監視あるところにprometheus-exporterあり ということで、もちろん有志のprometheus-exporterが githubに転がっています。
設定方法
git clone https://github.com/DRuggeri/nut_exporter
pi@alpha:~/nut_exporter $ cd nut_exporter/
collectors Dockerfile go.sum nut_exporter nut_exporter_test.go scripts
dashboard go.mod LICENSE nut_exporter.go README.md
pi@alpha:~/nut_exporter/nut_exporter $ go build
./nut_exporter --nut.server="127.0.0.1" --nut.serverport=3493 --nut.vars_enable="battery.charge,battery.charge.low,battery.charge.warning,battery.runtime,battery.runtime.low,battery.voltage,battery.voltage.nominal,input.voltage,input.voltage.nominal,output.voltage,ups.beeper.status,ups.load,ups.status"