On a Linux box - If you would like to see a metric with percentage memory and swap used, it's as simple as adding another 4 lines to the vm.sh file in /opt/circonus/etc/node-agent.d/linux
Below is the default vm.sh file with the following additions:
- let MEM_PERC=100*$MEM_USED/$MEM_TOTAL
- let SWAP_PERC=100*${SWAP[2]}/${SWAP[1]}
and then 2 print statements:
- print_vm memory perc $MEM_PERC
- print_vm swap perc $SWAP_PERC
- #!/bin/bash
- print_vm() {
- printf "%s`%s\tL\t%s\n" $1 $2 $3
- }
- MEM=($(free -b | grep ^Mem:))
- MEM_TOTAL=${MEM[1]}
- # For consistency across platforms, count cache as free, not used
- let MEM_USED=${MEM[1]}-${MEM[3]}-${MEM[5]}-${MEM[6]}
- let MEM_FREE=${MEM[3]}+${MEM[5]}+${MEM[6]}
- let MEM_PERC=100*$MEM_USED/$MEM_TOTAL
- SWAP=($(free -b | grep ^Swap:))
- SWAP_TOTAL=${SWAP[1]}
- SWAP_USED=${SWAP[2]}
- SWAP_FREE=${SWAP[3]}
- let SWAP_PERC=100*${SWAP[2]}/${SWAP[1]}
- # pgfault is min+maj
- PG_FAULTS=$(grep ^pgfault /proc/vmstat | awk '{ print $2 }')
- PG_MAJFAULTS=$(grep ^pgmajfault /proc/vmstat | awk '{ print $2 }')
- let PG_MINFAULTS=$PG_FAULTS-$PG_MAJFAULTS
- print_vm memory total $MEM_TOTAL
- print_vm memory used $MEM_USED
- print_vm memory free $MEM_FREE
- print_vm memory perc $MEM_PERC
- print_vm swap total $SWAP_TOTAL
- print_vm swap used $SWAP_USED
- print_vm swap free $SWAP_FREE
- print_vm swap perc $SWAP_PERC
- print_vm info page_fault $PG_FAULTS
- print_vm info page_fault`minor $PG_MINFAULTS
- print_vm info page_fault`major $PG_MAJFAULTS
Just remember to restart nad (sudo /etc/init.d/nad restart), then go to the existing check and enable the 2 new metrics!
You can also change the 100 to 10,000 above, turning the resulting %age into a 4 digit number, then apply =VAL/100 to the metric in the graph to get XX.XX% for more precision.