Add a monitor using the CLI
StackState v6.0
Last updated
StackState v6.0
Last updated
StackState provides , which provide monitoring on common issues that can occur in a Kubernetes cluster. It's also possible to configure custom monitors for the metrics collected by StackState or application metrics ingested .
Steps to create a monitor:
As an example the steps will add a monitor for the Replica counts
of Kubernetes deployments.
Create a new YAML file called monitor.yaml
and add this YAML template to it to create your own monitor. Open it in your favorite code editor to change it throughout this guide. At the end the StackState CLI will be used to create and update the monitor in StackState.
The fields in this template are:
_type
: StackState needs to know this is a monitor so, value always needs to be Monitor
aliasTemplate
: An alias for time series in the metric chart. This is a template that can substitute labels from the time series using the ${my_label}
placeholder.
comparator
: Choose one of LTE/LT/GTE/GT to compare the threshold against the metric. Time series for which <metric> <comparator> <threshold>
holds true will produce the failure state.
threshold
: A numeric threshold to compare against.
failureState
: Either "CRITICAL" or "DEVIATING". "CRITICAL" will show as read in StackState and "DEVIATING" as orange, to denote different severity.
titleTemplate
: A title for the result of a monitor. Because multiple monitor results can bind to the same component, it's possible to substitute time series labels using the ${my_label}
placeholder.
description
: A description of the monitor.
function
: A reference to the monitor function that will execute the monitor. Currently only {{ get "urn:stackpack:kubernetes-v2:shared:monitor-function:threshold" }}
is supported.
identifier
: An identifier of the form urn:custom:monitor:....
which uniquely identifies the monitor when updating its configuration.
intervalSeconds
: The interval at which the monitor executes. For regular real-time metric 30 seconds is advised. For longer-running analytical metric queries a bigger interval is recommended.
name
: The name of the monitor
status
: Either "DISABLED"
or "ENABLED"
. Determines whether the monitor will run or not.
tags
: Add tags to the monitor to help organize them in the monitors overview of your StackState instance, http://your-StackState-instance/#/monitors
For example, this could be the start for a monitor which monitors the available replicas of a deployment:
The urnTemplate
and remediationHint
will be filled in the next steps.
The results of a monitor need to be bound to components in StackState, to be visible and usable. The result of a monitor is bound to a component using the component identifiers
. Each component in StackState has one or more identifiers that uniquely identify the component. To bind a result of a monitor to a component, it's required to provide the urnTemplate
. The urnTemplate
substitutes the labels in the time series of the monitor result into the template, producing an identifier matching a component. This is best illustrated with the example:
The metric that's used in this example is the kubernetes_state_deployment_replicas_available
metric. Run the metric in the metric explorer to observe what labels are available on the time series:
In the above table it's shown the metric has labels like cluster_name
, namespace
and deployment
.
Because the metric is observed on deployments, it's most logical to bind the monitor results to deployment components. To do this, it's required to understand how the identifiers for deployments are constructed:
In the UI, navigate to the deployments
view and select a single deployment.
Open the Topology
view, and click the deployment component.
When expanding the Properties
in the right panel of the screen, the identifiers will show after hovering as shown below:
The identifier is shown as urn:kubernetes:/preprod-dev.preprod.stackstate.io:calico-system:deployment/calico-typha
. This shows that the identifier is constructed based on the cluster name, namespace and deployment name. Knowing this, it's now possible to construct the urnTemplate
:
The identifier is used as the unique key of a monitor. Changing the identifier will create a new monitor instead of updating the existing one.
The sts monitor
command has more options, for example it can list all monitors:
To delete a monitor use
To edit a monitor, edit the original of the monitor that was applied, and apply again. Or there is a sts monitor edit
command to edit the configured monitor in the StackState instance directly:
The <id>
in this command isn't the identifier but the number in the Id
column of the sts monitor list
output.
A monitor can be enabled or disabled. Enabled means the monitor will produce results, disabled means it will suppress all output. Use the following commands to enable/disable:
It's good practice to, after a monitor is made, validate whether it produces the expected result. The following steps can be taken:
Go to the monitor overview page (http://your-StackState-instance/#/monitors) and find your monitor.
Verify you see the expected amount of states in the Clear
/Deviating
/Critical
column. If the number of states is significantly lower or higher than the amount of components you meant to monitor, the PromQL query might be giving too many results.
Get the status of the monitor through the CLI
The section Monitor Stream errors:
will show the errors happening on the monitor and offer further help.
query
: A PromQL query. Use the of your StackState instance, http://your-stackstate-instance/#/metrics, and use it to construct query for the metric of interest.
unit
: The unit of the values in the time series returned by the query or queries, used to render the Y-axis of the chart. See the reference for all units.
urnTemplate
: A template to construct the urn of the component a result of the monitor will be .
remediationHint
: A description of what the user can do when the monitor fails. The format is markdown, with optionally use of handlebars variables to customize the hint based on time series or other data ().
whether the urnTemplate
is correct, is explained further below.
The remediation hint is there to help users find the cause of an issue when a monitor fires. The remediation hint is written in . It's also possible to use the labels that are on the time series of the monitor result using a handlebars template, as in the following example:
After completing the monitor.yaml
, use the to create or update the monitor:
Verify whether the monitor produces the expected results, using the steps .
Verify the Status
column is in Enabled
state. If the monitor is in Disabled
state, . If the status is in Error
state, follow the steps below .
Observe whether the monitor is producing a result on one of the components that it's meant to monitor for. If the monitor doesn't show up, follow to remedy.
First check if the monitor is actually . If this is the case but the monitor results do not show up on the components, there might be a problem with the binding. First use the following command to verify:
If the output has Monitor health states with identifier which has no matching topology element (<nr>): ....
, this shows that the urnTemplate
may not generate an identifier matching the topology. To remedy this .