Monitoring with Prometheus
Scrape your Legion agent's metrics with your own Prometheus, and use the example alert rules and Grafana dashboard.
The agent serves Prometheus metrics about your host: its health, whether it is listed, rentals, GPUs, benchmarks and its link to Legion. Point your own Prometheus at it to chart them and to get alerts when something needs you.
You don't have to do this. Legion monitors your hosts itself, over the Legion network. You don't open anything for that. This page is for providers who want their own alerts and dashboards.
The metrics need agent 0.8.0 or later. An older agent has no legion_ series. The agent updates itself.
What you get
Every metric starts with
legion_. Their names are stable: a new series may be added, but none is renamed or removed in a major version of the agent.agent_ Labels are few and bounded:
check,state,version, the GPU numbergpu, and the GPUmodelon one metric. There is no rental ID, host ID or address in them.The older
agent_metrics on the same endpoint are the agent's own internals. Build on the* legion_ones.agent_ *
Turn it on
The agent serves GET / on 127., so only the machine itself can read it. To scrape from another machine, set metrics_ in /:
metrics_addr: 10.0.0.5:9123 # a private interface; 0.0.0.0:9123 listens on every interfaceYou can set METRICS_ in the unit's environment drop-in instead. Then restart the agent:
sudo systemctl restart legion-agentRestarting the agent drops renters' SSH sessions, so pick a quiet moment on a host that is rented.
/ has no password. It shows your GPU model, rental counts and health, never a renter's data. Bind it to a private interface or a VPN address, and firewall the port so only your Prometheus can reach it. The agent logs a warning at startup when the address is not loopback. Never expose it to the internet.
Scrape it
Add the agent to your prometheus., one target for each host:
scrape_configs:
- job_name: legion-agent
scrape_interval: 30s
static_configs:
- targets: ["10.0.0.5:9123", "10.0.0.6:9123"]Check that it works with curl http:/ from the Prometheus machine. You should see lines that start with legion_.
Health checks
legion_ is 1 when all seven checks pass, and 0 when any fails. legion_ is 1 or 0 for each check, so you can see which one failed.
check | Passes when |
|---|---|
controller_ | The last sync with Legion succeeded, and the last success is less than three poll intervals old (at least 2 minutes). |
mesh | The agent's connection to the Legion network is up. |
docker | Docker answered the agent's last poll. |
gpu_ | nvidia-smi answers. A host without GPUs always passes. |
disk_ | The disk that holds the agent's state has at least 10 GiB free. |
certificate | The agent's certificate is valid and has not been revoked. |
clock | The host's clock is within 60 seconds of Legion's. |
Metrics
Health and listing
| Metric | Labels | Meaning |
|---|---|---|
legion_ | 1 healthy, 0 an issue (any failing check). | |
legion_ | check | 1 pass, 0 fail, for each check above. |
legion_ | 1 when the host is listed in the market and can be rented, 0 when it is not. Absent while Legion doesn't say. | |
legion_ | state | One state is 1 and the rest are 0: listed, unlisted, awaiting_, first_, held (agent too old), under_ (not approved yet), quarantined, suspended (your organization), removed, unknown (Legion didn't say). |
Rentals and GPUs
| Metric | Labels | Meaning |
|---|---|---|
legion_ | Rentals running now. | |
legion_ | state | Rentals by state: running, stopped, deleted, failed. |
legion_ | GPUs in the host. | |
legion_ | GPUs held by running rentals. | |
legion_ | Free space on the disk that holds rentals. | |
legion_ | Size of that disk. |
Per GPU
| Metric | Labels | Meaning |
|---|---|---|
legion_ | gpu, model | 1 for each GPU. |
legion_ | gpu | Utilization, 0 to 100. |
legion_ | gpu | Device memory in use. |
legion_ | gpu | Device memory in total. |
legion_ | gpu | Power draw. |
legion_ | gpu | Enforced power limit. |
legion_ | gpu | Temperature. Absent where the driver doesn't report it. |
Benchmarks
These are the figures of the agent's last completed run. They stay available across restarts. See Benchmarks and your score.
| Metric | Labels | Meaning |
|---|---|---|
legion_ | Upload line speed of the last run. | |
legion_ | Download line speed of the last run. | |
legion_ | Sequential disk read speed. | |
legion_ | Sequential disk write speed. | |
legion_ | Random 4 KiB reads a second. | |
legion_ | Random 4 KiB writes a second. | |
legion_ | When the last network and disk run finished (Unix time). | |
legion_ | gpu | FP16 dense matrix multiply speed. |
legion_ | gpu | BF16 dense matrix multiply speed. |
legion_ | gpu | FP32 dense matrix multiply speed. |
legion_ | gpu | Device memory bandwidth. |
legion_ | When the last GPU run finished (Unix time). |
Whether Legion flagged a run is not a metric. Look at the benchmark in the app.
Agent and connection
| Metric | Labels | Meaning |
|---|---|---|
legion_ | 1 when the last sync with Legion succeeded. | |
legion_ | When the last sync succeeded (Unix time). | |
legion_ | 1 when the agent's connection to the Legion network is up. | |
legion_ | Legion's clock minus the host's. | |
legion_ | When the agent's certificate expires (Unix time). | |
legion_ | version | Always 1. The label is the agent's version. |
legion_ | When the agent process started (Unix time). | |
legion_ | Seconds since it started. | |
legion_ | 1 while an update is held back for a renter's open SSH session. |
The agent's certificate lasts about a day. The agent renews it by itself when about 8 hours are left. So alert on under 4 hours, not on days.
Example alert rules
These rules cover the agent being down or unhealthy and which check failed, the host not being listed, no contact with Legion, a stale sync, a certificate about to expire, low disk, a hot GPU, and an update held back for a day. Copy what you want into your Prometheus rule files, or download the file: legion-agent-alerts.yml.
The for: times ride out an agent restart and a busy moment at Legion. Change them and the thresholds to suit your hosts.
groups:
- name: legion-agent
rules:
- alert: LegionAgentDown
expr: up{job="legion-agent"} == 0
for: 5m
labels: { severity: critical }
annotations:
summary: "Cannot scrape the Legion agent on {{ $labels.instance }}"
description: "The agent is down, or its metrics port is not reachable from Prometheus."
- alert: LegionAgentUnhealthy
expr: legion_agent_health_status == 0
for: 10m
labels: { severity: warning }
annotations:
summary: "Legion agent on {{ $labels.instance }} reports an issue"
description: "See legion_agent_health_check for the failing check: {{ range query (printf \"legion_agent_health_check{instance='%s'} == 0\" .Labels.instance) }}{{ .Labels.check }} {{ end }}"
- alert: LegionAgentHealthCheckFailing
expr: legion_agent_health_check == 0
for: 10m
labels: { severity: warning }
annotations:
summary: "Legion agent {{ $labels.instance }}: check {{ $labels.check }} fails"
- alert: LegionHostNotListed
expr: legion_agent_host_listing_status == 0
for: 15m
labels: { severity: info }
annotations:
summary: "{{ $labels.instance }} is not offered for rent"
description: "legion_agent_host_listing_state says why: unlisted, awaiting_first_benchmark, held, under_review, suspended and so on."
- alert: LegionAgentControllerUnreachable
expr: legion_agent_controller_reachable == 0
for: 10m
labels: { severity: warning }
annotations:
summary: "Legion agent on {{ $labels.instance }} cannot reach the controller"
description: "Running rentals are left as they are, but the host takes no new work until it syncs again."
- alert: LegionAgentSyncStale
expr: time() - legion_agent_last_sync_timestamp_seconds > 600
labels: { severity: warning }
annotations:
summary: "Legion agent on {{ $labels.instance }} last synced over 10 minutes ago"
- alert: LegionAgentCertificateExpiring
# The certificate lasts about a day and the agent renews it once a third
# of that is left (about 8 hours), so under 4 hours means renewal failed.
expr: legion_agent_certificate_expiry_timestamp_seconds - time() < 4 * 3600
for: 30m
labels: { severity: warning }
annotations:
summary: "The agent certificate on {{ $labels.instance }} expires in under 4 hours"
description: "The agent renews it by itself when about 8 hours are left; if this fires it has not been able to. Check the agent's log and that it can reach the controller."
- alert: LegionWorkspaceDiskLow
expr: legion_agent_workspace_disk_free_bytes < 20 * 1024^3
for: 15m
labels: { severity: warning }
annotations:
summary: "{{ $labels.instance }} has under 20 GiB free for rentals"
- alert: LegionGPUHot
expr: legion_agent_gpu_temperature_celsius > 88
for: 10m
labels: { severity: warning }
annotations:
summary: "GPU {{ $labels.gpu }} on {{ $labels.instance }} is at {{ $value }} C"
- alert: LegionAgentOutdated
expr: legion_agent_upgrade_deferred == 1
for: 24h
labels: { severity: info }
annotations:
summary: "An agent upgrade has been held back on {{ $labels.instance }} for a day (a renter's SSH session is open)"Grafana dashboard
Download the dashboard (legion-agent-dashboard.). In Grafana open Dashboards, New, Import, upload the file, and pick your Prometheus or VictoriaMetrics data source. It shows health, listing, rentals, GPUs, benchmarks and the certificate for each host.
Troubleshooting
No
legion_series. The agent exposes them after its first poll. A host that has just started shows nothing until then, which is not the same as unhealthy.agent_ health_ * A series is missing, not 0. A figure that can't be measured is left out, never reported as 0. A GPU that doesn't report temperature has no temperature series. Write alerts so that a missing series is not an error.
No benchmark series. They appear after the agent's first completed run. The network and disk run about once a day, and only while the host is idle. A host that is always rented can wait a long time. You can ask for a re-run.
upis 0 for your target. Prometheus can't reach the port. Checkmetrics_, that the agent was restarted, and your firewall.addr legion_is 0. Readagent_ host_ listing_ status legion_for the reason. See Review and approval and Listing and pricing.agent_ host_ listing_ state