commit 17502d56ac76f424ee57d02c02b96fe2fb35e52a Author: digital-freak Date: Thu May 7 23:42:35 2015 +0500 Initial GitHub commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..db1354d --- /dev/null +++ b/README.md @@ -0,0 +1,42 @@ +conky-hw-monitor +================ + + +Conky configs and scripts for FreeBSD desktop that monitors the CPU & RAM +usage and CPU temperature. Also monitors of all connected storages (i.e. +HDD, SSD drives and USB-dongles) with all mounted filesistems. For HDD +drives shows the current temperature (in Celsius). + +Requirements +------------ + +* `sysutils/smartmontools` - for HDD +* `coretemp.ko / amdtemp.ko` - for the on-die digital thermal sensor +* `devel/lua-sysctl` - for reading dev.cpu.X.temperature sysctl's + +Usage +----- + +First of all, install the `sysutils/smartmontools` and `devel/lua-sysctl`. +For `devel/lua-sysctl` remove the patch from the port, because this patch +for using with Lua 5.2 and Conky won't work correctly. + +Load the corresponding kernel module for your CPU: + +`kldload coretemp` - for Intel Core CPU's +`kldload amdtemp` - for AMD CPU's + +Add it to the loader.conf file: + + echo "coretemp_load=YES" >> /boot/loader.conf + +or + + echo "amdtemp_load=YES" >> /boot/loader.conf + +Get the project files to your computer: + + git clone https://github.com/digital-freak/conky-hw-monitor.git + +And run the `hwmon.sh` sctipt + diff --git a/conky-hw-monitor.png b/conky-hw-monitor.png new file mode 100644 index 0000000..b89de86 Binary files /dev/null and b/conky-hw-monitor.png differ diff --git a/drivedb.h b/drivedb.h new file mode 100644 index 0000000..1e33b39 --- /dev/null +++ b/drivedb.h @@ -0,0 +1,12 @@ +/* + * drivedb.h - smartmontools drive database file + * + */ + + { "USB: Samsung M2 Portable; ", + "0x04e8:0x60b3", + "", + "", + "-d usbjmicron" + }, + diff --git a/hdd.rc b/hdd.rc new file mode 100644 index 0000000..70bcd86 --- /dev/null +++ b/hdd.rc @@ -0,0 +1,47 @@ +background no + +cpu_avg_samples 2 +net_avg_samples 2 +diskio_avg_samples 2 +double_buffer yes +no_buffers yes +text_buffer_size 4096 +total_run_times 0 +update_interval 1.0 + +alignment tr +gap_x 212 +gap_y 10 +border_inner_margin 0 +border_outer_margin 0 +border_width 0 + +maximum_width 172 +minimum_size 172 12 + +own_window yes +own_window_class conky_hdd_monitor +own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager +own_window_argb_visual yes +own_window_transparent yes +own_window_type normal + +default_color E1E7CD +default_outline_color 281C06 +default_shade_color 281C06 +default_bar_size 172 4 + +draw_borders no +draw_graph_borders yes +draw_outline no +draw_shades no + +override_utf8_locale yes +use_xft yes +xftalpha 0.8 +xftfont DejaVu Sans:size=8 + +short_units yes +TEXT +${execpi 4 ./hdd.sh} + diff --git a/hdd.sh b/hdd.sh new file mode 100755 index 0000000..6f6f42e --- /dev/null +++ b/hdd.sh @@ -0,0 +1,69 @@ +#!/bin/sh + +SMARTCMD="smartctl -B +./drivedb.h" + +get_attached_devices() { +# DEVS="`sysctl kern.disks | awk '{$1=""; ;print $0}' | awk 'gsub(" ", "\n")' | grep -v ^$ | sed '/^cd[0-9]/d' | sort`" + DEVS="`sysctl -n kern.disks | tr ' ' '\n' | sed '/^cd[0-9]*/d' | sort`" + echo ${DEVS} +} + +get_device_model() { + DEVICE_MODEL="`${SMARTCMD} -i /dev/${1} | grep "Device Model" | awk -F\: '{print $2}' | sed 's/^[ \t]*//'`" + echo ${DEVICE_MODEL} +} + +get_device_capacity() { + DEVICE_CAPACITY="`${SMARTCMD} -i /dev/${1} | grep "User Capacity" | awk -F\[ '{print $2}' | sed 's/]//'`" + echo ${DEVICE_CAPACITY} +} + +get_device_temperature() { + DEVICE_TEMP="`${SMARTCMD} -A -f brief /dev/${1} | grep "Temperature_Celsius" | awk '{print $8}'`" + echo ${DEVICE_TEMP} +} + +get_device_partitions() { + PARTITIONS="`mount | grep /dev/${1} | grep -v none | awk '{print $1}' | sed 's/\/dev\///' | sort`" + echo "${PARTITIONS}" +} + +get_mount_point() { + MOUNT_POINT="`mount | grep /dev/${1} | awk '{print $3}'`" + echo ${MOUNT_POINT} +} + +for DEV in `get_attached_devices`; do + MODEL="`get_device_model ${DEV}`" + TEMP="`get_device_temperature ${DEV}`" + CAPACITY="`get_device_capacity ${DEV}`" + + if [ "${TEMP}" != "" ]; then + TEMP="[ ${TEMP} ℃ ]" + fi + +#BEB9A5 + printf "\${color 2A403D}\${font Poky:size=16}y\${font}\${color} \${color B53C27}\${hr}\${color}\n" + printf "\${voffset -20}\${alignr}${MODEL} \n\n" + printf "\${voffset -7} ${DEV} (${CAPACITY})\${alignr}${TEMP} \n" + printf "\${voffset -4}\${color B53C27}\${stippled_hr}\${color}\n" + + for PARTITION in `get_device_partitions ${DEV}`; do + MP="`get_mount_point ${PARTITION}`" + + if [ "${MP}" != "" ]; then + printf "\${goto 30}${MP}\${alignr}${PARTITION} \n" + printf "\${voffset -3}\${goto 30}\${fs_bar 3,140 ${MP}}\n" + printf "\${voffset -3}\${goto 30}\${alignr}\${fs_free ${MP}} / \${fs_size ${MP}} \n" + printf "\${voffset -4}\${goto 30}\${color 7F8484}\${stippled_hr}\${color}\n" + fi + done +done +#printf "\n" + +# ${font Poky:size=16}y${font} ${color B53C27}${stippled_hr}${color} +# ${voffset -18}${alignr}WDC WD2500AAKS-00F0A0 +# +# ${voffset -4}ada2 (250 GB)${alignr}[ 41 ℃ ] +# ${voffset -4}${color B53C27}${hr}${color} + diff --git a/hwmon.sh b/hwmon.sh new file mode 100755 index 0000000..7866058 --- /dev/null +++ b/hwmon.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +############################################################################## +# Get the real directory, where is located executable file +case `uname` in +"FreeBSD" ) + if [ $( readlink ${0} ) ]; then + RUNDIR=$( realpath $( dirname $( readlink ${0} ) ) ) + else + RUNDIR=$( realpath $( dirname ${0} ) ) + fi +;; +"Linux" ) + RUNDIR=$( dirname $( readlink -f ${0} ) ) +;; +esac +############################################################################## + +INTERVAL=${1:-20} + +cd ${RUNDIR} + +sleep ${INTERVAL} + +./system.sh +conky -c hdd.rc & +exit 0 diff --git a/system.lua b/system.lua new file mode 100644 index 0000000..533a6bd --- /dev/null +++ b/system.lua @@ -0,0 +1,8 @@ +require ('sysctl') + +function conky_cpu_temperature(core) + temperature = sysctl.IK2celsius(sysctl.get('dev.cpu.' .. core .. '.temperature')) .. ' ℃' + + return (temperature) +end + diff --git a/system.rc b/system.rc new file mode 100644 index 0000000..eed8b0e --- /dev/null +++ b/system.rc @@ -0,0 +1,65 @@ +background no + +cpu_avg_samples 2 +net_avg_samples 2 +diskio_avg_samples 2 +double_buffer yes +no_buffers yes +text_buffer_size 2048 +total_run_times 0 +update_interval 1.0 + +alignment tr +gap_x 20 +gap_y 10 +border_inner_margin 0 +border_outer_margin 0 +border_width 0 + +maximum_width 172 +minimum_size 172 12 + +own_window yes +own_window_class conky_system_monitor +own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager +own_window_argb_visual yes +own_window_transparent yes +own_window_type normal + +default_color E1E7CD +default_outline_color 281C06 +default_shade_color 281C06 +default_bar_size 172 4 + +draw_borders no +draw_graph_borders yes +draw_outline no +draw_shades no + +override_utf8_locale yes +use_xft yes +xftalpha 0.8 +xftfont DejaVu Sans:size=8 + +short_units yes + +lua_load system.lua + +TEXT +${color 2A403D}${font Poky:size=16}P${font} ${color B53C27}${hr}${color} +${voffset -20}${alignr}${offset -3}Intel Core i3 CPU 550 +${voffset 5}${alignr}${offset -3}3.20GHz +${voffset -3}${alignr}${offset -120}${font Open Sans Condensed Light:size=14}${cpu cpu0}%${font} +${voffset -22}${alignr}${offset -3}${cpugraph cpu0 16,110} +${goto 30}${lua cpu_temperature 0}${alignr}${offset -3}${lua cpu_temperature 1} +${voffset -4}${goto 30}${cpubar cpu1 3,60}${alignr}${offset -3}${cpubar cpu2 3,60} +${goto 30}${lua cpu_temperature 2}${alignr}${offset -3}${lua cpu_temperature 3} +${voffset -4}${goto 30}${cpubar cpu3 3,60}${alignr}${offset -3}${cpubar cpu4 3,60} +${voffset -4}${goto 30}${color 7F8484}${stippled_hr}${color} +${color 2A403D}${font Poky:size=16}M${font} ${color B53C27}${hr}${color} +${voffset -20}${alignr}${offset -3}⛂ ${mem} │ ⛀ ${memfree} +${voffset 5}${alignr}${offset -3}⛃ ${memmax} +${goto 30}RAM:${alignr}${offset -15}${memperc}%${offset -172}${alignr}${offset -3}${membar 3,60} + +${goto 30}SWAP:${alignr}${offset -15}${swapperc}%${offset -172}${alignr}${offset -3}${swapbar 3,60} +${voffset -4}${goto 30}${color 7F8484}${stippled_hr}${color} diff --git a/system.sh b/system.sh new file mode 100755 index 0000000..dc74ff7 --- /dev/null +++ b/system.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +CPU_NAME="`sysctl -n hw.model | \ + sed 's/(R)//;s/(TM)//' | \ + sed -E 's/[[:space:]]+/ /g' | \ + awk -F\@ '{print $1}' | \ + sed -E 's/[[:space:]]+$//'`" +CPU_SPEED="`sysctl -n hw.model | \ + sed 's/(R)//;s/(TM)//' | \ + sed -E 's/[[:space:]]+/ /g' | \ + awk -F\@ '{print $2}' | \ + sed -E 's/^[[:space:]]+//'`" +CPU_CORES="`sysctl -n hw.ncpu`" + +CPU_LOAD="" + +if [ ${CPU_CORES} -eq 1 ]; then + CPU_LOAD='${goto 30}[cpu_temp]\ +${voffset -2}${goto 30}${cpubar cpu0 3,140}' +else + N=0 + while [ ${N} != ${CPU_CORES} ]; do + POS=$((${N} % 2)) + + if [ ${POS} -eq 0 ]; then + CORE_TEMP='${goto 30}${lua cpu_temperature '${N}'}' + CORE_LOAD='${voffset -4}${goto 30}${cpubar cpu'$((N+1))' 3,60}' + else + CORE_TEMP=${CORE_TEMP}'${alignr}${offset -3}${lua cpu_temperature '${N}'}' + CORE_LOAD=${CORE_LOAD}'${alignr}${offset -3}${cpubar cpu'$((N+1))' 3,60}' + if [ ${N} -gt 1 ]; then + CPU_LOAD=${CPU_LOAD}'\ +'${CORE_TEMP}'\ +'${CORE_LOAD} + else + CPU_LOAD=${CORE_TEMP}'\ +'${CORE_LOAD} + fi + CORE_TEMP="" + CORE_LOAD="" + fi + + N=$((N + 1)) + done +fi + +rm -f system.rc + +cat templates/system.tmpl | \ + sed -E "s/\[cpu_name\]/${CPU_NAME}/; + s/\[cpu_speed\]/${CPU_SPEED}/; + s/\[cpu_load\]/${CPU_LOAD}/" >> ./system.rc + +conky -c system.rc & +exit 0 diff --git a/templates/system.tmpl b/templates/system.tmpl new file mode 100644 index 0000000..9ea9db0 --- /dev/null +++ b/templates/system.tmpl @@ -0,0 +1,62 @@ +background no + +cpu_avg_samples 2 +net_avg_samples 2 +diskio_avg_samples 2 +double_buffer yes +no_buffers yes +text_buffer_size 2048 +total_run_times 0 +update_interval 1.0 + +alignment tr +gap_x 20 +gap_y 10 +border_inner_margin 0 +border_outer_margin 0 +border_width 0 + +maximum_width 172 +minimum_size 172 12 + +own_window yes +own_window_class conky_system_monitor +own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager +own_window_argb_visual yes +own_window_transparent yes +own_window_type normal + +default_color E1E7CD +default_outline_color 281C06 +default_shade_color 281C06 +default_bar_size 172 4 + +draw_borders no +draw_graph_borders yes +draw_outline no +draw_shades no + +override_utf8_locale yes +use_xft yes +xftalpha 0.8 +xftfont DejaVu Sans:size=8 + +short_units yes + +lua_load system.lua + +TEXT +${color 2A403D}${font Poky:size=16}P${font} ${color B53C27}${hr}${color} +${voffset -20}${alignr}${offset -3}[cpu_name] +${voffset 5}${alignr}${offset -3}[cpu_speed] +${voffset -3}${alignr}${offset -120}${font Open Sans Condensed Light:size=14}${cpu cpu0}%${font} +${voffset -22}${alignr}${offset -3}${cpugraph cpu0 16,110} +[cpu_load] +${voffset -4}${goto 30}${color 7F8484}${stippled_hr}${color} +${color 2A403D}${font Poky:size=16}M${font} ${color B53C27}${hr}${color} +${voffset -20}${alignr}${offset -3}⛂ ${mem} │ ⛀ ${memfree} +${voffset 5}${alignr}${offset -3}⛃ ${memmax} +${goto 30}RAM:${alignr}${offset -15}${memperc}%${offset -172}${alignr}${offset -3}${membar 3,60} + +${goto 30}SWAP:${alignr}${offset -15}${swapperc}%${offset -172}${alignr}${offset -3}${swapbar 3,60} +${voffset -4}${goto 30}${color 7F8484}${stippled_hr}${color}