Sending email on perfmon alert

  • 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.

  • Hi

    Try this. It worked for me everytime.

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

    Thank You,

    Best regards,

    SQLBuddy

  • 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

  • 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.

  • 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!

  • Thanks Hawkeye DBA. Maybe one day I will find the time to learn enough WMI script to use this method! 🙂

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply