Skip to content

Monitoring

Monitoring shows the current metrics of Servers and Jets: free disk, used memory, load or any custom value. Each server or jet keeps one value per metric, with the time of its last update. There is no history.

  • Metrics define what is measured and how it is shown: a progress bar, a gauge or a plain number.
  • Thresholds set the value state to Warning or Critical, and can run a Command or a Flight Plan when the state is reached. A value that is not updated in time becomes Stale.
  • Collectors are ordinary Commands and Flight Plans. Python code saves a value with record_metric(). Webhooks can push values too.

Module

Monitoring is provided by the Cetmix Tower Monitoring module (cetmix_tower_monitoring). It depends on Cetmix Tower Webhook.

Access Rules

Metrics, thresholds and metric values are available to Manager and Root users only. Users do not see them.

Group Metric and its thresholds Metric value and its override thresholds Jet Template metrics
Manager R Same rights as the server or jet: R when added to its "Users", CRU when added to its "Managers", plus D for the values they created. Values of a jet also need access to the jet's server Same rights as the Jet Template
Root CRUD CRUD CRUD

Only Root creates and changes metrics and their thresholds: their collectors and threshold actions run on every server and jet that has the metric.

Values are saved as the user who runs the code that calls record_metric(): the user who runs the command, or the Run as User of a webhook. This user must be able to write the server or jet (be in its "Managers"), otherwise the value is not saved.

Info

CRUD stands for Create, Read, Update, Delete.

Metric Configuration

Metrics are under Settings > Monitoring > Metrics (Cetmix Tower menu).

Field Description
Name Metric name, shown on servers and jets.
Reference Unique reference used in record_metric() and YAML export/import. Leave blank to generate it from the name.
Widget How the value is shown. Progress Bar: used amount of a total, e.g. disk or memory. Gauge: a value with an optional maximum, e.g. CPU usage; without a maximum it is shown as a number. Number: a plain value, e.g. load average.
Unit Shown next to the value, e.g. GiB, MiB or %.
Stale After (minutes) A value not updated for this many minutes becomes Stale. See Settings.
Show on Kanban Show this metric on the server and jet kanban cards.
Pull data, minutes Run the collector of every value of this metric every N minutes. 0 turns pulling off. See Collect values periodically.
Collector Command / Collector Flight Plan Collector run by the Refresh button and by pulling. Set one of them, or none for metrics pushed by a webhook.
Note Detailed description of the metric: what is measured, how it is collected, what the values mean.

Choose a unit for progress bars

On the server and jet form, a progress bar shows whole numbers only: 45.2 of 100 is shown as 45 / 100, 3.1 of 8 as 3 / 8. Record values in a unit where whole numbers are meaningful, e.g. GiB for disk and MiB for memory, not GiB for memory.

Thresholds

Thresholds are on the Thresholds tab of the metric.

Field Description
Condition >=, <=, >, <, == or Stale.
Value Value to compare with. For Progress Bar metrics the condition compares used / total in percent: >= 90 means "90 % or more is used". For Gauge and Number metrics it compares the value.
Severity Warning or Critical. While the condition matches, the value state is at least this severity. Stale thresholds have no severity: the value state is Stale anyway.
Action None, Run Command or Run Flight Plan.

The command or flight plan runs when the condition becomes matched: on the first sample that matches, or when the condition matches again after it stopped matching. Each threshold is tracked on its own, so the value does not need to return to OK in between: with Warning at >= 80 and Critical at >= 90, samples of 95 → 85 → 95 run the Critical action twice. It does not run again on every sample while the condition stays matched.

Actions run on the server of the value. For a jet value they run on the jet's server, for this jet. See Use the metric in threshold actions.

YAML

Metrics are exported and imported with their thresholds and collectors. See YAML export/import.

Metrics on Servers and Jets

Monitoring tab

The Monitoring tab of a server or jet lists every metric with its value, unit, state and last update. Progress bar metrics show a bar, gauge metrics with a maximum show a gauge, other metrics show the number.

  • Pull data (servers only): pull the metric data of this server and its jets. See Collect values periodically.
  • Refresh: runs each collector command or flight plan of the metrics once, even if a collector serves several metrics. Shown only when at least one metric has a collector.

Open a metric value to change it for this server or jet only:

  • Collector Command / Collector Flight Plan: use another collector than the one of the metric.
  • Override Thresholds tab: if a value has any override thresholds, the metric thresholds are not used for it.

Kanban and list

  • Kanban: the overall monitoring state and the metrics marked Show on Kanban. Progress bar metrics show a bar with the used and total values, up to two decimals (45.2 / 100 GiB); other metrics show the number.
  • List: rows are yellow when the overall state is Warning and red when it is Critical or Stale. The optional Monitoring State column shows the state.

Open kanban and list views update by themselves when a metric value or state changes, including updates from a scheduled task, a webhook or a data pull. An open form does not update by itself, so unsaved changes are never lost: reload the page to see the new values.

Metric states

State Meaning
Unknown No value received yet.
OK The value is up to date and no threshold matches.
Warning / Critical The worst severity of the matching thresholds.
Stale The value was not updated within Stale After (minutes) of the metric.

The overall state of a server or jet is the worst state of its metrics, in this order: Critical, Stale, Warning, Unknown, OK.

Metrics from Templates

Server Templates

Add metrics on the Metrics tab of a Server Template. A server created from the template gets a value for each of them, in the Unknown state until the first value is received.

Metrics are copied once, when the server is created. Later changes to the template metrics do not change existing servers. Servers created without the template, or by duplicating a server, do not get them. Set collector overrides and override thresholds on the server values, not on the template.

Jet Templates

Add lines on the Metrics tab of a Jet Template:

Field Description
Metric The metric that jets of this template get.
Environments Leave empty to apply to all jets of the template. Otherwise only jets whose environment is in the list get the metric.

Unlike Server Templates, changes are applied to existing jets: a jet gets a value for each metric that applies to it, and loses the values of metrics that no longer apply, together with their override thresholds. An environment used in a Jet Template metric cannot be deleted.

On the jet Monitoring tab, the Manual column tells the values apart:

  • Manual checked: added by a user, or by record_metric() for a metric the jet had no value for. The Jet Template never changes or deletes it. If the Jet Template adds the same metric later, the manual value is kept and no other value is added.
  • Manual not checked: added from the Jet Template.

Server Template and Jet Template metrics are exported and imported with the template in YAML.

Collecting Values

Collectors

A collector is a Python command, or a flight plan with Python commands, that measures the values and saves them with record_metric(). SSH commands cannot save values: run them from a Python command and parse their output.

One collector can serve several metrics. It must name each metric explicitly, because the Refresh button, pulling and scheduled tasks run it without any metric:

runner = server.with_context(no_command_log=True)
disk = runner.run_command(tower_commands.get_by_reference("my_disk_bytes"))
if disk["status"] == 0:
    used, total = disk["response"].strip().splitlines()[-1].split()
    server.record_metric(
        "disk_root", used=int(used) / 1024 ** 3, total=int(total) / 1024 ** 3
    )
result = {"exit_code": 0, "message": "ok"}

Save a value from Python code

record_metric() is available on servers and jets, in a Python command or in webhook code:

server.record_metric("disk_root", used=45.2, total=100.0)  # progress bar
server.record_metric("cpu", value=37.5, total=100)  # gauge
jet.record_metric("load_1", value=1.37)  # number
  • The metric must exist.
  • A progress bar needs used and total, with total greater than 0 (used can be 0).
  • A gauge or a number needs value; a gauge also takes an optional total.
  • Values must be finite numbers: nan and inf are refused.

Collect values periodically

  • Pull data: set Pull data, minutes on the metric, and enable Pull data on the Monitoring tab of each server to pull. The server and its jets are then pulled; other servers and their jets are skipped. Each collector runs once per server or jet, even if it serves several metrics. The real interval can be longer than N by up to the interval of the Pull metric data cron job (see Settings). The command and flight plan logs of these runs are deleted when the runs are done; logs of commands and flight plans run by thresholds are kept, and so is the log of a run that could not start. Check Last Update on the Monitoring tab to see when a value was received.
  • Scheduled task: create a Scheduled Task that runs the collector command or flight plan on the servers or jets. Use it for a custom schedule. Its logs are kept, as are the logs of the Refresh button.

Push values with a webhook

A Webhook can save values sent by an external system. Webhook code has no current server: resolve it from the payload.

server = tower_servers.get_by_reference(payload["server_reference"])
for item in payload["metrics"]:
    server.record_metric(
        item["reference"],
        value=item.get("value"),
        used=item.get("used"),
        total=item.get("total"),
    )
result = {"exit_code": 0, "message": "ok"}

Use tower_jets.get_by_reference() for jets. Set the Run as User of the webhook to a user that can write the servers or jets.

Use the metric in threshold actions

A Python command run by a threshold, and every Python command of a flight plan run by a threshold (including nested flight plans), has these objects:

Variable Description
metric The metric whose threshold runs the command.
metric_value Its current value, with value, max_value, state and last_update.
server, jet The server, and the jet when the value belongs to a jet.
if metric.reference == "disk_root" and metric_value.state == "critical":
    result = {"exit_code": 0, "message": "disk critical"}

In other commands metric and metric_value are None. Webhook and authenticator code does not have them. Every Python command and webhook can use tower_metrics and tower_metric_values, shortcuts to the metric and metric value models.

SSH commands and flight plan line conditions cannot use Python objects. They get custom values instead, also available in Python as custom_values:

Custom value Content
__metric__ Metric reference
__metric_value__ Current value
__metric_max__ Total or maximum, empty if none
__metric_unit__ Unit
__metric_state__ New state
__metric_previous_state__ State before this update
__metric_severity__ Threshold severity, empty for Stale thresholds
__server__ Server reference
__jet__ Jet reference, empty for a server

Settings

Two cron jobs run monitoring. Open them from Cetmix Tower > Settings > General Settings, Monitoring section, with the Cron Job buttons. See General Settings.

Setting Description
Check stale metrics Marks values that are not updated in time as Stale and runs Stale thresholds. A value becomes Stale on the first run after Stale After (minutes). Runs every 5 minutes by default.
Pull metric data Runs the collectors of metrics with Pull data, minutes set, on servers with Pull data enabled and their jets. Runs every 5 minutes by default.