swap 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/sh -e
  2. #
  3. # mem_swap: show the current swap available and used
  4. #
  5. # Copyright (C) 2010 Canonical Ltd.
  6. # Copyright (C) 2011-2014 Dustin Kirkland
  7. #
  8. # Authors: Dustin Kirkland <kirkland@byobu.org>
  9. #
  10. # This program is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation, version 3 of the License.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. __swap_detail() {
  22. cat /proc/meminfo
  23. }
  24. __swap() {
  25. local stotal="" sfree="" name="" val="" unit="" mem="" f="";
  26. while read name val unit; do
  27. if [ "$name" = "SwapTotal:" ]; then
  28. stotal="$val"
  29. elif [ "$name" = "SwapFree:" ]; then
  30. sfree="$val"
  31. else
  32. continue
  33. fi
  34. [ -n "$stotal" -a -n "$sfree" ] && break;
  35. done < /proc/meminfo
  36. if [ "${stotal:-0}" = "0" ]; then
  37. printf ""
  38. rm -f "$BYOBU_RUN_DIR/status.$BYOBU_BACKEND/swap"
  39. else
  40. mem=${stotal}
  41. f=$(((100*($stotal-$sfree))/$stotal))
  42. if [ $mem -ge 1048576 ]; then
  43. fpdiv "${mem}" 1048576 1
  44. mem=${_RET}
  45. unit="$ICON_GB"
  46. elif [ $mem -ge 1024 ]; then
  47. fpdiv "${mem}" 1024 0
  48. mem=${_RET}
  49. unit="$ICON_MB"
  50. else
  51. mem="$mem"
  52. unit="$ICON_KB"
  53. fi
  54. [ -n "$mem" ] || return
  55. color b G k; printf "s%s" "$mem"; color -; color G k; printf "%s" "$unit"; color -;
  56. color b G k; printf "%s" "$f"; color -; color G k; printf "%s" "$PCT"; color --
  57. fi
  58. }
  59. # vi: syntax=sh ts=4 noexpandtab