Projet

Général

Profil

Révision d89e5781

IDd89e57818e74ce56eb001629103ca37171230e17
Parent fc514892
Enfant 3a70dd84

Ajouté par Wilfred Chau il y a presque 14 ans

Initial version

Voir les différences:

plugins/other/microsoft-sql-log-file-size
1
#! /usr/bin/ruby
2
#
3
# Munin Plugin for MSSQL - log files 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_logfilesizes.rb /etc/munin/plugins/mssql_logfilesizes.rb
33
#
34
# Parameters:
35
#	autoconf
36
#	config (required)
37
#
38
# Config variables:
39
#	sqluser : mssql user who has view server state priviledge
40
#	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
instance_name_query = "SELECT distinct instance_name 
62
                       FROM sys.dm_os_performance_counters
63
		       WHERE instance_name = '#{instance}'"
64

  
65
logfilesize_query = "SELECT cntr_value/1024.0 from sys.dm_os_performance_counters
66
                     WHERE counter_name = 'Log File(s) Size (KB)'
67
                     AND object_name = 'SQLServer:Databases'
68
                     AND instance_name = ?"
69

  
70
all_instance_names  = Array.new
71
sth = dbh.execute(instance_name_query)
72
sth.fetch do |row|
73
	all_instance_names.push(row[0].strip)
74
end
75
sth.finish
76

  
77
#
78
# autoconf
79
#
80
if ARGV[0] == "autoconf"
81
	if all_instance_names.length > 1 && sqluser.length > 1 && sqlpass.length > 1
82
		puts "yes"
83
	else
84
		puts "no"
85
		puts "Usage: #{__FILE__} autoconf|conf"
86
	end
87
	exit 0
88
#
89
# config definition
90
#
91
elsif ARGV[0] == "config"
92
	puts "graph_args --base 1024k -r --lower-limit 0"	
93
	puts "graph_title MSSQL DB Log File Sizes"
94
	puts "graph_category MSSQL"
95
	puts "graph_info This graph shows DB Log File Sizes (MB)"
96
	puts "graph_vlabel MB"
97
	puts "graph_scale no"
98
	puts "graph_period second"
99

  
100
	all_instance_names.sort.each do |s|
101
		puts "#{s}.label #{s}"
102
		puts "#{s}.info INSTANCE: #{s}"
103
		puts "#{s}.type GAUGE"
104
		puts "#{s}.draw LINE1"
105
	end
106

  
107
	exit 0
108
end
109

  
110
sth = dbh.prepare(logfilesize_query)
111
all_instance_names.sort.each do |k|
112
	sth.execute(k)
113
	sth.fetch do |row|
114
		puts "#{k.to_s}.value #{row[0].to_s}"
115
	end
116
end
117
sth.finish
118
dbh.disconnect

Formats disponibles : Unified diff