perl scripts for SQL monitoring

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
User avatar
FallingDown
Posts: 6
Joined: Wed Mar 12, 2008 9:36 am
Location: Austin, Texas

perl scripts for SQL monitoring

Post by FallingDown »

I am new to scripting and in need of some assistance. I am using some scripts that I found here from kwabbernoot and zbose, and they work great:

Code: Select all

#!/usr/bin/perl

$response = `/bin/check_nt -H $ARGV[0] -p 1248 -v CPULOAD -l 10,80,95`;
chomp $response;
($load) = ($response =~ /min. (\d+)\%\)/);

print "$load\n";

#!/usr/bin/perl

$active_sessions= `/usr/lib/nagios/plugins/check_nt -H $ARGV[0] -p 1248  -v COUNTER -l "\\Terminal Services\\Active Sessions"`;
chomp $active_sessions;

$inactive_sessions= `/usr/lib/nagios/plugins/check_nt -H $ARGV[0] -p 1248  -v COUNTER -l "\\Terminal Services\\Inactive Sessions"`;
chomp $inactive_sessions;

print "active:$active_sessions inactive:$inactive_sessions\n";
[/color]

The problem is I can not get the SQL examples to work. I get NANs or sometimes I actually get Zeros. If I run from command line I get the proper return, but never from the perl script. Obviously it is in the Perl script. Any help would be great.
A little information:
Cacti version: 0.8.7a on CentOS
SQL Sever: 2003svr 64bit running SQL2000 32bit. (I think this is the problem - 32 bit counters on 64 bit system)
NSClient installed on servers.


Examples:

Code: Select all

#!/usr/bin/perl

$sql_trans_sec = `/usr/lib/nagios/plugins/check_nt -H $ARVG[0] -p 1248 -v COUNTER -l "\\SQLServer:Databases(_Total)\Transactions/sec"`;
chomp $sql_trans_sec;

print "sql_trans_sec:$sql_trans_sec\n";

#!/usr/bin/perl

$sql_fscans = `/usr/lib/nagios/plugins/check_nt -H $ ARVG[0] -p 1248 -v COUNTER -l "\\SQLServer:Buffer Manager\Buffer cache hit ratio"`;
chomp $sql_fscans;

print "sql_fscans:$sql_fscans\n";
[/color]
And many more for SQL.
Is the problem in the Perl script or is it something to do with the 32 bit version of SQL on the 64 bit OS? When I run from command line:

Code: Select all

scripts]# /usr/lib/nagios/plugins/check_nt -H 10.0.20.7 -p 1248 -v COUNTER -l "\\SQLServer:Buffer Manager\Buffer cache hit ratio"
[/color]
I get 100, which is correct. When I run any of the SQL check_nt scripts from command line I get the correct response.
Additionally, when I run any of the .pl for SQL from command line

Code: Select all

scripts]# /usr/bin/perl check_nt_bchr.pl 
[/color]
I get Zero. As in 0. Not a NAN. I have about 6 other .pl that I have made from information I obtained here and they work great. It is just the SQL. If you need any more info, let me know.
User avatar
FallingDown
Posts: 6
Joined: Wed Mar 12, 2008 9:36 am
Location: Austin, Texas

Post by FallingDown »

Footnote:
I will be glad to post all templates and working scripts once this is resolved.
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Post by BSOD2600 »

1) wrong forum, moving.

2) change cacti's logging level to debug and then look in the log file when your scripts run. Any errors?

3) cmd or spine poller?
User avatar
FallingDown
Posts: 6
Joined: Wed Mar 12, 2008 9:36 am
Location: Austin, Texas

Post by FallingDown »

cmd.php
As for the logs:
CMDPHP: Poller[0] Host[20] DS[387] CMD: perl /usr/share/cacti/scripts/check_nt_sql_transec.pl ausdev1, output: U
could not parse argument.

When run from the command line, some of the sql.pl will return "could not parse argument". Sorry forgot to mention that. That is why I think my script has an error in it.
/perl noob
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Post by BSOD2600 »

FallingDown wrote:When run from the command line, some of the sql.pl will return "could not parse argument". Sorry forgot to mention that. That is why I think my script has an error in it.
/perl noob
Ah, yes that would most likely be your underlaying problem.

Also the correct format for mutli-value output for scripts needs to be: name1:value1 name2:value2, etc. This is documented in the documentation site guides.
User avatar
FallingDown
Posts: 6
Joined: Wed Mar 12, 2008 9:36 am
Location: Austin, Texas

Post by FallingDown »

I realize that the fact that it can not parse the argument is the problem. What part of the argument is causing the failure?
If this works from the command line,

Code: Select all

scripts]# /usr/lib/nagios/plugins/check_nt -H 10.0.20.7 -p 1248 -v COUNTER -l "\\SQLServer:Databases(_Total)\Transactions/sec"
[/color]
then why doesn't:

Code: Select all

#!/usr/bin/perl

$sql_trans_sec = `/usr/lib/nagios/plugins/check_nt -H $ARVG[0] -p 1248 -v COUNTER -l "\\SQLServer:Databases(_Total)\Transactions/sec"`;
$chomp $sql_trans_sec;

print "$sql_trans_sec\n";
[/color]
work from perl? I have tried substituting the host variable with the actual IP in the perl script, and that did not work either. I have built another SQL server that is 2003 32 bit with 32 bit SQL 2000 and I get the same results. All the scripts I have that pull data from WMI counters work with the exception of SQL. Could it be the "-v COUNTER" part of the argument? I could not find anything in the documentation for a SQL specific argument for this.
User avatar
FallingDown
Posts: 6
Joined: Wed Mar 12, 2008 9:36 am
Location: Austin, Texas

Post by FallingDown »

:x Holy Crap :D
I figured it out. It was a problem in the Perl script. Not the most readable language to learn in the last 2 days. It would appear that "/" are not read like I would have thought. Anyway here it is.
Non-functioning Perl script

Code: Select all

#!/usr/bin/perl

$sql_trans_sec = `/usr/lib/nagios/plugins/check_nt -H $ARGV[0] -p 1248 -v COUNTER -l "\\SQLServer:Databases(_Total)\Transactions/sec"`;
chomp $sql_trans_sec;


print "$sql_trans_sec\n";
[/color]
In the variable .....(_Total)\Trans..... there is only one \ and there needs to be 2. Something about single quoted and double quoted string literals. Fixed code is:

Code: Select all

#!/usr/bin/perl

$sql_trans_sec = `/usr/lib/nagios/plugins/check_nt -H $ARGV[0] -p 1248 -v COUNTER -l "\\SQLServer:Databases(_Total)\\Transactions/sec"`;
chomp $sql_trans_sec;


print "$sql_trans_sec\n";
[/color]

I will post more later. I have to drive to Houston.
Kristiaan
Posts: 1
Joined: Tue Feb 22, 2011 9:27 am

Re: perl scripts for SQL monitoring

Post by Kristiaan »

According to this page, something like the following command should give me a correct output;

./check_nt -H 10.0.13.81 -v COUNTER -l “\\MSSQL$SQLEXPRESS:Databases(_Total)\\Data File(s) Size (KB)”

Unfortunately, the output is 0. According to my performance monitor, the output should be at least above 250000.

When I want to monitor the ‘% Processor Time’ for example, it gives me a correct output.
./check_nt -H 10.0.13.81 -v COUNTER -l “\\Processor(_Total)\\% Processor Time”
Output = 3

I’ve noticed I can correctly check anything, except for the MSSQL-checks. Same problems occur, when connected to our Enterprise Vault server, when trying to check our EV-objects.

What am I doing wrong here, or do you blame MSSQL and EV?

I hope hearing from you very fast.

Many thanks in advance!


Kristiaan Wouters from Belgium.
User avatar
FallingDown
Posts: 6
Joined: Wed Mar 12, 2008 9:36 am
Location: Austin, Texas

Re: perl scripts for SQL monitoring

Post by FallingDown »

Kristiaan wrote:According to this page, something like the following command should give me a correct output;

./check_nt -H 10.0.13.81 -v COUNTER -l “\\MSSQL$SQLEXPRESS:Databases(_Total)\\Data File(s) Size (KB)”
What am I doing wrong here, or do you blame MSSQL and EV?
Kristiaan Wouters from Belgium.
kristiaan,
You need to escape the $ in the SQL instance section of the counter definition.
Try...

Code: Select all

./check_nt -H 10.0.13.81 -v COUNTER -l “\\MSSQL\$SQLEXPRESS:Databases(_Total)\\Data File(s) Size (KB)”
That should work.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests