junos-exporter
Overview
This exporter turns Junos device information into Prometheus metrics. It collects NETCONF RPC replies and parses them with pygxml, a streaming XML parser with gjson-style path queries. Everything about a metric -- which RPC to send, how to read records out of the reply, and how to expose them -- is declared in config.yml, so adding a metric never requires writing code.
To allow junos-exporter connectivity via NETCONF over SSH, ensure the following configuration is applied to your Junos devices.
set system service netconf ssh
Note: 0.2.0 introduces the following breaking changes from 0.1.0.
- Remove
general.ssh_configand stop reading~/.ssh/config; useproxy_jumpincredentialsto reach devices via a jump host.- Change
junos_upto report whether the scrape completed, and addjunos_rpc_successfor each probe. An unreachable device or a timeout now returns HTTP 200 withjunos_up 0instead of HTTP 500/504.- Remove the
/debugendpoint.
Note: 0.1.0 introduces the following breaking changes from 0.0.12.
- Change the parser from PyEZ Tables and Views to pygxml.
- Change the
config.ymlformat.- Change the scrape endpoint from
/metricsto/probe.
Installation
pip install junos-exporter
Usage
-
Write your
config.ymlThe exporter always loads the bundled
config.ymlfirst, which already defines 26 probes and thedefaultmodule. Your ownconfig.ymlis layered on top of it, so it only needs to carry what you want to change -- usually just the credentials.mkdir -p ~/.junos-exporter && cat > ~/.junos-exporter/config.yml <<'EOF' credentials: default: username: admin # Junos device login username password: admin@123 # Junos device login password EOF
The exporter looks for
./config.ymlfirst, then~/.junos-exporter/config.yml, and layers the first one it finds. -
Configure the
config.ymlAnything under
generalis overridden key by key, whilecredentials,modulesandprobesare overridden by the names directly under them -- a name that already exists in the bundled config is replaced whole.general: prefix: junos # Prefix prepended to all exported metric names timeout: 60 # Total timeout for Junos RPC execution and data collection timeout_socket: 15 # Timeout for establishing the initial NETCONF SSH connection (TCP connect and authentication) credentials: default: username: admin # Junos device login username password: admin@123 # Junos device login password
To customize a probe, copy just that probe from the bundled
config.ymlinto yours and edit it. Probes you do not copy keep following the bundled definitions as they are updated. -
Configure the Prometheus
scrape_configs: - job_name: "junos-exporter" metrics_path: /probe static_configs: - targets: - "192.168.1.1" # Target device - "192.168.1.2,192.168.1.3" # Multiple Target device such as dual RE relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] regex: '^([^,]+).*' replacement: '$1' target_label: instance - target_label: __address__ replacement: 127.0.0.1:9326
When multiple targets are provided in a comma-separated list, if the first target is unreachable, it proceeds to the next one in the sequence.
-
Run the exporter
junos-exporter
For Docker users, use the following command
docker run -d \ -p 9326:9326 \ -v /path/to/config.yml:/app/config.yml \ ghcr.io/minefuto/junos-exporter
CLI Options
The junos-exporter is powered by the uvicorn ASGI server. You can customize the server's behavior using the following command-line options.
usage: junos-exporter [-h] [--host HOST] [--log-level {critical,error,warning,info,debug,trace}]
[--no-access-log] [--port PORT] [--reload] [--root-path ROOT_PATH] [--version]
[--workers WORKERS]
options:
-h, --help Show this help message and exit
--host HOST Listen address [default: 0.0.0.0]
--log-level Log level [default: info]
--no-access-log Disable access log
--port PORT Listen port [default: 9326]
--reload Enable auto reload
--root-path ROOT_PATH
Root path [default: ""]
--version Show version number and exit
--workers WORKERS Number of worker processes [default: 1]
Credentials
This exporter allows you to configure specific authentication methods for each Junos device. To select a profile defined in the credentials section of your config.yml, add the credential query parameter to the scrape URL.
e.g. http://localhost:9326/probe?credential=vjunos&target=192.168.10.12
credentials:
default: # password authentication
username: admin
password: admin@123
vjunos: # public key authentication
username: admin
private_key: ~/.ssh/id_rsa
private_key_passphrase: admin@123 # option
via_bastion: # through a jump host
username: admin
password: admin@123
proxy_jump:
host: bastion.example.com
port: 22 # option
credential: bastion # credential used to log in to the jump host
bastion:
username: jump
private_key: ~/.ssh/id_rsa
In your Prometheus configuration, setting __params_credential to vjunos ensures the corresponding credentials are used.
If the credential parameter is omitted, the default profile will be used.
scrape_configs:
- job_name: "junos-exporter"
metrics_path: /probe
static_configs:
- targets:
- "192.168.1.1" # Target device using "default" credential
- targets:
- "192.168.1.2" # Target device using "vjunos" credential
labels:
__params_credential: "vjunos"
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9326
Metrics
Scrape status
Every scrape exposes two status metrics next to the collected ones.
# HELP junos_up Target was reachable and the scrape completed
# TYPE junos_up gauge
junos_up{} 1
# HELP junos_rpc_success RPC for the probe succeeded
# TYPE junos_rpc_success gauge
junos_rpc_success{probe="vrrp_status"} 1
They split the two kinds of failure apart, so an alert points at the right side:
up == 0-- the exporter is at fault: an undefinedmoduleorcredential, a reply it cannot interpret, or a probe definition that fails to parse. The exporter answers with HTTP 500 and Prometheus records the scrape as failedjunos_up == 0-- the device is at fault: unreachable, or the connection died before the scrape finished. Nojunos_rpc_successis exposed in this casejunos_rpc_success == 0-- the device gave no usable answer to that one RPC: anrpc-error, which also happens when a platform does not support it, or a reply the exporter could not read back. The rest of the scrape is unaffected, and the exporter log reports the reason
Selecting a module
This exporter allows you to configure which metrics are scraped for each Junos device.
To use a specific profile defined in the modules section of your config.yml, add the module query parameter to the scrape URL.
e.g. http://localhost:9326/probe?module=router&target=192.168.10.12
In your Prometheus configuration, setting __params_module to router ensures the corresponding modules are used.
If the module parameter is omitted, the default profile will be used.
Bundled probes
The bundled config.yml defines 25 probes covering alarms, chassis, interfaces, LLDP/LACP, routing, ARP, OSPF, BGP, VRRP, BFD, LDP, RSVP and MPLS LSPs -- all of them in the default module. They are always loaded, so your own config.yml only needs to list the ones you want to change.
| probe | rpc | command |
|---|---|---|
system_alarm_status |
get-system-alarm-information |
show system alarms |
chassis_alarm_status |
get-alarm-information |
show chassis alarms |
fpc_status |
get-fpc-information |
show chassis fpc |
hardware_status |
get-chassis-inventory |
show chassis hardware |
environment_status |
get-environment-information |
show chassis environment |
control_board_status |
get-environment-cb-information |
show chassis environment cb |
routing_engine_status |
get-route-engine-information |
show chassis routing-engine |
storage_status |
get-system-storage |
show system storage |
physical_interface_status |
get-interface-information |
show interfaces extensive |
logical_interface_status |
get-interface-information |
show interfaces detail |
interface_optic_status |
get-interface-optics-diagnostics-information |
show interfaces diagnostics optics |
lldp_status |
get-lldp-neighbors-information |
show lldp neighbors |
lacp_status |
get-lacp-interface-information |
show lacp interfaces |
route_summary_status |
get-route-summary-information |
show route summary |
arp_status |
get-arp-table-information |
show arp expiration-time |
ospf_interface_status |
get-ospf-interface-information |
show ospf interface detail |
ospf_neighbor_status |
get-ospf-neighbor-information |
show ospf neighbor extensive |
bgp_status |
get-bgp-summary-information |
show bgp summary |
bgp_route_status |
get-bgp-summary-information |
show bgp summary |
vrrp_status |
get-vrrp-information |
show vrrp extensive |
bfd_status |
get-bfd-session-information |
show bfd session |
ldp_neighbor_status |
get-ldp-neighbor-information |
show ldp neighbor detail |
rsvp_interface_status |
get-rsvp-interface-information |
show rsvp interface |
rsvp_neighbor_status |
get-rsvp-neighbor-information |
show rsvp neighbor detail |
mpls_lsp_status |
get-mpls-lsp-information |
show mpls lsp ingress detail |
mpls_lsp_path_status |
get-mpls-lsp-information |
show mpls lsp ingress detail |
Defining a probe
A probe is one RPC plus the rules for reading its reply. The reply XML is scanned into records (a flat path -> value mapping), and each record becomes one metric sample.
Records are cut out of the reply like this:
- Each element matching
containeris a starting point, anditemmarks where a record begins. Junos often emits records without a wrapping element, so a record is not necessarily the subtree of theitemelement. - Every
pathwritten inmetricsandlabelsis looked up in three places and the first hit wins: (a) inside theitemelement, (b) among the siblings that follow it, up to the nextitem, (c) among the ancestor's children that appeared before thatitem-- which is how a parent's values are inherited by its records. - A path that resolves nowhere is simply left out of the record, and the metric or label using it is not exposed for that record.
For example, show vrrp extensive returns each VR as a vrrp-vlan element followed by loose siblings, and the second VR reports its mode under active-inherit instead:
<vrrp-information>
<vrrp-interface>
<vrrp-vlan>
<physical-interface>xe-0/0/0</physical-interface>
<unit>1</unit>
</vrrp-vlan>
<interface-state>up</interface-state>
<group>10</group>
<vrrp-state>master</vrrp-state>
<vrrp-mode>active</vrrp-mode>
<vrrp-vlan>
<physical-interface>xe-0/0/0</physical-interface>
<unit>2</unit>
</vrrp-vlan>
<interface-state>up</interface-state>
<group>20</group>
<vrrp-state>master</vrrp-state>
<active-inherit>
<vrrp-mode>inherit</vrrp-mode>
</active-inherit>
</vrrp-interface>
</vrrp-information>
The bundled vrrp_status probe reads it as follows. physical-interface and unit are found by rule (a), the rest by rule (b), and the mode label lists two paths so that the second record falls back to the nested one.
probes:
vrrp_status:
rpc: get-vrrp-information
args:
extensive: True
container: vrrp-interface
item: vrrp-vlan
metrics:
- name: vrrp_state
path: vrrp-state
type: gauge
help: "VR State of show vrrp extensive(master: 5, backup: 4, transition: 3, bringup: 2, init: 1, idle: 0)"
value_transform:
"master": 5
"backup": 4
"transition": 3
"bringup": 2
"init": 1
"idle": 0
labels:
- name: interface
path: physical-interface
- name: unit
path: unit
- name: mode
path:
- vrrp-mode
- active-inherit.vrrp-mode
- name: group
path: group
Which is exposed as:
# HELP junos_vrrp_state VR State of show vrrp extensive(master: 5, backup: 4, transition: 3, bringup: 2, init: 1, idle: 0)
# TYPE junos_vrrp_state gauge
junos_vrrp_state{interface="xe-0/0/0",unit="1",mode="active",group="10"} 5.0
junos_vrrp_state{interface="xe-0/0/0",unit="2",mode="inherit",group="20"} 5.0
probes
| key | type | default | description |
|---|---|---|---|
rpc |
str | required | RPC name, sent as <rpc-name format="xml-minified"> |
args |
dict | {} |
RPC arguments. _ in a key becomes -. A value of true emits an empty element, anything else emits <key>value</key> |
container |
str | "" |
Path to the parent of the records, . separated and relative to the child level of the reply root. Every match is used |
item |
str | list[str] | required | Element name that begins a record |
recursive |
bool | false |
Also look for item further down the tree, for replies nested to an arbitrary depth such as show chassis hardware |
metrics |
list | [] |
Metric definitions, see below |
labels |
list | [] |
Label definitions applied to every metric of the probe, see below |
paths
Both metrics and labels read their value through a path relative to the record, which takes one of these forms:
- name: peer_state
path: peer-state # child element
- name: input_bytes
path: traffic-statistics.input-bytes # nested element
- name: config_flags
path: if-config-flags.@flag # attribute
- name: mode
path: # first path that resolves wins
- vrrp-mode
- active-inherit.vrrp-mode
- name: iff_up
path: if-config-flags.iff-up # presence instead of value
exists: True
- name: lsp
path: ^name # inherited from ancestors only
A path prefixed with ^ skips (a) and (b) and is looked up only in (c). Use it when the item element has a child of the same name as the parent's, e.g. mpls-lsp-path carrying its own name under mpls-lsp.
A path with exists: True yields the string "true" or "false" rather than the element value, so it always resolves. It cannot be combined with a list of paths.
metrics
| key | type | default | description |
|---|---|---|---|
name |
str | required | Exposed as <prefix>_<name>, with _total appended when type is counter |
path |
str | list[str] | required unless value |
Path to the value, see above |
value |
float | required unless path |
Constant to expose instead of reading the reply |
exists |
bool | false |
Expose whether path resolved, as "true" or "false" |
type |
str | untyped |
untyped, counter or gauge |
help |
str | "" |
Text of the HELP line |
regex |
str | none | Applied to the value. Capture group 1 is used if present, otherwise the whole match. A value that does not match is dropped |
value_transform |
dict | none | Maps a string value to a number. The _ key sets a default, otherwise an unlisted value becomes NaN |
to_unixtime |
bool | false |
Reads the value as YYYY-MM-DD HH:MM:SS, <w>w<d>d HH:MM:SS, <d>d HH:MM:SS or HH:MM:SS and converts it to unix time in milliseconds. Anything else becomes 0 |
labels
| key | type | default | description |
|---|---|---|---|
name |
str | required | Label name |
path |
str | list[str] | required | Path to the label value, see above |
exists |
bool | false |
Expose whether path resolved, as "true" or "false" |
regex |
str | none | Applied to the label value. Capture group 1 is used, and the label is omitted when it does not match |
A label whose path is missing from the record is omitted. Splitting xe-0/0/0.1 into a physical interface and a unit:
labels:
- name: interface
path: name
regex: ([^\.]*).*
- name: unit
path: name
regex: .*\.(\d+)
Checking a probe definition
Get the RPC reply from the device itself to work out what to write.
# The RPC name to put in `rpc:`
show vrrp extensive | display xml rpc
# The reply XML, to work out container / item / path
show vrrp extensive | display xml
Query
/query runs the RPCs defined under queries in the config and returns the extracted fields as JSON. RPC arguments declared in the definition can be overridden per request with args[<name>]=<value>. params renames an argument for requests ({request name: args key}); a renamed argument is accepted only by its new name.
queries:
physical_interface_status:
rpc: get-interface-information
args:
extensive: True
interface_name: null # required in the request
params:
interface: interface_name
item: physical-interface
fields:
- name: interface
path: name
- name: oper_status
path: oper-status
curl -g 'localhost:9326/query?target=192.168.1.1&queries=physical_interface_status&args[interface]=xe-0/0/0'
{
"target": "192.168.1.1",
"collected_at": "2026-10-05T12:34:56+09:00",
"queries": {
"physical_interface_status": [{"interface": "xe-0/0/0", "oper_status": "up"}]
}
}
Bundled queries
The bundled config.yml defines one query per bundled probe, with the same name, plus route_status, bgp_advertised_route_status and bgp_received_route_status (one record per route path), returning values as raw strings (e.g. "Established" instead of 5). Field names follow the same naming rules as probe labels: the same value has the same name in every query and probe (interface, unit, address, instance, state, ...), and an arg has the same name as the field it filters, so a returned value can be passed straight to another query's args. bgp_status and bgp_route_status are read from show bgp neighbor, so they cover peers in every routing instance.
| query | args |
|---|---|
fpc_status, control_board_status, routing_engine_status |
slot |
physical_interface_status, logical_interface_status |
interface (default [afgxe][et]-*) |
interface_optics_status |
interface (default [efgx][et]-*) |
lacp_status, arp_status |
interface |
route_summary_status |
table |
route_status (show route extensive) |
destination, table, protocol |
bgp_advertised_route_status, bgp_received_route_status |
address (required), table, destination |
ospf_interface_status, ospf_neighbor_status, rsvp_interface_status |
interface, instance |
bgp_status, bgp_route_status, ldp_neighbor_status |
address, instance |
bfd_status |
address |
rsvp_neighbor_status |
instance |
mpls_lsp_status, mpls_lsp_path_status |
name, regex, instance |
| others | none |
Args without a default are optional. An arg applies to every requested query that declares it:
curl -g 'localhost:9326/query?target=192.168.1.1&queries=bgp_status,ospf_neighbor_status&args[instance]=VRF-A'
License
MIT
Metadata
Release files for junos-exporter 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| junos_exporter-0.2.0.tar.gz | 54.4 kB | Without provenance | Details for junos_exporter-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| junos_exporter-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for junos_exporter-0.2.0-py3-none-any.whl |
Total release size: 83.9 kB
Release files / junos_exporter-0.2.0.tar.gz
| Download URL | junos_exporter-0.2.0.tar.gz |
|---|---|
| Size | 54.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d5709e7e31d29da9641cb27ebf53d89bd28a0863a6f4f30fc9cdf5c230ad8c40
|
|
BLAKE2b-256 checksum How to use checksums |
9df3c849e390032c26593403cc3da4fdab254b563c09eac82912be9ecb3153ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / junos_exporter-0.2.0-py3-none-any.whl
| Download URL | junos_exporter-0.2.0-py3-none-any.whl |
|---|---|
| Size | 29.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
01ad6ef1b91115b6abfc4fdb9dcf42201e8b0d2155f84e9c88bbea15b43881f1
|
|
BLAKE2b-256 checksum How to use checksums |
25b2c70e5f6f5bc37ce53d8c20d77b9a0a964f09ec434557f6f60772e635e36c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for junos-exporter 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.