使用RPi-Monitor監控、統計Guitar的運行狀態


前言

之前發在ickey社區上的一系列文章:

  1. 猶抱琵琶半遮面,無人知是荔枝來——unboxing & interview
  2. 葡萄美酒夜光杯,巧婦難為無米炊——資料與社區
  3. 一支穿雲箭,板子要加散熱片——系統監控與發熱問題
  4. 念去去千里煙波,暮靄沉沉楚天闊——遠程控制相關
  5. 竹喧歸浣女,蓮動小輕舟——延長板載eMMC壽命、優化性能

RPi-Monitor簡介

前文 講到如何通過一個shell腳本獲取CPU狀態和PMU溫度,而RPi-Monitor基於perl,內置webserver,通過優化后對sd卡占用更少。由於其極強的可定制性與拓展性,你可以換用熟悉的Web Server,顯示服務狀態,甚至作為視頻監控。最早是基於樹莓派的項目,后來在XApple社區發現有人移植到蓮霧派,今天cnx-software也報道了,特此記錄下來。之前都是使用的phpsysinfo

項目主頁:http://rpi-experiences.blogspot.com/
Github主頁: https://github.com/XavierBerger/RPi-Monitor

開始頁面

統計頁面

直接用cnx-software的圖了

安裝配置

添加rpimonitor源

sudo -s
apt-get install apt-transport-https ca-certificates
wget https://raw.githubusercontent.com/XavierBerger/RPi-Monitor/master/init/apt/sources.list.d/rpimonitor.list -O /etc/apt/sources.list.d/rpimonitor.list
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 2C0D3C0F

安裝升級RPi-Monitor

apt-get update && apt-get install rpimonitor && apt-get upgrade

停止服務添加自定義模塊

systemctl stop rpimonitor
nano /etc/rpimonitor/template/S500_ATC2603.conf

輸入以下內容:

########################################################################
# Extract S500/ATC2603 information
#  Page: 1
#  Information               Status     Statistics
#  - cpu frequency           - yes      - yes
#  - cpu load 1, 5, 15       - yes      - yes
#  - cpu scaling governor    - yes      - no
#  - power in voltage        - yes      - yes
#  - power in consumption    - yes      - yes
#  - USB OTG voltage         - yes      - yes
#  - USB OTG consumption     - yes      - yes
#  - battery consumption     - yes      - yes
#  - total consumption       - yes      - yes
#  - power in current        - yes      - yes
#  - USB OTG current         - yes      - yes
#  - soc temperature         - yes      - yes
#  - pmu temperature         - yes      - yes
########################################################################
dynamic.1.name=cpu_frequency
dynamic.1.source=/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
dynamic.1.regexp=(.*)
dynamic.1.postprocess=$1/1000
dynamic.1.rrd=GAUGE

dynamic.2.name=load1,load5,load15
dynamic.2.source=/proc/loadavg
dynamic.2.regexp=^(\S+)\s(\S+)\s(\S+)
dynamic.2.postprocess=
dynamic.2.rrd=GAUGE

dynamic.3.name=scaling_governor
dynamic.3.source=/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
dynamic.3.regexp=(.*)
dynamic.3.postprocess=
dynamic.3.rrd=

dynamic.4.name=ac_voltage
dynamic.4.source=/sys/devices/b0170000.i2c/i2c-0/0-0065/atc2603c-hwmon.0/wall_voltage
dynamic.4.regexp=(.*)
dynamic.4.postprocess=sprintf("%.2f", $1/1000)
dynamic.4.rrd=GAUGE

dynamic.5.name=ac_consumption
dynamic.5.source=/sys/devices/b0170000.i2c/i2c-0/0-0065/atc2603c-hwmon.0/wall_current
dynamic.5.regexp=(.*)
dynamic.5.postprocess=sprintf("%.2f", $1/153 * $this->{'dynamic'}->{'ac_voltage'})
dynamic.5.rrd=GAUGE

dynamic.6.name=usb_voltage
dynamic.6.source=/sys/devices/b0170000.i2c/i2c-0/0-0065/atc2603c-hwmon.0/vbus_voltage
dynamic.6.regexp=(.*)
dynamic.6.postprocess=sprintf("%.2f", $1/1000)
dynamic.6.rrd=GAUGE

dynamic.7.name=usb_consumption
dynamic.7.source=/sys/devices/b0170000.i2c/i2c-0/0-0065/atc2603c-hwmon.0/vbus_current
dynamic.7.regexp=(.*)
dynamic.7.postprocess=sprintf("%.2f", $1/1000 * $this->{'dynamic'}->{'usb_voltage'})
dynamic.7.rrd=GAUGE

dynamic.8.name=battery_consumption
dynamic.8.source=/sys/devices/b0170000.i2c/i2c-0/0-0065/atc2603c-hwmon.0/bat_current
dynamic.8.regexp=(.*)
dynamic.8.postprocess=sprintf("%.2f", $1/1000)
dynamic.8.rrd=GAUGE

dynamic.9.name=total_consumption
dynamic.9.source=/sys/devices/b0170000.i2c/i2c-0/0-0065/atc2603c-hwmon.0/bat_voltage
dynamic.9.regexp=(.*)
dynamic.9.postprocess=sprintf("%.2f", $1/1000 + $this->{'dynamic'}->{'ac_consumption'} + $this->{'dynamic'}->{'usb_consumption'})
dynamic.9.rrd=GAUGE

dynamic.10.name=usb_current
dynamic.10.source=/sys/devices/b0170000.i2c/i2c-0/0-0065/atc2603c-hwmon.0/vbus_current
dynamic.10.regexp=(.*)
dynamic.10.postprocess=sprintf("%.2f", $1/1000)
dynamic.10.rrd=GAUGE

dynamic.11.name=ac_current
dynamic.11.source=/sys/devices/b0170000.i2c/i2c-0/0-0065/atc2603c-hwmon.0/wall_current
dynamic.11.regexp=(.*)
dynamic.11.postprocess=sprintf("%.2f", $1/153)
dynamic.11.rrd=GAUGE

dynamic.12.name=soc_temp
dynamic.12.source=/sys/devices/virtual/thermal/thermal_zone1/temp
dynamic.12.regexp=(.*)
dynamic.12.postprocess=sprintf("%.1f", $1/1000)
dynamic.12.rrd=GAUGE

dynamic.13.name=pmu_temp
dynamic.13.source=/sys/devices/b0170000.i2c/i2c-0/0-0065/atc2603c-hwmon.0/ic_temperature
dynamic.13.regexp=(.*)
dynamic.13.postprocess=sprintf("%.1f", $1/1000)
dynamic.13.rrd=GAUGE

web.status.1.content.1.name=CPU
web.status.1.content.1.icon=cpu.png
web.status.1.content.1.line.1="Loads: <b>" + data.load1 + "</b> [1min] - <b>" + data.load5 + "</b> [5min] - <b>" + data.load15 + "</b> [15min]"
web.status.1.content.1.line.2="CPU frequency: <b>" + data.cpu_frequency + "MHz</b>  Governor: <b>" + data.scaling_governor + "</b>"

web.status.1.content.2.name=PMU
web.status.1.content.2.icon=pmu.png
web.status.1.content.2.line.1="Total PMU Consumption: <b>" + data.total_consumption + " W</b>"
web.status.1.content.2.line.2="PWR in: <b>" + data.ac_consumption + " W</b> USB OTG in: <b>" + data.usb_consumption + " W</b> BATT in: <b>" + data.battery_consumption + " W</b>"

web.status.1.content.3.name=Temperature
web.status.1.content.3.icon=cpu_temp.png
web.status.1.content.3.line.1=JustGageBar("SoC", "°C",0, data.soc_temp , 125,100,80,percentColors,70,85)+" "+JustGageBar("PMU", "°C",0, data.pmu_temp , 125,100,80,percentColors,70,85)

web.statistics.1.content.1.name=Load / cpufreq / Consumption
web.statistics.1.content.1.graph.1=load1
web.statistics.1.content.1.graph.2=load5
web.statistics.1.content.1.graph.3=load15
web.statistics.1.content.1.graph.4=total_consumption
web.statistics.1.content.1.graph.5=cpu_frequency
web.statistics.1.content.1.ds_graph_options.load1.label=Load 1 min
web.statistics.1.content.1.ds_graph_options.load5.label=Load 5 min
web.statistics.1.content.1.ds_graph_options.load15.label=Load 15 min
web.statistics.1.content.1.ds_graph_options.total_consumption.label=Consumption (W)
web.statistics.1.content.1.ds_graph_options.cpu_frequency.label=Clock speed (MHz)
web.statistics.1.content.1.ds_graph_options.cpu_frequency.yaxis=2
web.statistics.1.content.1.graph_options.y2axis={ position: "right" }

web.statistics.1.content.2.name=PMU current/voltage
web.statistics.1.content.2.graph.1=ac_voltage
web.statistics.1.content.2.graph.2=usb_voltage
web.statistics.1.content.2.graph.3=ac_current
web.statistics.1.content.2.graph.4=usb_current
web.statistics.1.content.2.graph.5=battery_consumption
web.statistics.1.content.2.ds_graph_options.ac_voltage.label=Voltage PWR in (V)
web.statistics.1.content.2.ds_graph_options.usb_voltage.label=Voltage USB OTG (V)
web.statistics.1.content.2.ds_graph_options.ac_current.label=Current PWR in (A)
web.statistics.1.content.2.ds_graph_options.usb_current.label=Current USB OTG (mA)
web.statistics.1.content.2.ds_graph_options.battery_consumption.label=Consumption Battery (W)
web.statistics.1.content.2.ds_graph_options.ac_voltage.yaxis=1
web.statistics.1.content.2.ds_graph_options.usb_voltage.yaxis=1
web.statistics.1.content.2.ds_graph_options.ac_current.yaxis=2
web.statistics.1.content.2.ds_graph_options.usb_current.yaxis=2
web.statistics.1.content.2.ds_graph_options.battery_consumption.yaxis=1
web.statistics.1.content.2.graph_options.y1axis={ position: "left", min: 1.5, max: 11 }
web.statistics.1.content.2.graph_options.y2axis={ position: "right" }

web.statistics.1.content.3.name=Temperature / Consumption
web.statistics.1.content.3.graph.1=pmu_temp
web.statistics.1.content.3.graph.2=soc_temp
web.statistics.1.content.3.graph.3=total_consumption
web.statistics.1.content.3.ds_graph_options.pmu_temp.label=PMU temperature (°C)
web.statistics.1.content.3.ds_graph_options.soc_temp.label=SoC temperature (°C)
web.statistics.1.content.3.ds_graph_options.total_consumption.label=Consumption (W)
web.statistics.1.content.3.ds_graph_options.total_consumption.yaxis=2
web.statistics.1.content.3.graph_options.y1axis={ position: "left", min: 0, max: 125 }
web.statistics.1.content.3.graph_options.y2axis={ position: "right" }
nano /etc/rpimonitor/template/lemaker_guitar.conf

添加以下內容,創建主配置文件,根據自己需要啟用|禁用模塊:

web.page.icon='img/logo.png'
web.page.menutitle='RPi-Monitor  <sub>('+data.hostname+')</sub>'
web.page.pagetitle='RPi-Monitor ('+data.hostname+')'

web.status.1.name=lemaker_guitar
web.statistics.1.name=lemaker_guitar

include=/etc/rpimonitor/template/version.conf
include=/etc/rpimonitor/template/uptime.conf
include=/etc/rpimonitor/template/S500_ATC2603.conf
include=/etc/rpimonitor/template/memory.conf
include=/etc/rpimonitor/template/swap.conf
include=/etc/rpimonitor/template/sdcard.conf
include=/etc/rpimonitor/template/network.conf
include=/etc/rpimonitor/template/wlan.conf

創建軟鏈接:

ln -sf /etc/rpimonitor/template/lemaker_guitar.conf /etc/rpimonitor/data.conf

重啟rpimonitor服務

systemctl start rpimonitor

訪問網頁前端

假如Guitar的IP為192.168.1.111,那么在瀏覽器里輸入192.168.1.111:8888 即可打開狀態頁面。經過配置可以遠程訪問Guitar之后,無論身處何地都可以及時監控Guitar的運行狀態。
軟件使用GPL3 協議,所以可以對界面進行一些改造。

自定義功能與添加模塊

使用配置文件生成助手

2.6版本之后引入了一個新工具:RPi-Monitor交互式配置文件生成助手 (RPi-Monitor Interactive Configuration Helper),通過運行

rpimonitord -i

可以非常方便地創建自己的監視點。Via

添加傳感器數據

以DHT溫濕度傳感器為例,可以監視溫濕度變化,繪制折線圖,修改之后可以顯示諸多傳感器數值。Via
官網截圖

使用標簽顯示狀態

2.7版本之后引入標簽顯示服務狀態的功能,支持6種顏色:

效果如圖所示:

根據模板修改/etc/rpimonitor/template/services.conf文件即可。稍加改造可以實現更多功能。
注意:最新2.10版/etc/rpimonitor/template/services.conf文件最后一行少一個")",需要自己補上。
nano中可通過Ctrl+E快速跳至行尾。Via

進階用法

其他進階用法及自定義功能。Via

其他模板

總結


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM