Skip to main content

Prometheus Exporter for Junos using PyEZ Tables and Views

Project description

junos-exporter

PyPI - Python Version PyPI GitHub

Overview

This is a Prometheus Exporter for Junos using PyEZ(Juniper/py-junos-eznc) Tables and Views.
PyEZ can extract information from Junos operational command output and map it to a Python data structure via yaml.
junos-exporter converts the information provided by PyEZ into the Prometheus metrics format via yaml.
So, this exporter's metrics can be flexibly configured by simply editing yaml.

Install

pip install junos-exporter

Usage

Docker(Recommended)

Download config.yml

curl -sO https://raw.githubusercontent.com/minefuto/junos-exporter/refs/heads/main/config.yml

Edit config.yml

general:
  prefix: junos  # prefix of the metrics
  timeout: 60  # request timeout of exporter

credentials:
  vjunos: # credential name
    username: admin  # junos device's username
    password: admin@123  # junos device's password

Edit prometheus config

scrape_configs:
  - job_name: "junos-exporter"
    static_configs:
      - targets:
          - "192.168.1.1"  # target device
          - "192.168.1.2"
        labels:
          __meta_credential: "vjunos"  # credential name
          __meta_module: "router"
    relabel_configs:
      - source_labels: [__meta_credential]
        target_label: __param_credential
      - source_labels: [__meta_module]
        target_label: __param_module
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9326

Run junos-exporter

docker run -v config.yml:/app/config.yml ghcr.io/minefuto/junos-exporter
Pip

Download config.yml

curl -s -o ~/.junos-exporter/config.yml --create-dirs https://raw.githubusercontent.com/minefuto/junos-exporter/refs/heads/main/config.yml

Edit config.yml

general:
  prefix: junos  # prefix of the metrics
  timeout: 60  # request timeout of exporter

credentials:
  vjunos: # credential name
    username: admin  # junos device's username
    password: admin@123  # junos device's password

Download op/tables.yml

curl -s -o ~/.junos-exporter/op/tables.yml --create-dirs https://raw.githubusercontent.com/minefuto/junos-exporter/refs/heads/main/op/tables.yml

Edit prometheus config

scrape_configs:
  - job_name: "junos-exporter"
    static_configs:
      - targets:
          - "192.168.1.1"  # target device
          - "192.168.1.2"
        labels:
          __meta_credential: "vjunos"  # credential name
          __meta_module: "router"
    relabel_configs:
      - source_labels: [__meta_credential]
        target_label: __param_credential
      - source_labels: [__meta_module]
        target_label: __param_module
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9326

Run junos-exporter

junos-exporter

Options

junos-exporter has some uvicorn options and change listen address/port 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] [--workers WORKERS]

options:
  -h, --help            show this help message and exit
  --host HOST           listen address[default: 0.0.0.0]
  --log-level {critical,error,warning,info,debug,trace}
                        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: ""]
  --workers WORKERS     number of worker processes[default: 1]

Build your own metrics

Please see the config.yml and op/tables.yml for configuration example.

1. Create parse rule for junos output

Create PyEZ config file and put the yaml or textfsm in the following directory.

  • pyez structured & unstructured tables and views configuration file
    • docker: /app/op/
    • pip: ~/.junos-exporter/op/
  • textfsm template file
    • docker: /app/textfsm/
    • pip: ~/.junos-exporter/textfsm/

How to configure PyEZ Tables and Views:

2. Create metrics convert rule

Edit optables section in config.yml.

optables:
  PhysicalInterfaceStatus:  # pyez table name
    metrics:
      - name: interface_speed  # metrics name
        value: speed  # metrics value
        type: gauge  # metrics type(gauge or count or untyped)
        help: Speed of show interfaces extensive  # metrics help
        value_transform:  #(optional) if metrics value is str, can be transformed to float
          100mbps: 100000000
          1000mbps: 1000000000
          1Gbps: 1000000000
          10Gbps: 10000000000
          100Gbps: 100000000000
          _: 0  #(optional) value_transform's fallback value(default: NaN)
      - name: interface_lastflap_seconds
        value: interface_flapped
        type: counter
        help: Last flapped of show interfaces extensive
        to_unixtime: True  # transform to unixtime for timestamp/uptime  e.g. 2025-03-22 12:57:10, 10w3d 11:11:11
-snip-
    labels:
      - name: interface  #(optional) label name
        value: name  # label value
        regex: ([^\.]*).*  #(optional) label values can be extracted by using regexp
      - name: unit
        value: name
        regex: .*\.(\d+)
      - name: description
        value: description

metrics/label value select from fields key of PyEZ View(e.g. oper_status, admin_status).

  • tables.yml
  PhysicalInterfaceStatusView:
    groups:
      traffic_statistics: traffic-statistics
      input_error_list: input-error-list
      output_error_list: output-error-list
      ethernet_pcs_statistics: ethernet-pcs-statistics
    fields: <- !!
      oper_status: oper-status
      admin_status: admin-status
      description: description
      speed: speed
      mtu: mtu
      link_mode: link-mode
      interface_flapped: interface-flapped
-snip-
  • config.yml
PhysicalInterfaceStatus:
    metrics:
      - name: interface_admin_status
        value: admin_status <- !!
        type: gauge
        help: "Admin status of show interfaces extensive(Up: 2, Down: 1)"
        value_transform:
          up: 2
          down: 1
      - name: interface_oper_status
        value: oper_status <- !!
        type: gauge
        help: "Oper status of show interfaces extensive(Up: 2, Down: 1)"
        value_transform:
          up: 2
          down: 1

PyEZ Table's key is automatically mapping to key and name for metrics/label value.

  • tables.yml
RoutingEngineStatus:
  rpc: get-route-engine-information
  item: route-engine
  key: slot <- !!
  view: RoutingEngineStatusView
  • config.yml
  RoutingEngineStatus:
    metrics:
-snip-
    labels:
      - name: slot
        value: key <- !!

If there are multiple keys, a number is assigned at the end such as key.0, key.1.

  • tables.yml
LldpStatus:
  rpc: get-lldp-neighbors-information
  item: lldp-neighbor-information
  key:
    - lldp-local-port-id <- key.0, name.0
    - lldp-remote-port-id <- key.1, name.1
  view: LldpStatusView
  • config.yml
  LldpStatus:
    metrics:
      - name: lldp_neighbor_info
        value: 1
        type: gauge
        help: Information of show lldp neighbor
    labels:
      - name: remote
        value: remote_system_name
      - name: interface
        value: key.0 <- !!
      - name: remote_interface
        value: key.1 <- !!

The metrics value can be a static value.

  • config.yml
  HardwareStatus:
    metrics:
      - name: hardware_info
        value: 1 <- !!
        type: gauge
        help: Infomation of show chassis hardware

3. Create modules

Edit modules section in config.yml.

modules:
  test:  # module name
    tables:  # add created optables
      - SystemAlarmStatus
      - ChassisAlarmStatus
      - FpcStatus
-snip-

Edit prometheus config

scrape_configs:
  - job_name: "junos-exporter"
    static_configs:
      - targets:
          - "192.168.1.1"  # target device
          - "192.168.1.2"
        labels:
          __meta_credential: "vjunos"  # credential name
          __meta_module: "test"  # module name
    relabel_configs:
      - source_labels: [__meta_credential]
        target_label: __param_credential
      - source_labels: [__meta_module]
        target_label: __param_module
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 127.0.0.1:9326

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

junos_exporter-0.0.8.tar.gz (55.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

junos_exporter-0.0.8-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file junos_exporter-0.0.8.tar.gz.

File metadata

  • Download URL: junos_exporter-0.0.8.tar.gz
  • Upload date:
  • Size: 55.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.17

File hashes

Hashes for junos_exporter-0.0.8.tar.gz
Algorithm Hash digest
SHA256 b28469c631ade7658c46395782bd31f3bba2a04cc9a05e5ab6f4fb02d471df14
MD5 21cd619036233c3e4f687b4a8c6c464a
BLAKE2b-256 a5c88d958a1a0cb4c032506721d843962c9cfe68d7704ce8bcf71e050aff5224

See more details on using hashes here.

File details

Details for the file junos_exporter-0.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for junos_exporter-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 514182259e13207a719953e7bf7b9a01f14114a0b6508383788688b903b48786
MD5 f0c85bc094886be5ba1af62e764d67b9
BLAKE2b-256 966ae2dbb000f632eb494166a232e2a89afde79a85082efd6682a5a5c506622b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page