Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Sending email on perfmon alert Expand / Collapse
Author
Message
Posted Friday, July 16, 2010 4:03 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, December 3, 2010 8:15 AM
Points: 9, Visits: 57
Hi,

I would like to use perfmon counter alerts to trigger an email to let developement DBAs know when their machine is running out of memory.

I got an idea from this article: http://www.db-staff.com/index.php/microsoft-sql-server/89-sql-server-monitoring-tool

I have set up an alert and created a small batch file that generates an email:

set mailbody=%1
set mailbody=%mailbody:~1,-1%
sqlcmd -S MyMachine -E -Q "declare @subject sysname; set @subject = 'Performance alert on ' + @@SERVERNAME; EXEC msdb.dbo.sp_send_dbmail @recipients='MyEmail',@subject = @subject , @body = '%mailbody%', @body_format = 'TEXT' ;"

This sends an email using sqlcmd to run a SQL stored procedure. It works when I run it.
When Perfmon tries to run the batch file I see the following error in the event log:

Unable to execute command '' for the MyFirstAlert alert. The alert will continue as scheduled. The error code returned is in the data.

I think I must be doing something wrong with the command line arguments (How exactly do I pass them into the batch file?) or perhaps a permissions issue (I've allowed read and excute to everyone on the .bat. Also allowed cmd.exe to [BATCH].

Thanks in advance.

Ben.
Post #953727
Posted Friday, July 16, 2010 1:25 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 2:06 PM
Points: 1,194, Visits: 2,210
Hi

Try this. It worked for me everytime.

http://www.sqlservercentral.com/articles/Administration/smtpsqlserverperformancealerts/2005/

Thank You,

Best regards,
SQLBuddy
Post #954141
Posted Friday, July 16, 2010 1:45 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, June 9, 2014 2:33 PM
Points: 219, Visits: 457
Depending on the version of SQL Server you could have your DBAs configure an Alert on their server to send them an email. You have to have a mail profile set up on the database server first, then you can go to the SQL Server Agent tree in SQL Management Studio > Alert and create a new alert.

Use the Alert type of SQL Performance Condition or WMI event alert and specify the counter info.

Here's a link to show you how this is done for SQL Server 2008, it is very similiar in 2005: http://msdn.microsoft.com/en-us/library/ms187827.aspx

Great job getting alerts on performance no matter how you do it that's very proactive!

Cheers -

Hawkeye DBA
Post #954151
Posted Monday, July 19, 2010 7:02 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, December 3, 2010 8:15 AM
Points: 9, Visits: 57
Thanks SQLBuddy,

It's a very similar method. I can get the script to run fine. But when I ask Perfmon to run it I get the same error!

Unable to execute command '' for the MyFirstAlert alert. The alert will continue as scheduled. The error code returned is in the data.

Do you change any permissions when you set this up?

Thanks,
Ben.
Post #954787
Posted Monday, July 19, 2010 8:05 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, December 3, 2010 8:15 AM
Points: 9, Visits: 57
bendhill (7/19/2010)
Thanks SQLBuddy,

It's a very similar method. I can get the script to run fine. But when I ask Perfmon to run it I get the same error!

Unable to execute command '' for the MyFirstAlert alert. The alert will continue as scheduled. The error code returned is in the data.

Do you change any permissions when you set this up?

Thanks,
Ben.


Doh. Just had to change the "Run as" property on the general tab!
Post #954826
Posted Monday, July 19, 2010 8:38 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, December 3, 2010 8:15 AM
Points: 9, Visits: 57
Thanks Hawkeye DBA. Maybe one day I will find the time to learn enough WMI script to use this method! :)
Post #954854
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse