Commit a549d6e532b8224267803d4c7f73a9616f0b7e84

Authored by Georg Hopp
1 parent eb7fdf20

some more stuff to make this slightly more useful on a freebsd

... ... @@ -3,6 +3,7 @@ gather_cpu_info() {
3 3
4 4 has_class "GNU" && {
5 5 export NCPUS=$(${NPROC})
  6 + set_class ${NCPUS}cpus
6 7 }
7 8
8 9 has_class "Linux" && {
... ... @@ -18,9 +19,14 @@ gather_cpu_info() {
18 19 }
19 20 /CPU(s):/ { print "export NCPUS=" $2 ";" }
20 21 /Virtualization/ { print "export CPU_VIRT=\"" $2 "\";" }')
  22 +
  23 + set_class ${NCPUS}cpus ${CPU_VIRT} ${BYTE_ORDER} ${OP_MODES}
21 24 }
22 25
23   - set_class ${NCPUS}cpus ${CPU_VIRT} ${BYTE_ORDER} ${OP_MODES}
  26 + has_class "FreeBSD" && {
  27 + export NCPUS=$(${SYSCTL} kern.smp.cpus | cut -d\ -f2)
  28 + set_class ${NCPUS}cpus
  29 + }
24 30 }
25 31
26 32 # vim: set ts=4 sw=4:
... ...
... ... @@ -6,28 +6,37 @@ gather_uptime_info() {
6 6 export LOAD_5=""
7 7 export LOAD_15=""
8 8
9   - has_class "Linux" && {
10   - eval $(${AWK} -v ncpus=${NCPUS} '{
11   - print "LOAD_1=\"" $1 "\";LOAD_5=\"" $2 "\";LOAD_15=\"" $3 "\";";
12   - for(i=1; i<4; i++) {
13   - if($i<=0.0) {
14   - load="LOW"
  9 + local CALC_LOAD_AWK='{
  10 + print "LOAD_1=\"" $1 "\";LOAD_5=\"" $2 "\";LOAD_15=\"" $3 "\";";
  11 + for(i=1; i<4; i++) {
  12 + if($i<=0.0) {
  13 + load="LOW"
  14 + } else {
  15 + inv_load=ncpus/$i;
  16 + if (inv_load > (ncpus/2)) {
  17 + load="LOW";
15 18 } else {
16   - inv_load=ncpus/$i;
17   - if (inv_load > (ncpus/2)) {
18   - load="LOW";
19   - } else {
20   - load="MODERATE";
21   - }
22   - if (inv_load <= 0) load="HIGH";
  19 + load="MODERATE";
23 20 }
24   -
25   - if(i==1) { classes=classes "LOAD_1_" load " " }
26   - if(i==2) { classes=classes "LOAD_5_" load " " }
27   - if(i==3) { classes=classes "LOAD_15_" load " "; }
  21 + if (inv_load <= 0) load="HIGH";
28 22 }
29   - print "set_class " classes ";";
30   - }' </proc/loadavg)
  23 +
  24 + if(i==1) { classes=classes "LOAD_1_" load " " }
  25 + if(i==2) { classes=classes "LOAD_5_" load " " }
  26 + if(i==3) { classes=classes "LOAD_15_" load " "; }
  27 + }
  28 + print "set_class " classes ";";
  29 + }'
  30 +
  31 + has_class "Linux" && {
  32 + eval $(${AWK} -v ncpus=${NCPUS} "${CALC_LOAD_AWK}" </proc/loadavg)
  33 + }
  34 +
  35 + has_class "FreeBSD" && {
  36 + local N='\([0-9]*\.[0-9]*\)'
  37 + eval $(${SYSCTL} vm.loadavg |\
  38 + ${SED} 's/^.*{ '"${N}"' '"${N}"' '"${N}"'.*/\1 \2 \3/' |\
  39 + ${AWK} -v ncpus=${NCPUS} "${CALC_LOAD_AWK}")
31 40 }
32 41
33 42 export UPTIME LOAD_1 LOAD_5 LOAD_15
... ...
Please register or login to post a comment