Révision b0b39b01
Ruby plugins: apply style changes as suggested by "rubocop --fix-layout"
| plugins/mssql/microsoft-sql-buffer-cache-hit-ratio | ||
|---|---|---|
| 1 | 1 |
#!/usr/bin/env ruby |
| 2 |
# |
|
| 3 |
# Munin Plugin for MSSQL - Buffer cache hit ratio monitoring |
|
| 4 |
# |
|
| 5 |
# Author: Wilfred Chau <openapp.developer@gmail.com> |
|
| 6 |
# Date: 2011-05-19 |
|
| 7 |
# Version: 1.0 |
|
| 8 |
# |
|
| 9 |
# This program is free software; you can redistribute it and/or modify |
|
| 10 |
# it under the terms of the GNU General Public License version 2 |
|
| 11 |
# as published by the Free Software Foundation. |
|
| 12 |
# |
|
| 13 |
# This program is distributed in the hope that it will be useful, |
|
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 16 |
# GNU General Public License for more details. |
|
| 17 |
# |
|
| 18 |
# You should have received a copy of the GNU General Public License along |
|
| 19 |
# with this program; if not, write to the Free Software Foundation, Inc., |
|
| 20 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
| 21 |
# |
|
| 22 |
# |
|
| 23 |
# Prerequistes: |
|
| 24 |
# 1) /etc/odbc.ini and /etc/freetds.conf |
|
| 25 |
# 2) rubygems |
|
| 26 |
# 3) ruby-dbi |
|
| 27 |
# |
|
| 28 |
# Usage: |
|
| 29 |
# 1) copy this script to the munin install plugins directory (e.g. /usr/share/munin/plugins) |
|
| 30 |
# 2) chmod to allow executable to others |
|
| 31 |
# 3) create symbolic link in /etc/munin/plugins |
|
| 32 |
# ln -s /usr/share/munin/plugins/mssql_buffercachehitratio.rb /etc/munin/plugins/mssql_buffercachehitratio.rb |
|
| 33 |
# |
|
| 34 |
# Parameters: |
|
| 35 |
# autoconf |
|
| 36 |
# config (required) |
|
| 37 |
# |
|
| 38 |
# Config variables: |
|
| 39 |
# sqluser : mssql user who has view server state privilege |
|
| 40 |
# sqlpass : password for the mssql user |
|
| 41 |
# dsn : datasource name as defined in /etc/odbc.ini |
|
| 42 |
# |
|
| 2 |
|
|
| 3 |
=begin |
|
| 4 |
|
|
| 5 |
Munin Plugin for MSSQL - Buffer cache hit ratio monitoring |
|
| 6 |
|
|
| 7 |
Author: Wilfred Chau <openapp.developer@gmail.com> |
|
| 8 |
Date: 2011-05-19 |
|
| 9 |
Version: 1.0 |
|
| 10 |
|
|
| 11 |
This program is free software; you can redistribute it and/or modify |
|
| 12 |
it under the terms of the GNU General Public License version 2 |
|
| 13 |
as published by the Free Software Foundation. |
|
| 14 |
|
|
| 15 |
This program is distributed in the hope that it will be useful, |
|
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 18 |
GNU General Public License for more details. |
|
| 19 |
|
|
| 20 |
You should have received a copy of the GNU General Public License along |
|
| 21 |
with this program; if not, write to the Free Software Foundation, Inc., |
|
| 22 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
| 23 |
|
|
| 24 |
|
|
| 25 |
Prerequistes: |
|
| 26 |
1) /etc/odbc.ini and /etc/freetds.conf |
|
| 27 |
2) rubygems |
|
| 28 |
3) ruby-dbi |
|
| 29 |
|
|
| 30 |
Usage: |
|
| 31 |
1) copy this script to the munin install plugins directory (e.g. /usr/share/munin/plugins) |
|
| 32 |
2) chmod to allow executable to others |
|
| 33 |
3) create symbolic link in /etc/munin/plugins |
|
| 34 |
ln -s /usr/share/munin/plugins/mssql_buffercachehitratio.rb /etc/munin/plugins/mssql_buffercachehitratio.rb |
|
| 35 |
|
|
| 36 |
Parameters: |
|
| 37 |
autoconf |
|
| 38 |
config (required) |
|
| 39 |
|
|
| 40 |
Config variables: |
|
| 41 |
sqluser : mssql user who has view server state privilege |
|
| 42 |
sqlpass : password for the mssql user |
|
| 43 |
dsn : datasource name as defined in /etc/odbc.ini |
|
| 44 |
|
|
| 43 | 45 |
#%# family=auto |
| 44 | 46 |
#%# capabilities=autoconf |
| 45 | 47 |
|
| 48 |
=end |
|
| 49 |
|
|
| 50 |
|
|
| 46 | 51 |
require 'rubygems' |
| 47 | 52 |
require 'dbi' |
| 48 | 53 |
|
| ... | ... | |
| 54 | 59 |
# Queries |
| 55 | 60 |
# |
| 56 | 61 |
# |
| 57 |
dbh = DBI.connect("DBI:ODBC:#{dsn}",sqluser,sqlpass)
|
|
| 62 |
dbh = DBI.connect("DBI:ODBC:#{dsn}", sqluser, sqlpass)
|
|
| 58 | 63 |
|
| 59 | 64 |
buffercachehitratio_query = "select (a.cntr_value * 1.0 / b.cntr_value) * 100.0 |
| 60 | 65 |
from sys.dm_os_performance_counters a |
| ... | ... | |
| 70 | 75 |
# autoconf |
| 71 | 76 |
# |
| 72 | 77 |
if ARGV[0] == "autoconf" |
| 73 |
if all_instance_names.length > 1 && sqluser.length > 1 && sqlpass.length > 1
|
|
| 74 |
puts "yes"
|
|
| 75 |
else
|
|
| 76 |
puts "no"
|
|
| 77 |
puts "Usage: #{__FILE__} autoconf|conf"
|
|
| 78 |
end
|
|
| 79 |
exit 0
|
|
| 78 |
if all_instance_names.length > 1 && sqluser.length > 1 && sqlpass.length > 1
|
|
| 79 |
puts "yes"
|
|
| 80 |
else
|
|
| 81 |
puts "no"
|
|
| 82 |
puts "Usage: #{__FILE__} autoconf|conf"
|
|
| 83 |
end
|
|
| 84 |
exit 0
|
|
| 80 | 85 |
# |
| 81 | 86 |
# config definition |
| 82 | 87 |
# |
| 83 | 88 |
elsif ARGV[0] == "config" |
| 84 |
puts "graph_args --base 1000 -r --lower-limit 0"
|
|
| 85 |
puts "graph_title MSSQL Buffer Cache Hit Ratio "
|
|
| 86 |
puts "graph_category db"
|
|
| 87 |
puts "graph_info This graph shows Buffer Cache Hit Ratio"
|
|
| 88 |
puts "graph_vlabel %"
|
|
| 89 |
puts "graph_scale no"
|
|
| 90 |
puts "graph_period second"
|
|
| 91 |
|
|
| 92 |
puts "bc_hitratio.label BufferCacheHitRatio"
|
|
| 93 |
puts "bc_hitratio.info BufferCacheHitRatio"
|
|
| 94 |
puts "bc_hitratio.type GAUGE"
|
|
| 95 |
puts "bc_hitratio.draw LINE1"
|
|
| 96 |
|
|
| 97 |
exit 0
|
|
| 89 |
puts "graph_args --base 1000 -r --lower-limit 0"
|
|
| 90 |
puts "graph_title MSSQL Buffer Cache Hit Ratio "
|
|
| 91 |
puts "graph_category db"
|
|
| 92 |
puts "graph_info This graph shows Buffer Cache Hit Ratio"
|
|
| 93 |
puts "graph_vlabel %"
|
|
| 94 |
puts "graph_scale no"
|
|
| 95 |
puts "graph_period second"
|
|
| 96 |
|
|
| 97 |
puts "bc_hitratio.label BufferCacheHitRatio"
|
|
| 98 |
puts "bc_hitratio.info BufferCacheHitRatio"
|
|
| 99 |
puts "bc_hitratio.type GAUGE"
|
|
| 100 |
puts "bc_hitratio.draw LINE1"
|
|
| 101 |
|
|
| 102 |
exit 0
|
|
| 98 | 103 |
end |
| 99 | 104 |
|
| 100 | 105 |
sth = dbh.execute(buffercachehitratio_query) |
| 101 | 106 |
sth.fetch do |row| |
| 102 |
puts "bc_hitratio.value #{row[0].strip.to_s}"
|
|
| 107 |
puts "bc_hitratio.value #{row[0].strip.to_s}"
|
|
| 103 | 108 |
end |
| 104 | 109 |
sth.finish |
| 105 | 110 |
dbh.disconnect |
Formats disponibles : Unified diff