From 9b6d154afb2b32f81dae99cc45392b4cace2a29d Mon Sep 17 00:00:00 2001 From: NeodarZ Date: Sun, 18 Sep 2016 02:11:28 +0200 Subject: Add more conf --- .i3-blocks/blocks/cpu | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 .i3-blocks/blocks/cpu (limited to '.i3-blocks/blocks/cpu') diff --git a/.i3-blocks/blocks/cpu b/.i3-blocks/blocks/cpu new file mode 100755 index 0000000..2cb27ad --- /dev/null +++ b/.i3-blocks/blocks/cpu @@ -0,0 +1,48 @@ +#!/bin/bash +# Source: http://askubuntu.com/a/450136 + +URGENT_VALUE=90 + +PREV_TOTAL=0 +PREV_IDLE=0 + +cpuFile="/tmp/.cpu" + +if [[ -f "${cpuFile}" ]]; then + fileCont=$(cat "${cpuFile}") + PREV_TOTAL=$(echo "${fileCont}" | head -n 1) + PREV_IDLE=$(echo "${fileCont}" | tail -n 1) +fi + +CPU=(`cat /proc/stat | grep '^cpu '`) # Get the total CPU statistics. +unset CPU[0] # Discard the "cpu" prefix. +IDLE=${CPU[4]} # Get the idle CPU time. + +# Calculate the total CPU time. +TOTAL=0 + +for VALUE in "${CPU[@]:0:4}"; do + let "TOTAL=$TOTAL+$VALUE" +done + +if [[ "${PREV_TOTAL}" != "" ]] && [[ "${PREV_IDLE}" != "" ]]; then + # Calculate the CPU usage since we last checked. + let "DIFF_IDLE=$IDLE-$PREV_IDLE" + let "DIFF_TOTAL=$TOTAL-$PREV_TOTAL" + let "DIFF_USAGE=(1000*($DIFF_TOTAL-$DIFF_IDLE)/$DIFF_TOTAL+5)/10" + echo "${DIFF_USAGE}%" + echo "${DIFF_USAGE}%" + echo "" +else + echo "?" + echo "?" + echo "" +fi + +# Remember the total and idle CPU times for the next check. +echo "${TOTAL}" > "${cpuFile}" +echo "${IDLE}" >> "${cpuFile}" + +if [[ "${DIFF_USAGE}" -gt 0 ]] && [[ "${DIFF_USAGE}" -gt "${URGENT_VALUE}" ]]; then + exit 33 +fi \ No newline at end of file -- cgit v1.2.1