- Go 91%
- Python 9%
gocoax-exporter #
A Prometheus exporter for the goCoax MA2500D MoCA 2.5 Ethernet bridge. It scrapes the bridge's embedded web interface and exposes topology, link, PHY-rate, RF, and Ethernet counter metrics.
LLM / "AI" #
This exporter has been vibecoded heavily. The human in the loop took great care to achieve high confidence in what this exporter does and does not do. It was especially important to me to make the test cases clear and trustworthy.
One concern was that the exporter has to have admin rights on the device and to make sure that no HTTP request has any side-effect on the device (i.e. configuration change).
I read the code. Warranty disclaimers apply, though.
This paragraph was written w/o the help of "AI".
How it works #
The MA2500D runs an InterNiche Technologies WebServer 2.0 on port 80 with two
layers of authentication:
- HTTP Basic Auth (default user
admin). - A rotating
csrf_tokencookie that must be echoed back as anX-CSRF-TOKENheader on every request. The token changes on (nearly) every response, so the client re-reads it before each POST.
All reads are HTTP POSTs to the device's /ms/... management service. The
device distinguishes reads from writes with a URL suffix (/GET vs /PUT) or
by the MoCA command number, so this exporter only ever calls read endpoints
and cannot change the bridge's configuration.
Build #
go build -o gocoax-exporter .
Run #
Devices are described in a config file, one per line, as name;url, where the
URL carries the credentials (and, optionally, a base path):
printf '%s\n' \
'basement;http://admin:secret@192.168.79.10' \
'attic;http://admin:secret@192.168.79.11' \
> devices.conf
./gocoax-exporter -config devices.conf
The name becomes the device label on every metric. Keep the file readable by
the exporter only (chmod 600 devices.conf), since it holds the passwords.
Config file details:
- Each line is
name;http://user:password@host[:port][/base]. The URL is parsed withnet/url, so percent-encode characters that are special in a URL (for example, a password ofp@ssis writtenp%40ss). - The scheme is honored as written: the bridges only speak HTTP, so
https://fails at the TLS handshake rather than silently downgrading. - A path in the URL is kept as the base for the management endpoints, so
http://admin:secret@host/mocacalls/moca/ms/.... - Blank lines and lines starting with
#are ignored. - Device names must be unique, and the file must define at least one device.
- Errors report the file and line, e.g.
config file devices.conf: line 3: want name;url.
| Flag | Default | Description |
|---|---|---|
-config |
(required) | Device config file, name;url per line. |
-listen-address |
:9487 |
Address to expose metrics on. |
-debug-dir |
— | If set, run a one-shot probe, write its output here, and exit. |
Then check http://localhost:9487/metrics.
The exporter imposes no scrape timeout of its own. Each device read inherits the
HTTP request's context, so when Prometheus cancels a scrape (because its
scrape_timeout elapsed or the scrape was discarded), the in-flight device
requests are cancelled with it.
Metrics #
| Metric | Type | Labels |
|---|---|---|
gocoax_up |
gauge | device |
gocoax_link_up |
gauge | device |
gocoax_device_info |
gauge (1) | device, mac_address, ip_address, chip, soc_version, moca_version, node_id, is_nc |
gocoax_moca_network_info |
gauge (1) | device, version |
gocoax_node_info |
gauge (1) | device, node, mac_address, moca_version, is_nc |
gocoax_phy_rate_nper_mbps |
gauge | device, from_node, to_node |
gocoax_phy_rate_vlper_mbps |
gauge | device, from_node, to_node |
gocoax_phy_rate_gcd_mbps |
gauge | device, node |
gocoax_ethernet_tx_good_total |
counter | device |
gocoax_ethernet_tx_bad_total |
counter | device |
gocoax_ethernet_tx_dropped_total |
counter | device |
gocoax_ethernet_rx_good_total |
counter | device |
gocoax_ethernet_rx_bad_total |
counter | device |
gocoax_ethernet_rx_dropped_total |
counter | device |
gocoax_beacon_channel_mhz |
gauge | device |
gocoax_primary_channel_mhz |
gauge | device |
gocoax_secondary_channel_mhz |
gauge | device |
gocoax_first_channel_mhz |
gauge | device |
gocoax_channel_count |
gauge | device |
gocoax_scrape_duration_seconds |
gauge | device |
The standard Go and process collectors are also registered.
Notes:
- NPER/VLPER rates are directional (
from_node→to_node) and omit the self-pair; the broadcast/multicast rate is exposed asgocoax_phy_rate_gcd_mbps. - MoCA 2.5 nodes report either NPER or VLPER depending on the
txpriorityperboot setting; the unused one is0. - The Ethernet counters are the raw 64-bit counters the device reports in its "Ethernet TX/RX" status section (they reset on reboot, which Prometheus handles as a counter reset).
Prometheus scrape config #
scrape_configs:
- job_name: gocoax
static_configs:
- targets: ['localhost:9487']
scrape_interval: 30s
scrape_timeout: 10s
The exporter has no timeout of its own; scrape_timeout is the only deadline,
and expiring it cancels the exporter's in-flight device requests.
Development #
go test ./...
Package layout:
| Package | Responsibility |
|---|---|
config |
Flag parsing, device config file, defaults. |
client |
HTTP session handling and decoding of the device's management endpoints. |
collector |
Prometheus collector translating device reads into metrics. |
exporter |
Wires collectors into the /metrics and index HTTP handlers. |
debug |
One-shot probe mode (-debug-dir). |
internal/capture |
Loads and replays captured device traffic for tests. |
main |
Configuration, process lifecycle (signals, startup, graceful shutdown). |
For the complete endpoint-to-metric mapping, including what is deliberately not
exported and why, see docs/data-inventory.md.
Capturing test data #
Tests are seeded with real device traffic captured under testdata/. To
re-capture against a live device:
python3 scripts/capture.py --config .private/gocoax-exporter.cfg --out testdata
See scripts/README.md for the capture schema and testdata/README.md for the
layout. The capture uses HTTP Basic auth and the device's CSRF cookie on the
wire but never writes them to disk.