BSDG33KCLUB

freebsd sysctl stuff

Feb 24th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. Even if You mount /proc on FreeBSD, it does contain only the pseudo directories with stats/information for pids. It does not contain all the Linuxisms like /proc/cpuinfo or /proc/swap or whatever.
  2.  
  3. If You take a Linux script and put it on FreeBSD it mostly ends up not working.
  4.  
  5. On FreeBSD I used a script that would gather that data without /proc, for example from sysctl.
  6.  
  7.  
  8. % cat ~/scripts/xmobar.sh
  9. #! /bin/sh
  10.  
  11. date +"<fc=#AAAAAA>date:</fc> <fc=#EEEEEE>%Y/%m/%d/%A/%H:%M</fc>" | tr '[A-Z]' '[a-z]'
  12.  
  13. echo -n " <fc=#dd0000>|</fc> <fc=#aaaaaa>cpu:</fc> <fc=#eeeeee>"
  14.  
  15. top -b 10 | awk 'NR>8 { gsub(/%/,"",$0); CPU+=$11; } END { split(CPU,cpu,"."); print cpu[1]; }'
  16.  
  17. echo -n "%/"
  18.  
  19. sysctl -n dev.cpu.0.freq
  20.  
  21. echo -n "MHz/"
  22.  
  23. sysctl -n dev.cpu.0.temperature | awk -F '.' '{print $1}'
  24.  
  25. echo -n "C</fc> <fc=#dd0000>|</fc> <fc=#aaaaaa>load:</fc> <fc=#eeeeee>"
  26.  
  27. sysctl -n vm.loadavg | awk '{ print substr($2,0,3) "/" substr($3,0,3) "/" substr($4,0,3) }'
  28.  
  29. BOOT=$( sysctl -n kern.boottime | awk 'match($0, / sec = [0-9]+/) { $0 = substr($0, RSTART, RLENGTH); print $3 }' )
  30. DATE=$( date +%s )
  31. echo -n " <fc=#dd0000>|</fc> <fc=#aaaaaa>uptime:</fc> <fc=#eeeeee>$( date -r $(( ${DATE} - ${BOOT} - 3600 )) +"%k:%M" | tr -d ' ' )</fc>"
  32.  
  33. echo -n "</fc> <fc=#dd0000>|</fc> <fc=#aaaaaa>ps:</fc> <fc=#eeeeee>"
  34.  
  35. sysctl -n vm.vmtotal | awk 'match($0, /Processes/) { gsub(/\)/,"",$11); print $3 "/" $6 "/" $9 "/" $11 }'
  36.  
  37. echo -n "</fc> <fc=#dd0000>|</fc> <fc=#aaaaaa>mem:</fc> <fc=#eeeeee>"
  38.  
  39. MEM_PAGE=$( sysctl -n hw.pagesize )
  40. MEM_SIZE=$(( $( sysctl -n vm.stats.vm.v_page_count ) * ${MEM_PAGE} / 1024 / 1024 ))
  41. MEM_INCT=$(( $( sysctl -n vm.stats.vm.v_inactive_count ) * ${MEM_PAGE} / 1024 / 1024 ))
  42. MEM_FREE=$(( $( sysctl -n vm.stats.vm.v_free_count ) * ${MEM_PAGE} / 1024 / 1024 ))
  43. MEM_USED=$(( ${MEM_SIZE} - ${MEM_FREE} - ${MEM_INCT} ))
  44.  
  45. echo -n "$(( 100 * ${MEM_USED} / ${MEM_SIZE} ))%/$(( ${MEM_USED} ))M"
  46.  
  47. echo -n "</fc> <fc=#dd0000>|</fc> <fc=#aaaaaa>ip:</fc> <fc=#eeeeee>$( if_ip.sh )</fc>"
  48.  
  49. echo -n "<fc=#dd0000>|</fc> <fc=#aaaaaa>vol/pcm:</fc> <fc=#eeeeee>$( __conky_mixer_vol.sh )/$( __conky_mixer_pcm.sh )</fc> "
  50.  
  51. echo -n "<fc=#dd0000>|</fc> <fc=#aaaaaa>fs:</fc> <fc=#eeeeee>"
  52.  
  53. zpool list storage | awk 'END{print $5 "/" $4}'
  54.  
  55. echo -n "</fc> <fc=#dd0000>|</fc> <fc=#aaaaaa>bat:</fc> <fc=#eeeeee>$( battery.sh )</fc>"
Add Comment
Please, Sign In to add comment