PageRenderTime 35ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/bin/plugins/tcp

https://github.com/ebonyeye/sonic-dns-munin
Shell | 96 lines | 71 code | 21 blank | 4 comment | 5 complexity | fd634b5604921331fdc502b7f5de9749 MD5 | raw file
  1. #!/bin/sh
  2. : <<EOF
  3. =head1 NAME
  4. tcp - Plugin to monitor IPV4/6 TCP socket status on a Linux host.
  5. =head1 AUTHOR
  6. Copyright 2009 Tim Small <tim@seoss.co.uk>
  7. =head1 LICENSE
  8. GPLv2
  9. =begin comment
  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 2 dated June, 1991.
  13. This program is distributed in the hope that it will be useful, but
  14. WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  20. USA.
  21. =end comment
  22. =head1 MAGIC MARKERS
  23. #%# family=manual
  24. #%# capabilities=autoconf
  25. =cut
  26. EOF
  27. case $1 in
  28. config)
  29. cat <<EOF
  30. graph_title TCP
  31. graph_vlabel TCP Sockets
  32. graph_category network
  33. graph_args -l 0
  34. graph_info TCP socket states for the local machine
  35. EOF
  36. for i in established syn_sent syn_recv fin_wait1 \
  37. fin_wait2 time_wait close close_wait last_ack \
  38. listen closing
  39. do
  40. echo ${i}.label $i
  41. echo ${i}.draw LINE2
  42. echo ${i}.info Sockets in state $i
  43. done
  44. exit 0
  45. ;;
  46. autoconf)
  47. if [ -f /proc/net/tcp -o -f /proc/net/tcp6 ]
  48. then
  49. echo yes
  50. exit 0
  51. else
  52. echo no
  53. exit 1
  54. fi
  55. esac
  56. # See #include <netinet/tcp.h>
  57. cat /proc/net/tcp* | awk '
  58. match ($4, /0[0-9A-B]/) {
  59. STATE[$4]++;
  60. }
  61. END {
  62. printf "established.value %d\n", STATE["01"];
  63. printf "syn_sent.value %d\n", STATE["02"];
  64. printf "syn_recv.value %d\n", STATE["03"];
  65. printf "fin_wait1.value %d\n", STATE["04"];
  66. printf "fin_wait2.value %d\n", STATE["05"];
  67. printf "time_wait.value %d\n", STATE["06"];
  68. printf "close.value %d\n", STATE["07"];
  69. printf "close_wait.value %d\n", STATE["08"];
  70. printf "last_ack.value %d\n", STATE["09"];
  71. printf "listen.value %d\n", STATE["0A"];
  72. printf "closing.value %d\n", STATE["0B"];
  73. }'