From 21a88edfaa6c67dea108b6c3ffdfe0a9190b7e5c Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Wed, 17 Feb 2021 00:15:17 +0000 Subject: [PATCH] Add system-info Linux systemd user unit Update the `system-info` directory with the addition of a `systemd` service file and an new Linux script to display current CPU temperature and core/thread utilization. Update `.conduit.yaml` with addition `apt` dependencies `sysstat` and `jq`. Update the install and remove scripts to setup and tear down the `systemd` user unit. Lastly, decrease the `tmux` status line update interval from 5 to 2 seconds. --- .conduit.yaml | 2 ++ system-info/install.sh | 4 ++++ system-info/remove.sh | 3 +++ system-info/system-info-Linux.sh | 24 ++++++++++++++++++++++++ system-info/system-info.service | 8 ++++++++ tmux.conf | 2 +- 6 files changed, 42 insertions(+), 1 deletion(-) create mode 100755 system-info/system-info-Linux.sh create mode 100644 system-info/system-info.service diff --git a/.conduit.yaml b/.conduit.yaml index fbfae16..5cf9dd0 100644 --- a/.conduit.yaml +++ b/.conduit.yaml @@ -4,6 +4,8 @@ - tmux - xclip - urlview + - sysstat + - jq - brew: - tmux - urlview diff --git a/system-info/install.sh b/system-info/install.sh index 8fc19e4..4dd5e9f 100755 --- a/system-info/install.sh +++ b/system-info/install.sh @@ -5,4 +5,8 @@ script_dir=`dirname $0` if [ `uname` = Darwin ]; then cp $script_dir/system-info.plist ~/Library/LaunchAgents/system-info.plist launchctl load -w ~/Library/LaunchAgents/system-info.plist +else + cp $script_dir/system-info.service ~/.config/systemd/user/system-info.service + systemctl --user enable system-info + systemctl --user start system-info fi diff --git a/system-info/remove.sh b/system-info/remove.sh index cfacc33..872bef0 100755 --- a/system-info/remove.sh +++ b/system-info/remove.sh @@ -3,4 +3,7 @@ if [ `uname` = Darwin ]; then launchctl unload ~/Library/LaunchAgents/system-info.plist rm ~/Library/LaunchAgents/system-info.plist +else + systemctl --user stop system-info + systemctl --user disable system-info fi diff --git a/system-info/system-info-Linux.sh b/system-info/system-info-Linux.sh new file mode 100755 index 0000000..de22269 --- /dev/null +++ b/system-info/system-info-Linux.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +cache_dir=~/.cache/tmux +cache_file=$cache_dir/system-info + +# Make sure the output directory exists. +if [ ! -d $cache_dir ]; then + mkdir -p $cache_dir +fi + +# Cleanup cache file when interrupted. +trap '[ -f $cache_file ] && rm $cache_file; exit' INT +trap '[ -f $cache_file ] && rm $cache_file; exit' TERM + +while true; do + # Parse the current CPU load on all cores/threads. + cpu_load=`mpstat -P ALL -n 1 -u 1 -o JSON | \ + jq '.sysstat.hosts[0].statistics[0]["cpu-load"][1:]|.[].idle' | \ + awk '$idle ~ /[-.0-9]*/ { printf "%s", substr("█▇▆▅▄▃▂▁ ", int($idle / 11), 1) }'` + # Parse the current CPU package temperature. + cpu_temp=`sensors coretemp-isa-0000 | awk 'NR == 3 { print substr($4, 2) }'` + # Write to the cache file. + echo "$cpu_temp $cpu_load" > $cache_file +done diff --git a/system-info/system-info.service b/system-info/system-info.service new file mode 100644 index 0000000..c47ff23 --- /dev/null +++ b/system-info/system-info.service @@ -0,0 +1,8 @@ +[Unit] +Description=System Info + +[Service] +ExecStart=/home/benie/.config/tmux/system-info/system-info-Linux.sh + +[Install] +WantedBy=default.target diff --git a/tmux.conf b/tmux.conf index 76ef522..4a14923 100644 --- a/tmux.conf +++ b/tmux.conf @@ -19,7 +19,7 @@ set -g history-limit 1000000 set -g display-time 4000 # Refresh 'status-left' and 'status-right' more often -set -g status-interval 5 +set -g status-interval 2 # Upgrade $TERM set -g default-terminal "tmux-256color"