root / plugins / mssql / microsoft-sql-buffer-cache-hit-ratio @ 17f78427
Historique | Voir | Annoter | Télécharger (3,06 ko)
| 1 | 7a37bfb1 | Lars Kruse | #!/usr/bin/env ruby |
|---|---|---|---|
| 2 | fc514892 | Wilfred Chau | # |
| 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 | fba800ae | Veres Lajos | # sqluser : mssql user who has view server state privilege |
| 40 | fc514892 | Wilfred Chau | # sqlpass : password for the mssql user |
| 41 | # dsn : datasource name as defined in /etc/odbc.ini |
||
| 42 | # |
||
| 43 | #%# family=auto |
||
| 44 | #%# capabilities=autoconf |
||
| 45 | |||
| 46 | require 'rubygems' |
||
| 47 | require 'dbi' |
||
| 48 | |||
| 49 | sqluser = 'rubyuser' |
||
| 50 | sqlpass = 'rubyuser' |
||
| 51 | dsn = 'TESTSQL' |
||
| 52 | |||
| 53 | # |
||
| 54 | # Queries |
||
| 55 | # |
||
| 56 | # |
||
| 57 | dbh = DBI.connect("DBI:ODBC:#{dsn}",sqluser,sqlpass)
|
||
| 58 | |||
| 59 | buffercachehitratio_query = "select (a.cntr_value * 1.0 / b.cntr_value) * 100.0 |
||
| 60 | from sys.dm_os_performance_counters a |
||
| 61 | join (select cntr_value, object_name |
||
| 62 | from sys.dm_os_performance_counters |
||
| 63 | where counter_name = 'Buffer cache hit ratio base' |
||
| 64 | and object_name = 'SQLServer:Buffer Manager') b |
||
| 65 | on a.object_name = b.object_name |
||
| 66 | where a.counter_name = 'Buffer cache hit ratio' |
||
| 67 | and a.object_name = 'SQLServer:Buffer Manager'" |
||
| 68 | |||
| 69 | # |
||
| 70 | # autoconf |
||
| 71 | # |
||
| 72 | 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 |
||
| 80 | # |
||
| 81 | # config definition |
||
| 82 | # |
||
| 83 | elsif ARGV[0] == "config" |
||
| 84 | 17f78427 | Lars Kruse | puts "graph_args --base 1000 -r --lower-limit 0" |
| 85 | fc514892 | Wilfred Chau | puts "graph_title MSSQL Buffer Cache Hit Ratio " |
| 86 | fa99ece8 | dipohl | puts "graph_category db" |
| 87 | fc514892 | Wilfred Chau | 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 |
||
| 98 | end |
||
| 99 | |||
| 100 | sth = dbh.execute(buffercachehitratio_query) |
||
| 101 | sth.fetch do |row| |
||
| 102 | puts "bc_hitratio.value #{row[0].strip.to_s}"
|
||
| 103 | end |
||
| 104 | sth.finish |
||
| 105 | dbh.disconnect |
