Udostępnij za pośrednictwem


Defining Queries for Monitoring Objects

Applies To: Operations Manager 2007 R2, Operations Manager 2007 SP1, System Center Operations Manager 2007

A MonitoringObject represents an instance of a MonitoringClass defined in a Management Pack. You can query the Operations Manager database to obtain the existing monitoring objects in a Management Group.

Like other Operations Manager objects, you can define a criteria expression to narrow the search results when obtaining a collection of monitoring objects. For more information, see Operations Manager Data Queries Overview.

When you define a criteria expression for monitoring objects, do the following:

  • Qualify the property names of the monitoring objects.

  • Whenever it is possible, use partial monitoring objects to improve database performance.

These tasks are described in the following sections.

Qualifying Monitoring Object Property Names

All monitoring objects share a common set of standard properties. (This set includes the Name and DisplayName properties.) Also, each monitoring object has any custom properties that are defined for the object's MonitoringClass (in the Management Pack that defines the class) and any custom properties that are inherited by the class (from its base class).

Because each monitoring class inherits the properties of its base class, it is possible for a monitoring class to inherit a property that has the same name as another property that is defined for the monitoring class. When you define a criteria expression that references a property whose name is not unique, you must qualify the property name with the name of the class for which it is defined, as follows:

[className].[propertyName]

or

[managementPackName!className].[propertyName]

Note

You can improve the performance of the database query by qualifying property names, so you should qualify all monitoring object property names whenever it is possible.

For example, the following segment from a Management Pack defines a custom class that represents a component of an application (in this case, a file saved on the computer that hosts the application).

<ClassType ID="Microsoft.Demo.Scripting.AppYComponent" Abstract="false" Accessibility="Public" Hosted="true" Base="Windows!Microsoft.Windows.ApplicationComponent">
    <Property ID="ID" Type="string" Key="true"/>
    <Property ID="FileName" Type="string"/>
</ClassType>

The class defines two custom properties, ID and FileName. Assuming that an instance of this class has been discovered with the file name "YLog.txt", you could define a criteria expression to get the monitoring object that uses an unqualified property name as follows:

String qStr = "FileName = 'YLog.txt'";
MonitoringObjectCriteria yComponentCriteria = new MonitoringObjectCriteria(qStr, AppYComponentClass);

ReadOnlyCollection<MonitoringObject> appYComponents = mg.GetMonitoringObjects(yComponentCriteria);
if (appYComponents.Count != 1)
{
    throw new InvalidOperationException("Expected one component with: " + qStr);
}

To qualify the property name, change the query string in the previous example to include the monitoring class name in brackets, as follows:

qStr = "[Microsoft.Demo.Scripting.AppYComponent].[FileName] = 'YLog.txt'";

The new query string qualifies the FileName property by providing the name of the class to which the property belongs. Assuming that the Management Pack that contains the class was named Microsoft.Demo.Scripting, you could further qualify the property name by including the Management Pack name as follows:

qStr = "[Microsoft.Demo.Scripting!Microsoft.Demo.Scripting.AppYComponent].[FileName] = 'YLog.txt'";

Qualifying a class name by using a Management Pack name is required when the same class name is defined in more than one Management Pack.

Using Partial Monitoring Objects

You can dramatically improve the performance of monitoring object queries by using partial monitoring objects whenever it is possible. A partial monitoring object is an object for which only the standard set of monitoring object properties is defined (any custom properties of the object's class are omitted). Because the Operations Manager database omits custom property values when responding to the query, using partial monitoring objects decreases the load on the database and improves query performance.

For example, the following segment from a Management Pack defines a custom class that represents a component of an application. (This is the same example class that is used in the previous section.)

<ClassType ID="Microsoft.Demo.Scripting.AppYComponent" Abstract="false" Accessibility="Public" Hosted="true" Base="Windows!Microsoft.Windows.ApplicationComponent">
    <Property ID="ID" Type="string" Key="true"/>
    <Property ID="FileName" Type="string"/>
</ClassType>

The class defines two custom properties, ID and FileName. Assuming that an instance of this class has been discovered with the name "YLog" (which is stored in the monitoring object's standard Name property), you can define a MonitoringObjectGenericCriteria object to get the partial monitoring object for the class instance as follows:

qStr = "Name = 'Ylog'";
MonitoringObjectGenericCriteria yGenCompCriteria = new MonitoringObjectGenericCriteria(qStr);

ReadOnlyCollection<PartialMonitoringObject> appYCompPartial = mg.GetPartialMonitoringObjects(yGenCompCriteria);
if (appYCompPartial.Count != 1)
{
    throw new InvalidOperationException("Expected one component with: " + qStr);
}

The PartialMonitoringObject returned by the GetPartialMonitoringObjects method does not have the custom ID or FileName properties of the full monitoring object.

See Also

Concepts

Improving Query Performance

Other Resources

Using Operations Manager Data Queries