Commit c88b202e authored by Roman Alifanov's avatar Roman Alifanov

modules: add system_monitor module

parent ae16a549
...@@ -2,6 +2,9 @@ modules_dir = pkgdatadir / 'modules' ...@@ -2,6 +2,9 @@ modules_dir = pkgdatadir / 'modules'
plugins = [ plugins = [
'example_module', 'example_module',
'system_monitor',
] ]
install_subdir(plugins, install_dir: modules_dir) foreach plugin : plugins
install_subdir(plugin, install_dir: modules_dir)
endforeach
#!/bin/bash
get_cpu_usage() {
local cpu_line="$1"
local stat1=$(grep "^${cpu_line} " /proc/stat)
sleep 0.1
local stat2=$(grep "^${cpu_line} " /proc/stat)
local idle1=$(echo "$stat1" | awk '{print $5}')
local idle2=$(echo "$stat2" | awk '{print $5}')
local total1=$(echo "$stat1" | awk '{sum=0; for(i=2;i<=NF;i++) sum+=$i; print sum}')
local total2=$(echo "$stat2" | awk '{sum=0; for(i=2;i<=NF;i++) sum+=$i; print sum}')
local idle_diff=$((idle2 - idle1))
local total_diff=$((total2 - total1))
if [ "$total_diff" -gt 0 ]; then
awk "BEGIN {printf \"%.1f\", 100 * (1 - $idle_diff / $total_diff)}"
else
echo "0.0"
fi
}
case "$1" in
cpu)
get_cpu_usage "cpu"
;;
cpu[0-9]*)
get_cpu_usage "$1"
;;
ram)
free | awk '/Mem:/ {printf "%.1f", $3/$2*100}'
;;
swap)
free | awk '/Swap:/ {if($2>0) printf "%.1f", $3/$2*100; else print "0"}'
;;
esac
- name: "System Monitor"
weight: 50
pages:
- name: "Monitor"
icon: utilities-system-monitor-symbolic
sections:
- name: "CPU"
weight: 0
page: "Monitor"
type: custom
settings:
- name: CPU Total
type: info_graph
update_interval: 1
get_command: "{module_path}/bin/stats.sh cpu"
map:
min: 0
max: 100
points: 60
color: "#e5a50a"
suffix: "%"
- name: "CPU Cores"
weight: 5
page: "Monitor"
type: dynamic
generator_command: "seq 0 $(($(nproc)-1))"
setting_template:
name: "Core {_item}"
type: info_graph
update_interval: 1
get_command: "{module_path}/bin/stats.sh cpu{_item}"
map:
min: 0
max: 100
points: 60
color: "#ff7800"
suffix: "%"
- name: "Memory"
weight: 10
page: "Monitor"
type: custom
settings:
- name: RAM Usage
type: info_graph
update_interval: 1
get_command: "{module_path}/bin/stats.sh ram"
map:
min: 0
max: 100
points: 60
color: "#3584e4"
suffix: "%"
- name: Swap Usage
type: info_graph
update_interval: 2
get_command: "{module_path}/bin/stats.sh swap"
map:
min: 0
max: 100
points: 30
color: "#c061cb"
suffix: "%"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment