All posts

Monitor every NodeRings VM with Prometheus, without editing prometheus.yml

prometheus-noderings-sd gives Prometheus the list of your NodeRings VMs, game servers and DNS host names, with region, plan, provider and tags as labels. A new VM showed up in Prometheus 53 seconds after we created it, and dropped out about a minute after we deleted it.

Written by NodeRings Inc.

NodeRings Inc. writes these notes. The company runs the marketplace and the agent that stays on the provider’s side of the hypervisor.

We created a VM called prom-sd-demo through the NodeRings API at 23:27:33 UTC. Nobody touched the Prometheus configuration. At 23:28:26 Prometheus knew about the new server, labelled with its city, plan, provider and the tags web and demo. Once the VM had finished installing, Prometheus started scraping it. When we deleted the VM at 23:32:24, it dropped out of Prometheus 62 seconds later.

The piece in the middle is prometheus-noderings-sd, a small open-source service that tells Prometheus which NodeRings VMs you have. This post shows what it does, how to run it, and what our test run looked like, with screenshots.

What it does, and what it doesn't

Prometheus collects metrics by visiting each server and reading a page of numbers, usually from node_exporter on port 9100. To do that, it needs a list of servers. Most people type that list into prometheus.yml by hand and then forget to update it.

prometheus-noderings-sd keeps that list for you:

  1. It asks the NodeRings API which VMs exist, every 60 seconds by default.
  2. Prometheus asks prometheus-noderings-sd for its target list, using Prometheus' built-in HTTP service discovery.
  3. Prometheus scrapes each VM directly.

It never collects metrics itself, and it only reads from the API. It never creates, changes or deletes anything. The metrics come from whatever exporter you run on the VMs.

NodeRings already records CPU, memory, disk and network for every VM from the hypervisor, and you can view them in your own Grafana or the one in the console. Use prometheus-noderings-sd when you run your own Prometheus and want metrics from inside the VM: per-filesystem disk usage, systemd units, or your application's own /metrics.

What you need

Step 1: Run prometheus-noderings-sd

Download the archive for your platform from the releases page, or use the container image:

docker run -d --name noderings-sd --restart unless-stopped \
  -p 127.0.0.1:10064:10064 \
  -e NODERINGS_TOKEN=<TOKEN> \
  ghcr.io/noderings/prometheus-noderings-sd:latest \
  --target.port=9100

The token is read from the environment, or from a file with --noderings.token-file, so it never shows up in the process list. Port 10064 is the service's default, taken from Prometheus' default port allocations.

Check that it sees your VMs:

curl -s localhost:10064/targets

This is what it returned for one of our VMs, trimmed:

[
  {
    "targets": ["203.0.113.10:9100"],
    "labels": {
      "__meta_noderings_vm_hostname": "fairowl-sc-gc-1c-1g-20-01",
      "__meta_noderings_vm_status": "started",
      "__meta_noderings_vm_distro": "ubuntu_26_04",
      "__meta_noderings_vm_cpus": "1",
      "__meta_noderings_vm_memory_bytes": "1073741824",
      "__meta_noderings_region_city": "Ashburn",
      "__meta_noderings_region_country": "United States",
      "__meta_noderings_plan_code": "SC-GC-1C-1G-20",
      "__meta_noderings_provider_name": "Enzonix",
      "__meta_noderings_billing_type": "usage",
      "__meta_noderings_tags": ""
    }
  }
]

Each VM gets its public IPv4 address plus the port as the target, and 23 labels in total. The full list is in the README.

Step 2: Point Prometheus at it

scrape_configs:
  - job_name: noderings-node
    http_sd_configs:
      - url: http://127.0.0.1:10064/targets?port=9100
    relabel_configs:
      # Only scrape VMs that are running.
      - source_labels: [__meta_noderings_vm_status]
        regex: started
        action: keep
      # Show the hostname instead of IP:port.
      - source_labels: [__meta_noderings_vm_hostname]
        target_label: instance
      - source_labels: [__meta_noderings_region_city]
        target_label: city
      - source_labels: [__meta_noderings_plan_code]
        target_label: plan
      - source_labels: [__meta_noderings_provider_name]
        target_label: provider
      # Every NodeRings tag becomes a tag_<name>="true" label.
      - regex: __meta_noderings_tag_(.+)
        action: labelmap
        replacement: tag_$1

Labels that start with __meta_ exist only during relabeling. Copy the ones you want onto your metrics, as above. The ?port= parameter sets the port for this job, so a second job can scrape your application on 8080 from the same service. To pick VMs by tag, keep only the ones whose __meta_noderings_tags matches .*,web,.*.

After a reload, open Status → Service discovery in Prometheus. The left column shows everything NodeRings reported, and the right column shows the labels your metrics will carry:

Prometheus 3.7 Service discovery page for the noderings-node pool, 2 of 2 targets. Discovered labels on the left: __address__ 203.0.113.10:9100 and __meta_noderings labels for backups_enabled false, billing_type usage, firewall_ruleset_id, plan_code SC-GC-1C-1G-20, plan_id, provider_name Enzonix, public_ipv4, public_ipv6, region_city Ashburn, region_country United States, region_id, vm_cpus 1, vm_disk_bytes 21474836480, vm_distro ubuntu_26_04, vm_hostname fairowl-sc-gc-1c-1g-20-01, vm_id, vm_memory_bytes 1073741824 and vm_status started. Target labels on the right: city Ashburn, country United States, instance fairowl-sc-gc-1c-1g-20-01, job noderings-node, plan, provider Enzonix and vm_id.
Discovered labels on the left; the labels that end up on your metrics after relabeling on the right.

Step 3: Let Prometheus reach the exporter

Install the exporter on the VM:

sudo apt-get install -y prometheus-node-exporter

It listens on port 9100 on all interfaces. Don't leave that port open to the internet. Allow only your Prometheus server, either with a rule in the VM's firewall ruleset in the console or on the VM itself. In our test we used nftables on the VM, with 203.0.113.5 standing in for the Prometheus server's address:

sudo nft add table inet prom
sudo nft 'add chain inet prom input { type filter hook input priority 0 ; policy accept ; }'
sudo nft add rule inet prom input tcp dport 9100 ip saddr != 203.0.113.5 drop
sudo nft add rule inet prom input tcp dport 9100 meta nfproto ipv6 drop

Use nft list ruleset > /etc/nftables.conf to keep the rules across reboots. If you create VMs with Ansible, Terraform or any other tool, add the exporter and the firewall rule to the same playbook or cloud-init. Every new VM is then ready to be scraped the moment it is discovered.

What happened when we added a VM

Our test used one existing VM, fairowl-sc-gc-1c-1g-20-01, which already ran node_exporter. The VMs' public addresses are blurred in the screenshots and replaced with documentation addresses (203.0.113.x) in the text. We set --discovery.refresh-interval=30s on the service and refresh_interval: 30s in Prometheus, so the timings below are faster than the 60-second defaults. Then we created a second VM with the tags web and demo:

Time (UTC)What happened
23:27:33prom-sd-demo created through the API
23:27:51It appears in /targets (18 s)
23:28:26Prometheus sees it. Its status is still created, so the keep started rule holds it back.
23:28:56The status changes to started and it becomes an active target. It shows DOWN because nothing listens on port 9100 yet.
23:30:24We install node_exporter on it, and the next scrape is UP

This is the Prometheus targets page at the DOWN step. Notice the tag_demo and tag_web labels that came from the NodeRings tags:

Prometheus Target health page. The noderings-node pool shows 1 of 2 up. fairowl-sc-gc-1c-1g-20-01 at 203.0.113.10:9100 is UP. prom-sd-demo at 203.0.113.11:9100 is DOWN with labels city Ashburn, country United States, plan SC-GC-1C-1G-20, provider Enzonix, tag_demo true and tag_web true, and the error: Get http://203.0.113.11:9100/metrics: context deadline exceeded.
The new VM was discovered with its tags before anything was installed on it. DOWN means Prometheus is trying to scrape and nothing answers yet.

Once the exporter was running, both VMs reported about 1,900 series each. We put a CPU load on the new VM to have something to look at. A query for CPU use per VM, grouped by the labels we copied, returned:

fairowl-sc-gc-1c-1g-20-01  Ashburn  SC-GC-1C-1G-20   0.72 %
prom-sd-demo               Ashburn  SC-GC-1C-1G-20  79.56 %

A Grafana dashboard for the whole fleet

The repository includes a dashboard, examples/grafana-dashboard.json. It expects the relabeling from step 2. It shows how many VMs were discovered, scraped and down, a fleet table, and CPU, memory, disk, network, load and uptime per VM. You can filter it by city and plan.

Grafana dashboard NodeRings fleet. Stats: VMs discovered 2, VMs scraped 2, VMs down 0, last discovery refresh 8.56 s, total vCPUs 2, total memory 1.74 GiB. A fleet table lists fairowl-sc-gc-1c-1g-20-01 and prom-sd-demo, both UP, in Ashburn, United States, on plan SC-GC-1C-1G-20 with provider Enzonix; prom-sd-demo has tag_demo and tag_web true. Graphs below show CPU busy near 100 percent for prom-sd-demo during the load test and near 0 for the other VM, memory used, root disk used and network traffic.
Both VMs in Grafana. prom-sd-demo appears partway through the time range because it didn't exist before.

Import it under Dashboards → New → Import and pick your Prometheus data source.

What happened when we deleted it

We deleted prom-sd-demo at 23:32:24. It left /targets at 23:32:52 and Prometheus' target list at 23:33:26, 62 seconds after the delete. Nothing was left behind to alert on, and the original VM carried on as before:

Prometheus Target health page after the delete. The noderings-node pool shows 1 of 1 up, only fairowl-sc-gc-1c-1g-20-01 at 203.0.113.10:9100. The prometheus-noderings-sd pool is also 1 of 1 up.
One minute after the delete, the target list matches the account again.

If the NodeRings API can't be reached, the service keeps serving the last list it fetched, so your targets don't disappear during an outage. Until its very first fetch succeeds, it answers 503, and Prometheus then keeps whatever targets it already had.

Game servers and DNS host names too

The same service can discover two more kinds of NodeRings resources. Turn them on with --discovery.role=vm,gameserver,dns, then pick one per scrape job with ?role=:

RoleTargetsWhat to do with them
vm (default)Each VM's public IP and a portScrape node_exporter or your app, as above
gameserverEach game server's IP and game portCheck with blackbox_exporter that every server accepts connections
dnsEvery A, AAAA and CNAME host name in your NodeRings DNS zonesCheck that each site answers over HTTPS, and see when its certificate expires

Game servers and host names don't run an exporter, so Prometheus asks blackbox_exporter to probe them instead. This job checks every web host name in zones that are delegated to NodeRings:

  - job_name: noderings-dns-https
    metrics_path: /probe
    params:
      module: [https_2xx]
    http_sd_configs:
      - url: http://127.0.0.1:10064/targets?role=dns
    relabel_configs:
      - source_labels: [__meta_noderings_dns_zone_delegated]
        regex: "true"
        action: keep
      - source_labels: [__address__]
        regex: (.+)
        target_label: __param_target
        replacement: https://$1
      - source_labels: [__meta_noderings_dns_record_fqdn]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9115

probe_success then tells you which sites are down, and probe_ssl_earliest_cert_expiry when each certificate runs out. That pairs well with the certificates from cert-manager on NodeRings DNS. The game server job is the same with ?role=gameserver and a tcp_connect module. Both are in examples/blackbox.yml. In our test account, the dns role returned the apex of our test zone with both of its A records and the zone state pending_ns, because that zone isn't delegated yet. The gameserver role returned an empty list, because the account has no game servers.

Running it properly

Get it

prometheus-noderings-sd is open source under Apache 2.0: github.com/noderings/prometheus-noderings-sd. Releases include binaries for Linux, macOS, Windows and FreeBSD, plus a multi-arch container image at ghcr.io/noderings/prometheus-noderings-sd.

It works well alongside the other NodeRings integrations: create VMs with Terraform or Pulumi, set them up with Ansible, and they appear in Prometheus a minute later.