Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / mssql / microsoft-sql @ 17f78427

Historique | Voir | Annoter | Télécharger (3,22 ko)

1 7a37bfb1 Lars Kruse
#!/usr/bin/env ruby
2 c0dc3b1b Wilfred Chau
#
3
# Munin Plugin for MSSQL - transaction monitoring
4
#
5
# Author: Wilfred Chau <openapp.developer@gmail.com>
6
# Date: 2011-05-18
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_transaction.rb /etc/munin/plugins/mssql_transaction.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 c0dc3b1b Wilfred Chau
#	sqlpass : password for the mssql user
41
#	dsn     : datasource name as defined in /etc/odbc.ini
42
#	instance: instance to monitor
43
#
44
#%# family=auto
45
#%# capabilities=autoconf
46
47
require 'rubygems'
48
require 'dbi'
49
50
sqluser  = 'rubyuser'
51
sqlpass  = 'rubyuser'
52
dsn      = 'TESTSQL'
53
instance = 'AdventureWorks'
54
55
#
56
# Queries
57
#
58
#
59
dbh = DBI.connect("DBI:ODBC:#{dsn}",sqluser,sqlpass)
60
61 17f78427 Lars Kruse
instance_name_query = "SELECT distinct instance_name
62
                       FROM sys.dm_os_performance_counters
63 c0dc3b1b Wilfred Chau
                       WHERE instance_name = '#{instance}'
64
		       and object_name = 'SQLServer:Databases'
65
                       order by instance_name"
66
67
transaction_query = "select cntr_value from sys.dm_os_performance_counters
68
                     where counter_name = 'transactions/sec'
69
                     and object_name = 'SQLServer:Databases'
70
                     and instance_name = ?"
71
72
all_instance_names  = Array.new
73
sth = dbh.execute(instance_name_query)
74
sth.fetch do |row|
75
	all_instance_names.push(row[0].strip)
76
end
77
sth.finish
78
79
#
80
# autoconf
81
#
82
if ARGV[0] == "autoconf"
83
	if all_instance_names.length > 1 && sqluser.length > 1 && sqlpass.length > 1
84
		puts "yes"
85
	else
86
		puts "no"
87
		puts "Usage: #{__FILE__} autoconf|conf"
88
	end
89
	exit 0
90
#
91
# config definition
92
#
93
elsif ARGV[0] == "config"
94 17f78427 Lars Kruse
	puts "graph_args --base 1000 -r --lower-limit 0"
95 c0dc3b1b Wilfred Chau
	puts "graph_title MSSQL Transactions/s"
96 fa99ece8 dipohl
	puts "graph_category db"
97 c0dc3b1b Wilfred Chau
	puts "graph_info This graph shows transactions/s"
98
	puts "graph_vlabel transactions/s"
99
	puts "graph_scale no"
100
	puts "graph_period second"
101
102
	all_instance_names.sort.each do |s|
103
		puts "#{s}.label #{s}"
104
		puts "#{s}.info INSTANCE: #{s}"
105
		puts "#{s}.type DERIVE"
106
		puts "#{s}.draw LINE1"
107
	end
108
109
	exit 0
110
end
111
112
#
113
# Getting data
114
#
115
sth = dbh.prepare(transaction_query)
116
all_instance_names.sort.each do |k|
117
	sth.execute(k)
118
	sth.fetch do |row|
119
		# since type is DERIVE, need to convert value to integer then to string
120
		puts "#{k.to_s}.value #{row[0].to_i.to_s}"
121
	end
122
end
123
sth.finish
124
dbh.disconnect