root / plugins / mssql / microsoft-sql-buffer-cache-hit-ratio @ b0b39b01
Historique | Voir | Annoter | Télécharger (3,05 ko)
| 1 | 7a37bfb1 | Lars Kruse | #!/usr/bin/env ruby |
|---|---|---|---|
| 2 | b0b39b01 | Lars Kruse | |
| 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 | |||
| 45 | fc514892 | Wilfred Chau | #%# family=auto |
| 46 | #%# capabilities=autoconf |
||
| 47 | |||
| 48 | b0b39b01 | Lars Kruse | =end |
| 49 | |||
| 50 | |||
| 51 | fc514892 | Wilfred Chau | require 'rubygems' |
| 52 | require 'dbi' |
||
| 53 | |||
| 54 | sqluser = 'rubyuser' |
||
| 55 | sqlpass = 'rubyuser' |
||
| 56 | dsn = 'TESTSQL' |
||
| 57 | |||
| 58 | # |
||
| 59 | # Queries |
||
| 60 | # |
||
| 61 | # |
||
| 62 | b0b39b01 | Lars Kruse | dbh = DBI.connect("DBI:ODBC:#{dsn}", sqluser, sqlpass)
|
| 63 | fc514892 | Wilfred Chau | |
| 64 | buffercachehitratio_query = "select (a.cntr_value * 1.0 / b.cntr_value) * 100.0 |
||
| 65 | from sys.dm_os_performance_counters a |
||
| 66 | join (select cntr_value, object_name |
||
| 67 | from sys.dm_os_performance_counters |
||
| 68 | where counter_name = 'Buffer cache hit ratio base' |
||
| 69 | and object_name = 'SQLServer:Buffer Manager') b |
||
| 70 | on a.object_name = b.object_name |
||
| 71 | where a.counter_name = 'Buffer cache hit ratio' |
||
| 72 | and a.object_name = 'SQLServer:Buffer Manager'" |
||
| 73 | |||
| 74 | # |
||
| 75 | # autoconf |
||
| 76 | # |
||
| 77 | if ARGV[0] == "autoconf" |
||
| 78 | b0b39b01 | Lars Kruse | 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 |
||
| 85 | fc514892 | Wilfred Chau | # |
| 86 | # config definition |
||
| 87 | # |
||
| 88 | elsif ARGV[0] == "config" |
||
| 89 | b0b39b01 | Lars Kruse | 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 |
||
| 103 | fc514892 | Wilfred Chau | end |
| 104 | |||
| 105 | sth = dbh.execute(buffercachehitratio_query) |
||
| 106 | sth.fetch do |row| |
||
| 107 | b0b39b01 | Lars Kruse | puts "bc_hitratio.value #{row[0].strip.to_s}"
|
| 108 | fc514892 | Wilfred Chau | end |
| 109 | sth.finish |
||
| 110 | dbh.disconnect |
