A MonitoringObject represents an instance of a class that is defined in a management pack. You can query the Operations Manager database to obtain the existing monitoring objects in a management group.
As with other Operations Manager objects, you can define a criteria expression to narrow the search results when you are 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 (in the management pack that defines the class) and any custom properties that are inherited by the class (from its base class).
Because each management pack class inherits the properties of its base class, it is possible for a management pack class to inherit a property that has the same name as another property that is defined for the management pack 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; therefore, 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); List<MonitoringObject> appYComponents = new List<MonitoringObject>(); IObjectReader<MonitoringObject> reader = mg.EntityObjects.GetObjectReader<MonitoringObject>( yComponentCriteria, ObjectQueryOptions.Default); appYComponents.AddRange(reader); 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 management pack 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 it responds 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); List<PartialMonitoringObject > appYCompPartial = new List<PartialMonitoringObject>(); IObjectReader<PartialMonitoringObject > reader = mg.EntityObjects.GetObjectReader< PartialMonitoringObject>( yComponentCriteria, ObjectQueryOptions.Default); appYCompPartial.AddRange(reader); if (appYCompPartial.Count != 1) { throw new InvalidOperationException("Expected one component with: " + qStr); }
The PartialMonitoringObject returned by the method does not have the custom ID or FileName properties of the full monitoring object.