Skip to main content

Using Application Monitor

Application Monitor monitors a user-extensible set of metrics, maintains a persistent repository of the data it collects, and triggers user-configured alerts.

Application Monitor is part of the System Monitor tools.

Overview

Application Monitor is an extensible utility that monitors a user-selected set of system- and user-defined metrics in each startup namespace configured in System Monitor. As described in Default System Monitor Components, when %SYS.Monitor.AppMonSensor, the Application Monitor sensor class, is called by System Monitor, it samples metrics, evaluates the samples, and generates its own notifications. (Unlike System Monitor and Health Monitor notifications, these are not written to the messages log.) Specifically, Application Monitor does the following in each System Monitor startup namespace:

  1. Starts when System Monitor starts.

  2. Lets you register the provided system monitor classes (they are registered in %SYS by default).

  3. Lets you activate the system and user-defined classes you want to monitor. You can activate any registered system class; you can activate any user-defined class that is present in the local namespace. For example, if you have created a user-defined class only in the USER namespace, you can activate that class only in the USER namespace.

  4. Monitors each active class by sampling the metrics specified by the class. These metrics represent the properties returned by the sample class called by the GetSample() method of the monitor class. For example, the %Monitor.System.LockTableOpens in a new tab class calls %Monitor.System.Sample.LockTableOpens in a new tab which returns (among others) the properties TotalSpace, containing the total size of the lock table, and UsedSpace, containing the size of the lock table space in use. The sampled data, along with monitor and class metadata, is stored in the local namespace and can be accessed by all object and SQL methods.

  5. If an alert is configured for a class and the class returns a property value satisfying the evaluation expression configured in it, generates an email message or calls a class method, if one of these actions is configured in the alert. For example, you can first configure email notifications to a list of recipients, then configure an alert for the %Monitor.System.LockTableOpens in a new tab class, specifying that an email be sent when the ratio of the UsedSpace property of %Monitor.System.Sample.LockTableOpens in a new tab to the TotalSpace property is greater than .9 (90% full).

Note:

The %Monitor.System.HistorySysOpens in a new tab and %Monitor.System.HistoryPerfOpens in a new tab classes provided with Application Monitor, when activated, create and maintain a historical database of system usage and performance metrics to help you analyze system usage and performance issues over time. These classes and %Monitor.System.HistoryUserOpens in a new tab run only in %SYS and cannot be registered in other namespaces. See History Monitor for more information about these classes and the historical database.

Using ^%SYSMONMGR to Manage Application Monitor

As described in Using the ^%SYSMONMGR Utility, the ^%SYSMONMGR utility lets you manage and configure System Monitor, including Application Monitor. The utility can be executed in any namespace, and changes made with it affect only the namespace in which it is started. You must maintain a separate Application Monitor configuration for each startup namespace you configure by starting ^%SYSMONMGR in that namespace.

Note:

Following any change you make to the Application Monitor configuration, such as activating a class, you must restart System Monitor in the namespace in which you made the change for the change to take effect.

To manage Application Monitor, enter the following command in the Terminal:

%SYS>do ^%SYSMONMGR

then enter 5 for Manage Application Monitor. The following menu displays:

1) Set Sample Interval
2) Manage Monitor Classes
3) Change Default Notification Method
4) Manage Email Options
5) Manage Alerts
6) Debug Monitor Classes
7) Exit
 
Option?

Enter the number of your choice or press Enter to exit the Application Monitor utility.

Manage Application Monitor

The options in the main menu let you manage Application Monitor as described in the following table:

Option Description
1) Set Sample Interval

Sets the interval at which metrics are sampled; the default is 30 seconds. This setting can be overridden for an individual class by setting a class-specific interval (using the Set Class Sample Interval option on the Manage Monitor Classes submenu).

Note: if the System Monitor sampling interval (see Set Sample Interval in the Set System Monitor Options submenu) is longer than the sampling interval for an Application Monitoring class, the longer of the two intervals is used. For example, if the System Monitor interval is 30 and the Application Monitor interval is 120, all active Application Monitor classes are sampled every 120 seconds; if the System Monitor interval is 60 and the %Monitor.System.LockTableOpens in a new tab class interval is 20, the class is sampled every 60 seconds.

2) Manage Monitor Classes Displays the Manage Monitor Classes submenu which lets you manage system- and user-defined monitor classes in the namespace in which you are running the Application Monitor Manager.
3) Change Default Notification Method Lets you specify the default action for alerts when triggered. Any alerts you create use this action unless you specify otherwise.
4) Manage Email Options Displays the Monitor Email Options submenu which lets you enable and configure email notifications so you can specify this action in alerts.
5) Manage Alerts Displays Manage Alerts submenu which lets you create alerts for system and user-defined monitor classes.

Manage Monitor Classes

This submenu lets you manage system and user-defined monitor classes. Enter the number of your choice or press Enter to return to the main menu:

Option? 2
 
1) Activate/Deactivate Monitor Class
2) List Monitor Classes
3) Register Monitor System Classes
4) Remove/Purge Monitor Class
5) Set Class Sample Interval
6) Exit
 
Option?

This submenu displays a list of menu items that let you manage the system- and user-defined classes as described in the following table:

Option Description
1) Activate / Deactivate Monitor Class

Application Monitor samples active classes only. This option lets you activate an inactive class, or deactivate an active one. You can display a numbered list of the system and user-defined classes registered in the local namespace, including the activation state of each, by entering ? at the Class? prompt, then enter either the number or class name.

2) List Monitor Classes

Displays a list of the system- and user-defined classes registered in the local namespace, including the activation state of each.

3) Register Monitor System Classes

Registers all system monitor classes (except the %Monitor.System.HistorySysOpens in a new tab, %Monitor.System.HistoryPerfOpens in a new tab, and %Monitor.System.HistoryUserOpens in a new tab classes) and stores them in the local namespace. System classes must still be activated using option 1) Activate/Deactivate Monitor Class on this menu for sampling to begin.

4) Remove/Purge Class

Removes a monitor class from the list of classes in the local namespace. You can display a numbered list of the system and user-defined classes registered in the local namespace, including the activation state of each, by entering ? at the Class? prompt, then enter either the number or class name.

Note:

This option does not remove the class, but simply removes the name of the class from the list of registered classes that can be activated. To reset the list, choose option 3) Register Monitor System Classes on this menu.

5) Set Class Sample Interval

Lets you override the default Application Monitor sampling interval, specified by the 1) Set Sample Interval option of the Manage Application Monitor menu, for a single class. The default is 0, which means the class does not have a class-specific sample interval.

See the description of the Set Sample Interval option for an explanation of precedence between this setting, the Set Sample Interval setting, and the System Monitor sample interval discussed in Set System Monitor Options.

6) Debug Monitor Classes

Displays Debug Monitor Classes menu which lets you enable and disable debugging as well as lists errors.

Debug Monitor Classes

This submenu lets you manage system debugging.

Debugging monitor classes adds the capability to capture any errors generated during the collection of sample values by user-defined Application Monitor classes.

Enter the number of your choice or press Enter to return to the main menu:

Option? 6
 
1) Enable Debug
2) Disable Debug
3) List Errors
4) Exit
 
Option?

The options in this submenu let you manage debugging for Application Monitor as described in the following table:

Input Field Description
1) Enable Debug

Lets you enable debugging. If the class is not creating sample values, then you can check to see if errors are preventing the sample values from being saved.

2) Disable Debug

Lets you disable debugging.

3) List Errors

Displays the definitions of all errors in the local namespace; for example:

%Save(), %New(), Initialize() and GetSample().

Enable debugging for the class using ^%SYSMONMGR, and the System Monitor will save the last error caught for specific methods within the class.

Change Default Notification Method

When you create an alert, you specify an action to be taken when it is triggered; the default choice for this action is the default notification method, set using this option. Enter the number of your choice or press Enter to return to the main menu:

Option? 3
  
Notify Action (0=none,1=email,2=method)? 0 => 

The choice you make with this option is used when you configure an alert to use the default notification method, as described in the following table:

Input Field Description
0

Do not take action when an alert is triggered.

1

Send an email message to the configured recipients when an alert is triggered. For information about configuring email, see Manage Email Options.

2

Call a notification method when an alert is triggered. If you select this action, the method is called with two arguments – the application name specified in the alert and a %List object containing the properties returned to the monitor class by the sample class (as described in Application Monitor Overview). When prompted, enter the full class name and method, that is packagename.classname.method. This method must exist in the local namespace.

Manage Email Options

The options in this submenu let you configure and enable email. When email is enabled, Application Monitor sends email notifications when an alert configured for them is triggered. Enter the number of your choice or press Enter to return to the main menu:

Option? 4

1) Enable/Disable Email
2) Set Sender
3) Set Server
4) Manage Recipients
5) Set Authorization
6) Test Email
7) Exit

Option? 

The options in this submenu let you manage the email notifications for the Application Monitor as described in the following table:

Option Description
1) Enable / Disable Email

Enabling email makes it possible for Application Monitor to send email notifications when alerts are triggered, if configured. Disabling email prevents Application Monitor from sending email notifications when an alert is triggered.

Note:

It is not necessary to reconfigure email options when you disable and then reenable email.

2) Set Sender

This option is required. Enter text identifying the sender of the email. Depending on the specified outgoing mail server, this may or may not have to be a valid email account.

3) Set Server

This option is required. Enter the name of the server that handles outgoing email for your site. If you are not sure, your IT staff should be able to provide this information.

4) Manage Recipients

This option displays a submenu that lets you list, add, or remove valid email addresses of recipients: 1) List Recipients 2) Add Recipient 3) Remove Recipient 4) Exit

When adding or removing recipients, email addresses must be entered individually, one per line. Addresses of invalid format are rejected.

5) Set Authorization

Lets you specify the authorization username and password if required by your email server. Consult your IT staff to obtain this information. If you do not provide entries, the authorization username and password are set to NULL.

6) Test Email

Sends a test message to the specified recipients using the specified email server. If the attempt fails, the resulting error message may help you fix the problem.

Manage Alerts

An alert specifies:

  • a condition within the namespace that is of concern to you, defined by the values of properties sampled by a monitor class.

  • an action to be taken to notify you when that condition occurs.

To return to the previous example, you might create an alert specifying:

The definition of a condition based on properties is called an evaluation expression; after specifying the properties of the sample class you want to use, you specify the evaluation expression. Properties are indicated in the expression by placeholders corresponding to the order in which you provide them; for example, if when creating the lock table alert you specify the UsedSpace property first and then the TotalSpace property, you would enter the evaluation expression as %1 / %2 > .9, but if you enter the properties in the reverse order, the expression would be %2 / %1 > .9.

When the alert menu displays, enter the number of your choice or press Enter to return to the main menu:

Option? 2
 
1) Create Alert
2) Edit Alert
3) List Alerts
4) Delete Alert
5) Enable/Disable Alert
6) Clear NotifyOnce Alert
7) Exit
 
Option?

The options in this submenu let you manage alerts for the Application Monitor as described in the following table:

Input Field Description
1) Create Alert

Lets you define a new alert. For a description of the prompts and responses, see the Responses to Alert Prompts. The newly created alert is enabled by default.

2) Edit Alert

Lets you modify an existing alert. Enter the name of the alert to edit, or enter ? for a list of existing alerts and then enter a number or name.

Note:

You must respond to all prompts including those that you do not want to modify; that is, you must re-enter information for fields that you do not want to modify as well as the revised information for the fields you are modifying. For a description of the prompts and responses, see Responses to Alert Prompts.

3) List Alerts

Displays the definitions of all alerts in the local namespace; for example:

Alert: LockTable90 USER

Action: email

Class: %Monitor.System.LockTable

Property: UsedSpace,TotalSpace

Expression: %1/%2>.9

Notify Once: True

Enabled: Yes

4) Delete Alert

Lets you delete an existing alert. Enter the name of the alert to edit, or enter ? for a list of existing alerts and then enter a number or name.

Note:

Each alert must be entered individually; that is, you cannot specify a series or range of alerts to delete.

5) Enable / Disable Alert

Enabling an alert activates it. Disabling an alert deactivates it.

Note:

It is not necessary to reconfigure alert options when you disable and then reenable an alert.

6) Clear NotifyOnce Alert

Lets you set an internal Notified flag for a specified Alert name when the Alert is triggered. When set, it will not post another Alert.

The following table describes the valid responses to Alert prompts:

Responses to Alert Prompts
Input Field Description
Alert Name?

Enter an alphanumeric name. To display a numbered list of alert names already defined in the local namespace, enter ? at the Alert Name? prompt.

Application?

Enter descriptive text to be passed to the email message or notification method. This text can include references to the properties you specify at the Property? prompt later in the procedure in the form %N, where %1 refers to the first property in the list of properties, %2 the second property, and so on.

Action (0=default, 1=email, 2=method)?

Specifies the action to take when the alert is triggered. Enter one of the following options:

  • 0 – Use the notification method identified as the default method (none, email, or class method). See Change Default Notification Method.

  • 1 – Send an email message containing your descriptive text and the names and values of the properties returned to the monitor class by the sample class (as described in Application Monitor Overview) to the configured email recipients when an alert is triggered. For information about configuring email, see Manage Email Options.

  • 2 – Call a specified notification method with two arguments – your descriptive text and a %List object containing the properties returned to the monitor class by the sample class (as described in Application Monitor Overview).

    When prompted, enter the full class name and method, that ispackagename.classname.method. This method must exist in the local namespace.

Raise this alert during sampling?

orDefine a trigger for this alert?

The first prompt is displayed when are creating an alert; the send prompt is displayed when you are editing an alert for which you entered No at the first prompt when creating it. Enter one of the following:

  • Yes – Continues prompting for required information.

  • No – Skips to the end, bypassing Class, Property and Evaluation expression prompts.

Class?

Enter the name of a system or user-defined monitor class registered in the local namespace. To display a numbered list of registered classes in the local namespace, including its activation state, enter ? at the Class? prompt, then enter a number or name.

Note:

You can create an alert for an inactive class. An alert is not removed when the class it is configured for is removed.

Property?

Enter the name of a property defined in the class specified in the preceding prompt that you are using in the evaluation expression, in the descriptive text, or in both.. To display a numbered list of properties defined in the named class, enter ? at the Property? prompt, then enter a number or name. Each property must be entered individually. When you are done, press Enter at an empty prompt to display the list of properties in the order in which you specified them.

Evaluation expression?

Expression used to evaluate the properties specified at the Property? prompt. For example, in (%1 = "User") && (%2 < 100), %1 refers to the first property in the list of properties, %2 the second property, and so on.

Notify once only?

Enter one of the following:

  • Yes – Notify users only the first time an alert is triggered.

  • No – Notify users every time an alert is triggered.

Application Monitor Metrics

The system monitor classes included with Application Monitor call various sample classes, as shown in the following table:

Sample Classes Application Monitor System Classes
Audit metrics %Monitor.System.Sample.AuditCountOpens in a new tab and %Monitor.System.Sample.AuditEventsOpens in a new tab
Client metrics %Monitor.System.Sample.ClientsOpens in a new tab
Web Gateway metrics %Monitor.System.Sample.CSPGatewayOpens in a new tab
Disk space metrics %Monitor.System.Sample.DiskspaceOpens in a new tab
Free space metrics %Monitor.System.Sample.FreespaceOpens in a new tab
Global metrics %Monitor.System.Sample.GlobalsOpens in a new tab
History database metrics (see History Monitor) %Monitor.System.Sample.HistoryPerfOpens in a new tab, %Monitor.System.Sample.HistorySysOpens in a new tab, %Monitor.System.Sample.HistoryUserOpens in a new tab
Journal metrics %Monitor.System.Sample.JournalsOpens in a new tab
License metrics %Monitor.System.Sample.LicenseOpens in a new tab
Lock table metrics %Monitor.System.Sample.LockTableOpens in a new tab
Process metrics %Monitor.System.Sample.ProcessesOpens in a new tab
Routine metrics %Monitor.System.Sample.RoutinesOpens in a new tab
Server metrics %Monitor.System.Sample.ServersOpens in a new tab
System activity metrics %Monitor.System.Sample.SystemMetrics

For a list of properties corresponding to the sample metrics in each category, see the InterSystems Class Reference.

Similar functions that control the MONITOR facility are available through the classes in the %Monitor.System package, which also allows you to save the data as a named collection in a persistent object format. See the %Monitor.System.Sample package classes and the %Monitor.System.SystemMetricsOpens in a new tab class documentation in the InterSystems Class Reference for more details.

Generating Metrics

The %Monitor.SampleAgent class does the actual sampling, invoking the Initialize() and GetSample() methods of the metrics classes.

The %Monitor.SampleAgent.%New() constructor takes one argument: the name of the metrics class to run. It creates an instance of that class, and invokes the Startup() method on that class. Then, each time the %Monitor.SampleAgent.Collect() method is invoked, the Sample Agent invokes the Initialize() method for the class, then repeatedly invokes the GetSample() method for the class. On each call to GetSample(), %Monitor.SampleAgent creates a sample class for the metrics class. The pseudocode for these operations is:

set sampler = ##class(%Monitor.SampleAgent).%New("MyMetrics.Freespace")
/* at this point, the sampler has created an instance of MyMetrics.Freespace,
and invoked its Startup method */
for I=1:1:10 { do sampler.Collect() hang 10 }
/* at each iteration, sampler calls MyMetrics.Freespace.Initialize(), then loops
on GetSample().  Whenever GetSample() returns $$$OK, sampler creates a new
MyMetrics.Sample.Freespace instance, with the sample data. When GetSample()
returns an error value, no sample is created, and sampler.Collect() returns. */

Viewing Metrics Data

All metrics classes are CSP-enabled; the CSP code is generated automatically when the sample class is generated. Therefore, the simplest way to view metrics is using a web browser. Based on the example in Generating Metrics, the CSP URL has the following form, which uses the <baseURL> for your instance: http://<baseURL>/csp/user/MyMetrics.Sample.Freespace.cls. The output displayed is similar to:

Monitor - Freespace c:\InterSystems\IRIS51\ 
            Name of dataset:  c:\InterSystems\IRIS51\
Current amount of Freespace:  8.2MB

Monitor - Freespace c:\InterSystems\IRIS51\mgr\ 
            Name of dataset:  c:\InterSystems\IRIS51\mgr\
Current amount of Freespace:  6.4MB

Alternatively, you can use the Display(metric_class) method of the %Monitor.ViewOpens in a new tab class; for example:

%SYS>set mclass="Monitor.Test.Freespace"

%SYS>set col=##class(%Monitor.SampleAgent).%New(mclass)

%SYS>write col.Collect()
1
%SYS>write ##class(%Monitor.View).Display(mclass)

Monitor - Freespace    c:\InterSystems\IRIS51\
                Name of dataset:  c:\InterSystems\IRIS51\
    Current amount of Freespace:  8.2MB

Monitor - Freespace    c:\InterSystems\IRIS51\mgr\
                Name of dataset:  c:\InterSystems\IRIS51\mgr\
    Current amount of Freespace:  6.4MB

Note:

The URL for a class with % (percent sign) in the name must use %25 in its place. For example, the URL for the %Monitor.System.FreespaceOpens in a new tab class has the following form, which uses the <baseURL> for your instance:

http://<baseURL>/csp/sys/%25Monitor.System.Freespace.cls

Writing User-Defined Application Monitor Classes

In addition to the provided system classes, you can write your monitor and sample classes to monitor user application data and counters.

A monitor class is any class that inherits from the abstract Monitor class, %Monitor.AdaptorOpens in a new tab; the %Monitor.System classes are examples of such classes. To create your own user-defined monitor classes:

  1. Run ^%MONAPPMGR in the namespace where you want to monitor data. Use option 2 to list monitor classes, and within that menu, use option 3 to register monitor system classes.

    SAMPLES>d ^%MONAPPMGR
     
     
    1) Set Sample Interval
    2) Manage Monitor Classes
    3) Change Default Notification Method
    4) Manage Email Options
    5) Manage Alerts
    6) Exit
     
    Option? 2
     
    1) Activate/Deactivate Monitor Class
    2) List Monitor Classes
    3) Register Monitor System Classes
    4) Remove/Purge Monitor Class
    5) Set Class Sample Interval
    6) Exit
     
    Option? 3
    Exporting to XML started on 06/21/2022 12:52:36
    Exporting class: Monitor.Sample
    Export finished successfully.
     
    Load started on 06/21/2022 12:52:36
    Loading file C:\InterSystems\SRCCTRL\mgr\Temp\t0jFhPqLkZoYAA.stream as xml
    Imported class: Monitor.Sample
    Compiling class Monitor.Sample
    Compiling table Monitor.Sample
    Compiling routine Monitor.Sample.1
    Load finished successfully.
     
     
    1) Activate/Deactivate Monitor Class
    2) List Monitor Classes
    3) Register Monitor System Classes
    4) Remove/Purge Monitor Class
    5) Set Class Sample Interval
    6) Exit
     
    Option?
    
  2. Write a class that inherits from %Monitor.AdaptorOpens in a new tab. The inheritance provides persistence, parameters, properties, code generation, and a projection that generates the monitor metadata from your class definition. See the %Monitor.AdaptorOpens in a new tab class documentation for full details on this class, as well as the code you must write.

  3. Compile your class. Compiling classes that inherit from %Monitor.AdaptorOpens in a new tab generates new sample classes in a subpackage of the users class called Sample. For example, if you compile A.B.MyMetric, a new class is generated in A.B.Sample.MyMetric. You do not need to do anything with the generated class.

    Important:

    When deleting application monitor classes, only the monitor class should be deleted; that is, do not delete generated sample classes. Use the Management Portal to delete only the monitor class (for example, A.B.MyMetric) from which the sample class (for example, A.B.Sample.MyMetric) is generated; this automatically deletes both the monitor class and generated sample class.

All sample classes are automatically CSP-enabled, so that sample data for the user's metrics may be viewed by pointing to A.B.Sample.MyMetric.cls. Application Monitor automatically invokes this class and generates data and alerts, if the class has been activated; for information about activating monitor classes, see Manage Monitor Classes.

Important:

The SECURITYRESOURCE parameter is empty in %Monitor.AdaptorOpens in a new tab, and therefore in user classes inheriting from %Monitor.AdaptorOpens in a new tab unless explicitly modified. Code generation copies the SECURITYRESOURCE value from the user-defined class to the generated sample class.

The following simple example retrieves the free space for each dataset in an InterSystems IRIS instance.

Each sampling requests n instances of sample data objects, each instance corresponding to a dataset. In this example, each instance has only a single property, the free space available in that dataset when the sample was collected.

  1. Create a class that inherits from %Monitor.AdaptorOpens in a new tab:

    Class MyMetric.Freespace Extends %Monitor.Adaptor [ ProcedureBlock ]
    {
    }
    
  2. Add properties that you want to be part of the sample data. Their types must be classes within the %Monitor package:

    • Gauge

    • Integer

    • Numeric

    • String

    For example:

    Class MyMetric.Freespace Extends %Monitor.Adaptor [ ProcedureBlock ]
    {
    /// Name of dataset
    Property DBName As %Monitor.String(CAPTION = "Database Name");
    
    /// Current amount of Freespace
    Property FreeSpace As %Monitor.String;
    }
  3. Add an INDEX parameter that tells which fields form a unique key among the instances of the samples:

    Parameter INDEX = "DBName";
    
  4. Add control properties as needed, marking them [Internal] so they do not become part of the storage definition in the generated class.

    /// Result Set for use by the class
    Property Rspec As %SQL.StatementResult [Internal];
    
  5. Override the Initialize() method. Initialize() is called at the start of each metrics gathering run.

    /// Initialize the list of datasets and freespace.
    Method Initialize() As %Status
    {
        set stmt=##class(%SQL.Statement).%New()
        set status= stmt.%PrepareClassQuery("SYS.Database","FreeSpace")
        set ..Rspec = stmt.%Execute()
        return $$$OK
    }
  6. Override the GetSample() method. GetSample() is called repeatedly until a status of 0 is returned. You write code to populate the metrics data for each sample instance.

    /// Get dataset metric sample.
    /// A return code of $$$OK indicates there is a new sample instance.
    /// A return code of 0 indicates there is no sample instance.
    Method GetSample() As %Status
    {
        // Get freespace data
        set stat = ..Rspec.%Next(.sc)
    
        // Quit if we have done all the datasets
        if 'stat {
            Quit 0
        }
    
        // populate this instance
        set ..DBName = ..Rspec.%Get("Directory")
        set ..FreeSpace = ..Rspec.%Get("Available")
    
        // quit with return value indicating the sample data is ready
        return $$$OK
    }
  7. Compile the class. The class is shown below:

    Class MyMetric.Freespace Extends %Monitor.Adaptor
    {
    Parameter INDEX = "DBName";
    
    /// Name of dataset
    Property DBName As %Monitor.String;
    
    /// Current amount of Freespace
    Property FreeSpace As %Monitor.String;
    
    /// Result Set
    Property Rspec As %SQL.StatementResult [Internal];
    
    /// Initialize the list of datasets and freespace.
    Method Initialize() As %Status
    {
        set stmt=##class(%SQL.Statement).%New()
        set status= stmt.%PrepareClassQuery("SYS.Database","FreeSpace")
        set ..Rspec = stmt.%Execute()
        return $$$OK
    }
    
    /// Get routine metric sample. 
    /// A return code of $$$OK indicates there is a new sample instance. 
    /// Any other return code indicates there is no sample instance. 
    Method GetSample() As %Status
    {
        // Get freespace data
        set stat = ..Rspec.%Next(.sc)
    
        // Quit if we have done all the datasets
        if 'stat {
            Quit 0
        }
    
        // populate this instance
        set ..DBName = ..Rspec.%Get("Directory")
        set ..FreeSpace = ..Rspec.%Get("Available")
    
        // quit with return value indicating the sample data is ready
        return $$$OK
    }
    
    }
  8. Additionally, you can override the Startup() and Shutdown() methods. These methods are called once when sampling begins, so you can open channels or perform other one-time-only initialization:

    /// Open a tcp/ip device to send warnings
    Property io As %Status;
    
    Method Startup() As %Status
    {
        set ..io="|TCP|2"
        set host="127.0.0.1"
        open ..io:(host:^serverport:"M"):200
    }
    
    Method Shutdown() As %Status
    {
        close ..io
    }
    
    
  9. Compiling the class creates a new class, MyMetric.Sample.Freespace in the MyMetric.Sample package :

    /// Persistent sample class for MyMetric.Freespace
    Class MyMetric.Sample.Freespace Extends Monitor.Sample 
    {
    Parameter INDEX = "DBName";
    
    Property Application As %String [ InitialExpression = "MyMetric" ];
    
    /// Name of dataset
    Property DBName As %Monitor.String(CAPTION = "");
    
    /// Current amount of Freespace
    Property FreeSpace As %Monitor.String(CAPTION = "");
    
    Property GroupName As %String [ InitialExpression = "Freespace" ];
    
    Property MetricsClass As %String [ InitialExpression = "MyMetric.Freespace" ];
    
    }
    Note:

    You should not modify this class. You may, however, inherit from it to write custom queries against your sample data.

    Important:

    If you do modify and recompile an active user-defined Application monitor class, the class is deactivated and the class-specific sample interval override, if any, is removed; to restore it, you must activate it, reset the sample interval if desired, and restart of System Monitor.

See Also

FeedbackOpens in a new tab