Guest User

Untitled

a guest
Sep 15th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. #!/bin/sh
  2. # -*- sh -*-
  3.  
  4. : << =cut
  5.  
  6. =head1 NAME
  7.  
  8. intra_mysql_metrics - Munin Plugin to monitor the number of records on a
  9. mysql-server
  10.  
  11.  
  12. =head1 CONFIGURATION
  13.  
  14. The following environment variables are used by this plugin:
  15.  
  16. mysqlopts - Options to pass to mysql
  17.  
  18. =head1 AUTHOR
  19.  
  20. Unknown author
  21.  
  22. =head1 LICENSE
  23.  
  24. Unknown license
  25.  
  26. =head1 MAGIC MARKERS
  27.  
  28. #%# family=manual
  29. #%# capabilities=autoconf
  30.  
  31. =cut
  32.  
  33. #MYSQLOPTS="$mysqlopts"
  34. MYSQLOPTS="-u xxxdbuser -h xxxx-db-instance.qwertyuiopas.ap-northeast-1.rds.amazonaws.com --password=xxxdbuserpass"
  35. MYSQLADMIN=${mysqladmin:-mysqladmin}
  36.  
  37. if [ "$1" = "autoconf" ]; then
  38. $MYSQLADMIN --version 2>/dev/null >/dev/null
  39. if [ $? -eq 0 ]
  40. then
  41. $MYSQLADMIN $MYSQLOPTS status 2>/dev/null >/dev/null
  42. if [ $? -eq 0 ]
  43. then
  44. echo yes
  45. exit 0
  46. else
  47. echo "no (could not connect to mysql)"
  48. fi
  49. else
  50. echo "no (mysqladmin not found)"
  51. fi
  52. exit 0
  53. fi
  54.  
  55. if [ "$1" = "config" ]; then
  56. echo 'graph_title MySQL metrics'
  57. # echo 'graph_args --base 1000 -l 0'
  58. echo 'graph_args -l 0'
  59. echo 'graph_vlabel count(*)'
  60. echo 'graph_category intra_mysql'
  61. echo 'graph_info Note that this is a old plugin which is no longer installed by default. It is retained for compatability with old installations.'
  62.  
  63. echo 'users.label users'
  64. #echo 'users.type DERIVE'
  65. #echo 'users.type COUNTER'
  66. echo 'users.min 0'
  67. echo 'users.max 500000'
  68.  
  69. echo 'posts.label posts'
  70. #echo 'posts.type DERIVE'
  71. #echo 'posts.type COUNTER'
  72. echo 'posts.min 0'
  73. echo 'posts.max 500000'
  74.  
  75. echo 'groups.label groups'
  76. #echo 'groups.type DERIVE'
  77. #echo 'groups.type COUNTER'
  78. echo 'groups.min 0'
  79. echo 'groups.max 500000'
  80.  
  81. echo 'pages.label pages'
  82. #echo 'pages.type DERIVE'
  83. #echo 'pages.type COUNTER'
  84. echo 'pages.min 0'
  85. echo 'pages.max 500000'
  86.  
  87. echo 'login.label login users in 5 mins.'
  88. #echo 'login.type DERIVE'
  89. #echo 'login.type COUNTER'
  90. echo 'longin.min 0'
  91. echo 'login.max 500000'
  92.  
  93. exit 0
  94.  
  95. fi
  96.  
  97. #/usr/bin/printf "usres.value "
  98. #/usr/bin/mysql -B -e "select count(*) from users;" $MYSQLOPTS xxxdb 2>/dev/null | tail -n +2 | awk '{print $1}'
  99.  
  100.  
  101. #/usr/bin/printf "queries.value "
  102. #($MYSQLADMIN $MYSQLOPTS status 2>/dev/null || echo a a a a a a a a U) | awk '{print $9}'
  103.  
  104.  
  105. /usr/bin/printf "users.value "
  106. mysql -B -e "select count(*) from users;" $MYSQLOPTS xxxdb 2>/dev/null | tail -n +2 | awk '{print $1}'
  107.  
  108. /usr/bin/printf "posts.value "
  109. mysql -B -e "select count(*) from posts;" $MYSQLOPTS xxxdb 2>/dev/null | tail -n +2 | awk '{print $1}'
  110.  
  111. /usr/bin/printf "groups.value "
  112. mysql -B -e "select count(*) from groups;" $MYSQLOPTS xxxdb 2>/dev/null | tail -n +2 | awk '{print $1}'
  113.  
  114. /usr/bin/printf "pages.value "
  115. mysql -B -e "select count(*) from pages;" $MYSQLOPTS xxxdb 2>/dev/null | tail -n +2 | awk '{print $1}'
  116.  
  117.  
  118. /usr/bin/printf "login.value "
  119. mysql -B -e "select count(*) from users where current_sign_in_at > date_sub(now(), interval 5 minute);" $MYSQLOPTS xxxdb 2>/dev/null | tail -n +2 | awk '{print $1}'
Add Comment
Please, Sign In to add comment