Monitoring SQL Server Agent Jobs With SCOM-2

Embed Size (px)

Citation preview

  • 8/17/2019 Monitoring SQL Server Agent Jobs With SCOM-2

    1/11

     

    Monitoring SQL Server Agent

    Jobs with SCOM

    Keeping Tabs on Maintenance Jobs

  • 8/17/2019 Monitoring SQL Server Agent Jobs With SCOM-2

    2/11

    IntroductionIn an environment where you work, there is a high degree of probably that you use Microsoft SQL

    Server of some version of edition to provide a database to an application. In the same environment,

    there’s a good chance, if you are a Microsoft shop that you are using System Center Operations

    Manager (SCOM) to monitor your environments.

    All good database administrators (DBAs) create jobs, plans and tasks to keep their SQL servers in tip

    top shape but a lot of the time, insight as to the status of these jobs is left either unturned like an

    age old stone or is done by configuring SQL Database Mail on your SQL servers so that email alerts

    are generated which means you have additional configuration being done on every server to

    configure this and it’s yet another thing to manage.

    In this guide, I am going to walk you through configuring a System Center Operations Manager 2012

    R2 environment to extend the monitoring of your SQL Servers to include the health state of your SQL

    Server Agent Jobs, allowing you to keep an eye on not just the SQL Server platform but also on the

     jobs that run to make the platform healthy.

    This guide as are all my publications, dedicated to my wife Nicky and my three daughters; Madison,

    Jessica and Layla who are subjected to living with me and technology and not always in that order.

    AuthorsRichard J Green works as a Consultant for Fordway Solutions Limited, dealing in all things Microsoft

    whilst specializing in delivering System Center solutions helping customers leverage their investment

    in IT through Microsoft management technologies. Richard works extensively with Windows Azure.

    He has an unhealthy obsession with the colour pink hence the colour choice of this book.

    You can follow Richard on Twitter @richardjgreen or read his blog at focusing on Microsoft products

    and technologies along with other digital ramblings at http://richardjgreen.net. 

    CopyrightThis book is copyright of Richard J Green and co-authors. No unauthorised copying of material in this

    book shall be performed without the prior written consent of Richard Green or one of the co-

    authors.

    © 2014

    http://www.fordway.com/http://www.fordway.com/http://www.fordway.com/http://twitter.com/richardjgreenhttp://twitter.com/richardjgreenhttp://twitter.com/richardjgreenhttp://richardjgreen.net/http://richardjgreen.net/http://richardjgreen.net/http://richardjgreen.net/http://twitter.com/richardjgreenhttp://www.fordway.com/http://www.fordway.com/

  • 8/17/2019 Monitoring SQL Server Agent Jobs With SCOM-2

    3/11

     

    ContentsIntroduction ............................................................................................................................................ 2

    Authors .................................................................................................................................................... 2

    Copyright ................................................................................................................................................. 2

    Prerequisites for Configuration............................................................................................................... 4

    SQL Server and SQL Server Agent ....................................................................................................... 4

    SQL Server Agent Jobs ......................................................................................................................... 4

    System Center Operations Manager................................................................................................... 4

    Configuring SQL Agent Job Monitoring ................................................................................................... 5

    Create a SQL Server Agent Targeting Group ....................................................................................... 5

    Enable the Agent Job Object Discovery .............................................................................................. 6

    Create a SQL Server Agent Job Targeting Group ................................................................................ 8

    Enable Alerting for Failed SQL Server Agent Jobs ............................................................................. 10

    Extra Credit Tasks .................................................................................................................................. 11

    Closing Credits ....................................................................................................................................... 11

  • 8/17/2019 Monitoring SQL Server Agent Jobs With SCOM-2

    4/11

    Monitoring SQL Server Agent Jobs with SCOM 

    4

    Prerequisites for ConfigurationIn order to be able to complete the steps in this guide, you need to have some things in place in your

    environment, nothing that you shouldn’t already have though mind you.

    SQL Server and SQL Server Agent

    It goes without saying that to monitor SQL Server Agent Jobs, the scope of this guide, you will need

    to have a SQL Server that has a running SQL Server Agent. This can be either a standalone SQL

    Server, a SQL Server Failover Cluster or a SQL Server AlwaysOn Availability Group.

    The SQL Server Agent should be configured with a service type of Automatic for Standalone and

    AlwaysOn Availability Group servers or to Manual and controlled by the Cluster Service for Failover

    Cluster instances of SQL Server.

    In this guide, I am working with SQL Server 2012 but there is no rule for this. You can deploy this

    configuration with any version or edition of SQL Server and adjust the steps in the guide accordingly.

    SQL Server Agent JobsAs the scope of this guide is configuring SQL Server Agent Jobs, it is fairly obvious that we need to

    have some jobs to monitor. The scope of this guide is not to tell you how to create SQL Server Agent

    Jobs or what jobs you should have but I have a blog post exploring the Ola Hallengren SQL

    Maintenance Solution at http://richardjgreen.net/sql-server-maintenance-solution/ if you want

    more information.

    System Center Operations Manager

    In this guide, I am working with System Center Operations Manager 2012 R2 which is the latest

    release, ignoring the System Center vNext Technical Preview recently made available.

    There is no limitation for this to only work with SCOM 2012 R2 and it would be entirely possible todo this with older versions of SCOM. The only limiting factor with SCOM is Management Packs. In

    order to be able to follow this guide, you need to have the SQL Server Management Packs for the

    appropriate versions of SQL Server installed.

    The System Center Management Pack for SQL Server supporting SQL Server 2005, 2008, 2008 R2 and

    2012 can be downloaded from http://www.microsoft.com/en-gb/download/details.aspx?id=10631. 

    The System Center Management Pack for SQL Server 2014 can be downloaded from

    http://www.microsoft.com/en-us/download/details.aspx?id=42573. 

    http://richardjgreen.net/sql-server-maintenance-solution/http://richardjgreen.net/sql-server-maintenance-solution/http://richardjgreen.net/sql-server-maintenance-solution/http://www.microsoft.com/en-gb/download/details.aspx?id=10631http://www.microsoft.com/en-gb/download/details.aspx?id=10631http://www.microsoft.com/en-gb/download/details.aspx?id=10631http://www.microsoft.com/en-us/download/details.aspx?id=42573http://www.microsoft.com/en-us/download/details.aspx?id=42573http://www.microsoft.com/en-us/download/details.aspx?id=42573http://www.microsoft.com/en-gb/download/details.aspx?id=10631http://richardjgreen.net/sql-server-maintenance-solution/

  • 8/17/2019 Monitoring SQL Server Agent Jobs With SCOM-2

    5/11

    Configuring SQL Agent Job Monitoring

    Configuring SQL Agent Job MonitoringWith all of our prerequisite talk out of the way, we can now get to the real topic, how to configure

    this monitoring.

    By default, the SQL Server Management Pack for SCOM monitors SQL Server health but with respect

    to the SQL Server Agent, it only monitors the health of the Agent service and not what runs inside

    that agent.

    Create a SQL Server Agent Targeting Group

    To get started, you need to make a choice: do you want to monitor the SQL Server Agent for a

    selection of your servers or for all of them?

    I made the choice that I want to only target a sub-set of servers for this monitoring so the first step is

    to create a group for these servers. In SCOM, we create a group from the Groups node of the

    Authoring pane in the Operations Console.

    As you will see from the screenshot of the group creation, the object that needs to be added is the

    SQLAgent$SERVER object, where SERVER is the SQL Server server name.

    If you wanted to include all SQL Servers in your environment, you could create the appropriate

    Dynamic Members statement or you could ignore this step and apply the following step to All

    Objects of a Class instead of to the Group.

  • 8/17/2019 Monitoring SQL Server Agent Jobs With SCOM-2

    6/11

    Monitoring SQL Server Agent Jobs with SCOM 

    6

    Enable the Agent Job Object Discovery

    With our group created, we now need to turn our attention to actually discovering the Agent Jobs

    and that is as the name suggests, done by an Object Discovery.

    In the Operations Console, on the Authoring pane, open the Object Discoveries node and change

    the scope of the Management Packs to be limited to SQL Server 2012 Agent Job. You will need tochange the radio button at the bottom of the scope dialog to View All Targets whilst doing this as

    the Agent is not defined as a common Management Pack.

    You should then see the Object Discovery Discover SQL Server 2012 Agent Jobs job which is disabledby default hence why we don’t get the statuses for our SQL Server Agent Jobs out of the box.

    Right-click this Object Discovery and select Overrides > Override the Object Discovery > For a Group 

    and from the group picker, select the group we created previously in the SQL Server and SQL Server

    Agent step.

  • 8/17/2019 Monitoring SQL Server Agent Jobs With SCOM-2

    7/11

    Configuring SQL Agent Job Monitoring

    In the Override Properties as you can see from the screenshot above, we want to override the

    status of this Object Discovery from Disabled to Enabled. Select the Override checkbox for the

    Parameter Name Enabled and set the Override Value to True. Once you have done this, select OK to

    apply the change.

    The next part depends on your level of patience. If you are happy to wait, then leave everythingalong and come back the following day as that is how long it will take the Microsoft Monitoring

    Agent on the SQL Server hosts to pick up the change to the Object Discovery and run it because of

    the Interval on the discovery.

    If like me, you don’t want to wait for that, simply restart the Microsoft Monitoring Agent service on

    your SQL Servers and the changes will be pulled in immediately and the Object Discovery forced to

    run at the agent restart.

    We can check that our SQL Server Agent Jobs have been discovered by SCOM using the Monitoring

    view. Click the Monitoring pane in the Operations Console and drill down to Microsoft SQL Server >

    SQL Server Database Engines > SQL Server 2005/2008/2012 > SQL Agent and open the SQL Agent

    Job State state view.

    As you can see from this screenshot, the two servers that I included in the group have performed the

    discovery of the SQL Server Agent Jobs and their status has been reported into SCOM as Healthy.

    In the screenshot, there are three jobs per server, dbcc_checkdb_weekly  and

    defragment_indexes_weekly  which are user created SQL Server Agent Jobs and

    syspolicy_purge_history which is a system job.

    Because syspolicy_purge_history is a system job that’s only purpose is to clear down the history of

    SQL Server Agent Jobs history I am not actually interested in monitoring this. Furthermore, we

    probably don’t want to monitor SQL Server Agent Jobs which individual administrators have chosen

    to create to aid their work; we only want to monitor the company mandated jobs used for

    maintaining our servers.

  • 8/17/2019 Monitoring SQL Server Agent Jobs With SCOM-2

    8/11

    Monitoring SQL Server Agent Jobs with SCOM 

    8

    Create a SQL Server Agent Job Targeting Group

    So far, we are collecting the status of the Jobs from the SQL Server Agents into SCOM. The status for

    these jobs is based on the Last Run Status monitor however right now, we are only seeing the status

    and there will not be any alerting.

    To get the alerting that we desire, we need to prepare another group to allow us to scope the usercreated jobs and to then allow those jobs to generate alerts.

    As shown in the screenshot above, I have started the process of creating a group however this time,

    the group is based on Dynamic Membership. By using Dynamic Membership, we can define here in

    the group the Job Names that we want to monitor and based on the membership of our first group,

    these will automatically be targeted and will be automatically applied to all our SQL Servers.

    In this Dynamic Group, I have chosen to include Or expression groups for each of the SQL Server

    Agent Job versions so that should somebody later add a SQL Server to our Agent Job monitoring

    group that is running a different version of SQL Server that it will still work. This is covered briefly in

    the Extra Credit Tasks task at the end of this guide but not a requirement.

    Once we have created our new group, we can use the View Group Members menu option in the

    Groups node of the Authoring pane in the Operations Console to check that we have correctly

    targeted our Classes and that everything has been detected properly.

  • 8/17/2019 Monitoring SQL Server Agent Jobs With SCOM-2

    9/11

    Configuring SQL Agent Job Monitoring

    As you can see from the image above, the user created SQL Server Agent Jobs that we designated to

    be part of this Dynamic Group have been correctly detected confirming both that our Class Targeting

    has been set correctly and that our expression to match the Job Name is working also.

  • 8/17/2019 Monitoring SQL Server Agent Jobs With SCOM-2

    10/11

    Monitoring SQL Server Agent Jobs with SCOM 

    10

    Enable Alerting for Failed SQL Server Agent Jobs

    So far, we’ve achieved a lot by targeting our SQL Servers and getting monitoring insight into the

    status of our SQL Server Agent Jobs but to get the full story, we now want to generate alerts for any

    failures and because we are kind SCOM Administrators, we want our alerts to automatically resolve

    which means we are using a Monitor for the SCOM educated amongst you.

    On the Authoring pane of the Operations Console, select the Monitor node. In the Monitor node,

    scope the Management Packs to SQL Server 2012 Agent Jobs which may already be the case from

    our previous scoping efforts.

    Right-click the Last Run Status Monitor and select Overrides > Override the Monitor > For a Group 

    and select the group that we created in the last step Create a SQL Server Agent Job Targeting Group. 

    At the Override Properties dialog as shown above in the screenshot, override the Auto-Resolve Alert

    and Generate Alert Parameter Names and change both of their Override Values to True.

    Once you’ve made these changes, select OK to apply the override.

    You now have a solution in place to bring visibly to the status of your SQL Server Agent Jobs into

    SCOM and you have alert generation for failures.

  • 8/17/2019 Monitoring SQL Server Agent Jobs With SCOM-2

    11/11

    Extra Credit Tasks

    11 

    Extra Credit TasksNow that you are finished, here are some extra credit tasks you can consider to make this even

    better:

      Repeat the steps in this guide for other versions of SQL Server such as SQL Server 2014 to

    future-proof your efforts if someone in your environment decides to be cutting-edge and

    deploys a SQL Server 2014 instance.

      Configure a Notification Channel and Subscriber for the SQL Server Agent Jobs alerts and

    have the alerts sent to your monitoring team or your SQL DBA team, whichever is relevant in

    your environment.

      Use Dynamic Membership on the first group we created in the Create a SQL Server Agent

    Targeting Group step so automatically include all of your SQL Servers but just make that you

    are happy that the health state of all of your SQL Servers is in a good place before you do

    otherwise the people receiving your alerts might be a bit unhappy with you.

    Closing CreditsI hope you’ve enjoyed this guide and found it helpful and please feel free to reach out to me via my

    blog at http://richardjgreen.net or via Twitter at @richardjgreen if you want more information about

    this guide or have any suggestions for how it could be made even better.

    http://richardjgreen.net/http://richardjgreen.net/http://richardjgreen.net/http://twitter.com/richardjgreenhttp://twitter.com/richardjgreenhttp://twitter.com/richardjgreenhttp://twitter.com/richardjgreenhttp://richardjgreen.net/