Create monitors
StackState Self-hosted v5.1.x
Overview
Monitors can be attached to any number of elements in the StackState topology to calculate a health state based on 4T data. Each monitor consists of a monitor definition and a monitor function. Monitors are created and managed by StackPacks, you can also create custom monitors and monitor functions outside of a StackPack without having to modify any configuration.
The example on this page creates a CPU metric monitor using an example monitor function.
β‘οΈ Learn more about the STJ file format used for monitor definitions
Example - CPU metric monitor
To create the example CPU metric custom monitor in StackState we will:
Create a new STJ import file
{
"_version": "1.0.39",
"timestamp": "2022-05-23T13:16:27.369269Z[GMT]",
"nodes": [
...
]
}You can place multiple monitors on the same STJ file. You can also add other node types on the same import file.
β‘οΈ Learn more about the STJ file format used for monitor definitions
Populate the monitor node
A monitor node of type Monitor needs to be added to the import file. This type of node is supported in API version 1.0.39 and above. The required fields are the name, identifier and description. The identifier should be a value that uniquely identifies this specific monitor definition. intervalSeconds, function and arguments determine what validation rule and how often it's run. An optional parameter of remediationHint can be specified - it's a Markdown-encoded instruction of what to do if this monitor produces an unhealthy health state. It's displayed on the interface together with the monitor result panel.
Configuring the monitor function is best done by utilizing the get helper function paired with the identifier of the function itself. In this example the function is named Metric above threshold and its identifier is urn:system:default:monitor-function:metric-above-threshold.
The invocation of the get helper function will automatically resolve to the ID of the desired function during import time.
β‘οΈ Learn more about the STJ file format used for monitor definitions
Populate the parameters of the monitor function invocation
The parameters are different for each monitor function. In the case of Metric above threshold we need to populate threshold, metrics and topologyIdentifierPattern:
Similar to the function, parameters can be referred to by utilizing the get helper function.
For further details of defining arguments in the monitor definition and how to work with commonly used parameters such as a metrics query or topology identifier, see monitor STJ file format > Arguments.
Apply the newly created monitor in StackState
This can be achieved by using the dedicated StackState CLI command:
From StackState v5.0, the old sts CLI has been renamed to stac and there is a new sts CLI. The command(s) provided here are for use with the new sts CLI.
stac monitor apply < path/to/the/file.stj
β οΈ From StackState v5.0, the old sts CLI is called stac. The old CLI is now deprecated.
The new sts CLI replaces the stac CLI. It's advised to install the new sts CLI and upgrade any installed instance of the old sts CLI to stac. For details see:
An alternative way is to include the newly created monitor in a custom StackPack and installing it.
Verify that your newly created monitor is working correctly
You can check if your monitor is working correctly by invoking the CLI command:
From StackState v5.0, the old sts CLI has been renamed to stac and there is a new sts CLI. The command(s) provided here are for use with the new sts CLI.
stac monitor status <id-or-identifier-of-a-monitor>
β οΈ From StackState v5.0, the old sts CLI is called stac. The old CLI is now deprecated.
The new sts CLI replaces the stac CLI. It's advised to install the new sts CLI and upgrade any installed instance of the old sts CLI to stac. For details see:
You can also preview the results it generates by invoking the CLI command:
From StackState v5.0, the old sts CLI has been renamed to stac and there is a new sts CLI. The command(s) provided here are for use with the new sts CLI.
stac monitor preview <id-or-identifier-of-a-monitor>
β οΈ From StackState v5.0, the old sts CLI is called stac. The old CLI is now deprecated.
The new sts CLI replaces the stac CLI. It's advised to install the new sts CLI and upgrade any installed instance of the old sts CLI to stac. For details see:
See also
Last updated