Skip to content
プロジェクト

AthennaMind/opnsense-exporter

GitHubで見る

概要

OPNsense Exporter for Prometheus

システム・インフラ

この数値の測り方

計測したスター増加

24時間
0
7日間
+1
15日間
+2
1か月
履歴を収集中

期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。

OPNsense Prometheus Exporter

The missing OPNsense exporter for Prometheus

GitHub License GitHub Actions Workflow Status GitHub go.mod Go version (branch)

Table of Contents

About

Focusing specifically on OPNsense, this exporter provides metrics about OPNsense, the plugin ecosystem and the services running on the firewall. However, it's recommended to use it with node_exporter. You can combine the metrics from both exporters in Grafana and in your Alert System to create a dashboard that displays the full picture of your system.

While the node_exporter must be installed on the firewall itself, this exporter can be installed on any machine that has network access to the OPNsense API.

Grafana Dashboard

OPNsense Exporter Dashboard

gateways

Finaly we have a Grafana dashboard to visualize the data from this exporter. The dashboard can be imported into Grafana by using the id 21113 or by importing the deploy/grafana/dashboard-v1.json file. Please give a review to the dashboard if you like our work. Thank you!

OPNsense user permissions

Type Name
GUI Diagnostics: ARP Table
GUI Diagnostics: Firewall statistics
GUI Diagnostics: Netstat
GUI Reporting: Traffic
GUI Services: Unbound (MVC)
GUI Status: DHCP leases
GUI Status: DNS Overview
GUI Status: IPsec
GUI Status: OpenVPN
GUI Status: Services
GUI System: Firmware
GUI System: Gateways
GUI System: Settings: Cron
GUI System: Status
GUI VPN: OpenVPN: Instances
GUI VPN: WireGuard
GUI Services: DHCP: Kea(v4)
GUI Services: DHCP: Kea(v6)
GUI Interfaces: Virtual IPs: Status
GUI Lobby: Dashboard

Note: The temperature collector calls api/diagnostics/system/system_temperature, which OPNsense covers with the Lobby: Dashboard privilege (page-system-login-logout in the core ACL). A least-privilege API user needs that privilege or the collector returns 403; alternatively disable it with --exporter.disable-temperature. The URL must be the snake_case form: OPNsense matches the request URI literally against its ACL patterns, so the camelCase systemTemperature spelling is rejected for every non-admin user regardless of privileges. Boxes without thermal sensors (most VMs) and releases without the endpoint report no temperature metrics and no errors.

Note: The CARP collector calls api/diagnostics/interface/get_vip_status, which requires the Interfaces: Virtual IPs: Status privilege. Without it the collector logs a 403 on every scrape. Grant the privilege or disable the collector with --exporter.disable-carp.

Note: The memory, swap, disk and system collectors read the same API the OPNsense dashboard widgets use, so they need Lobby: Dashboard too. Their endpoints are api/diagnostics/system/system_resources, system_swap, system_disk and system_time. Disk metrics need OPNsense 26.7.5 or newer. Disable each collector with --exporter.disable-memory, --exporter.disable-swap, --exporter.disable-disk and --exporter.disable-system.

Note: PF state usage and mbuf cluster usage require Lobby: Dashboard. Their endpoints are api/diagnostics/firewall/pf_states and api/diagnostics/system/system_mbuf. Disable them independently with --exporter.disable-pf-states and --exporter.disable-mbuf. Existing firewall packet metrics keep their separate --exporter.disable-firewall switch.

OPNsense settings

The exporter requires that the following OPNsense settings be enabled:

  • Unbound collector:
    • Unbound DNS > Advanced > Extended Statistics

Usage

Docker

The following command will start the exporter and expose the metrics on port 8080. Replace ops.example.com, your-api-key, your-api-secret and instance1 with your own values.

docker run -p 8080:8080 ghcr.io/athennamind/opnsense-exporter:latest \
      /opnsense-exporter \
      --log.level=debug \
      --log.format=json \
      --opnsense.protocol=https \
      --opnsense.address=ops.example.com \
      --opnsense.api-key=your-api-key \
      --opnsense.api-secret=your-api-secret \
      --exporter.instance-label=instance1 \
      --web.listen-address=:8080

TODO: Add example how to add custom CA certificates to the container.

Docker Compose

  • With environment variables
version: '3'
services:
  opnsense-exporter:
    image: ghcr.io/athennamind/opnsense-exporter:latest
    container_name: opensense-exporter
    restart: always
    command:
      - --opnsense.protocol=https
      - --opnsense.address=ops.example.com
      - --exporter.instance-label=instance1
      - --web.listen-address=:8080
      #- --exporter.disable-arp-table
      #- --exporter.disable-cron-table
      #- ....
    environment:
      OPNSENSE_EXPORTER_OPS_API_KEY: "<your-key>"
      OPNSENSE_EXPORTER_OPS_API_SECRET: "<your-secret>"
    ports:
      - "8080:8080"
  • With docker secrets

Create the secrets

echo "<your-key>" | docker secret create opnsense-api-key -
echo "<your-secret>" | docker secret create opnsense-api-secret -

Run the compose

version: '3'
services:
  opnsense-exporter:
    image: ghcr.io/athennamind/opnsense-exporter:latest
    container_name: opensense-exporter
    restart: always
    command:
      - --opnsense.protocol=https
      - --opnsense.address=ops.example.com
      - --exporter.instance-label=instance1
      - --web.listen-address=:8080
      #- --exporter.disable-arp-table
      #- --exporter.disable-cron-table
      #- ....
    environment:
      OPS_API_KEY_FILE: /run/secrets/opnsense-api-key
      OPS_API_SECRET_FILE: /run/secrets/opnsense-api-secret
    secrets:
      - opnsense-api-key
      - opnsense-api-secret
    ports:
      - "8080:8080"

Systemd

TODO

Configuration

The configuration of this tool is following the standard alongside the Prometheus ecosystem. This exporter can be configured using command-line flags or environment variables.

OPNsense API

To configure where the connection to OPNsense is, use the following flags:

  • --opnsense.protocol - The protocol to use to connect to the OPNsense API. Can be either http or https.
  • --opnsense.address - The hostname or IP address of the OPNsense API.
  • --opnsense.api-key - The API key to use to connect to the OPNsense API.
  • --opnsense.api-secret - The API secret to use to connect to the OPNsense API
  • --opnsense.max-concurrent-requests - Maximum number of API requests in flight at the same time. Defaults to 5.
  • --exporter.instance-label - Label to use to identify the instance in every metric. If you have multiple instances of the exporter, you can differentiate them by using different value in this flag, that represents the instance of the target OPNsense. You must not start more then 1 instance of the exporter with the same value in this flag.

A scrape makes about 25 API calls. The exporter sends at most --opnsense.max-concurrent-requests of them at once. The lighttpd in front of the OPNsense API allows 8 HTTP/2 streams per connection and closes idle connections after 30 seconds. With the default of 5, every scrape fits in one connection, so a scrape after a normal scrape interval opens one new connection instead of several. It also keeps the PHP load on the firewall low. Values above 8 make every scrape open extra connections.

If --opnsense.address resolves to several IP addresses, make sure all of them are reachable from the exporter. Each new connection tries them one by one and waits up to 2 seconds on an address that does not answer.

SSL/TLS

For self-signed certificates, the CA certificate must be added to the system trust store.

If you want to disable TLS certificate verification, you can use the following flag:

  • --opnsense.insecure - Disable TLS certificate verification. Defaults to false.

Exporters

Gathering metrics for specific subsystems can be disabled with the following flags:

  • --exporter.disable-arp-table - Disable the scraping of ARP table. Defaults to false.
  • --exporter.disable-cron-table - Disable the scraping of Cron tasks. Defaults to false.
  • --exporter.disable-wireguard - Disable the scraping of Wireguard service. Defaults to false.
  • --exporter.disable-unbound - Disable the scraping of Unbound service. Defaults to false.
  • --exporter.disable-openvpn - Disable the scraping of OpenVPN service. Defaults to false.
  • --exporter.disable-ipsec - Disable the scraping of IPsec service. Defaults to false.
  • --exporter.disable-firewall - Disable the scraping of Firewall (pf) metrics. Defaults to false.
  • --exporter.disable-firmware - Disable the scraping of Firmware infos. Defaults to false.
  • --exporter.disable-kea-dhcpv4 - Disable the scraping of Kea DHCPv4 leases. Defaults to false.
  • --exporter.disable-kea-dhcpv6 - Disable the scraping of Kea DHCPv6 leases. Defaults to false.
  • --exporter.disable-temperature - Disable the scraping of temperature sensors. Defaults to false.
  • --exporter.disable-carp - Disable the scraping of the CARP VIP status. Defaults to false.
  • --exporter.disable-pf-states - Disable PF state table usage metrics. Defaults to false.
  • --exporter.disable-mbuf - Disable mbuf cluster usage metrics. Defaults to false.
  • --exporter.disable-memory - Disable memory usage metrics. Defaults to false.
  • --exporter.disable-swap - Disable swap usage metrics. Defaults to false.
  • --exporter.disable-disk - Disable filesystem usage metrics. Defaults to false.
  • --exporter.disable-system - Disable uptime and load average metrics. Defaults to false.

To disable the exporter metrics itself use the following flag:

  • --web.disable-exporter-metrics - Exclude metrics about the exporter itself (promhttp_*, process_*, go_*). Defaults to false.

All Options

Flags:
  -h, --[no-]help                Show context-sensitive help (also try --help-long and --help-man).
      --[no-]exporter.disable-arp-table
                                 Disable the scraping of the ARP table ($OPNSENSE_EXPORTER_DISABLE_ARP_TABLE)
      --[no-]exporter.disable-cron-table
                                 Disable the scraping of the cron table ($OPNSENSE_EXPORTER_DISABLE_CRON_TABLE)
      --[no-]exporter.disable-wireguard
                                 Disable the scraping of Wireguard service ($OPNSENSE_EXPORTER_DISABLE_WIREGUARD)
      --[no-]exporter.disable-unbound
                                 Disable the scraping of Unbound service ($OPNSENSE_EXPORTER_DISABLE_UNBOUND)
      --[no-]exporter.disable-openvpn
                                 Disable the scraping of OpenVPN service ($OPNSENSE_EXPORTER_DISABLE_OPENVPN)
      --[no-]exporter.disable-ipsec
                                 Disable the scraping of IPsec service ($OPNSENSE_EXPORTER_DISABLE_IPSEC)
      --[no-]exporter.disable-firewall
                                 Disable the scraping of the firewall (pf) metrics ($OPNSENSE_EXPORTER_DISABLE_FIREWALL)
      --[no-]exporter.disable-firmware
                                 Disable the scraping of the firmware metrics ($OPNSENSE_EXPORTER_DISABLE_FIRMWARE)
      --[no-]exporter.disable-kea-dhcpv4  
                                 Disable the scraping of Kea DHCPv4 leases ($OPNSENSE_EXPORTER_DISABLE_KEADHCPV4)
      --[no-]exporter.disable-kea-dhcpv6  
                                 Disable the scraping of Kea DHCPv6 leases ($OPNSENSE_EXPORTER_DISABLE_KEADHCPV6)
      --[no-]exporter.disable-temperature
                                 Disable the scraping of the temperature sensors ($OPNSENSE_EXPORTER_DISABLE_TEMPERATURE)
      --[no-]exporter.disable-carp
                                 Disable the scraping of the CARP VIP status ($OPNSENSE_EXPORTER_DISABLE_CARP)
      --[no-]exporter.disable-pf-states
                                 Disable PF state table usage metrics ($OPNSENSE_EXPORTER_DISABLE_PF_STATES)
      --[no-]exporter.disable-mbuf
                                 Disable mbuf cluster usage metrics ($OPNSENSE_EXPORTER_DISABLE_MBUF)
      --[no-]exporter.disable-memory
                                 Disable memory usage metrics ($OPNSENSE_EXPORTER_DISABLE_MEMORY)
      --[no-]exporter.disable-swap
                                 Disable swap usage metrics ($OPNSENSE_EXPORTER_DISABLE_SWAP)
      --[no-]exporter.disable-disk
                                 Disable filesystem usage metrics ($OPNSENSE_EXPORTER_DISABLE_DISK)
      --[no-]exporter.disable-system
                                 Disable uptime and load average metrics ($OPNSENSE_EXPORTER_DISABLE_SYSTEM)
      --web.telemetry-path="/metrics"
                                 Path under which to expose metrics.
      --[no-]web.disable-exporter-metrics
                                 Exclude metrics about the exporter itself (promhttp_*, process_*, go_*).
                                 ($OPNSENSE_EXPORTER_DISABLE_EXPORTER_METRICS)
      --runtime.gomaxprocs=2     The target number of CPUs that the Go runtime will run on (GOMAXPROCS) ($GOMAXPROCS)
      --exporter.instance-label=EXPORTER.INSTANCE-LABEL
                                 Label to use to identify the instance in every metric. If you have multiple instances of the
                                 exporter, you can differentiate them by using different value in this flag, that represents
                                 the instance of the target OPNsense. ($OPNSENSE_EXPORTER_INSTANCE_LABEL)
      --[no-]web.systemd-socket  Use systemd socket activation listeners instead of port listeners (Linux only).
      --web.listen-address=:8080 ...
                                 Addresses on which to expose metrics and web interface. Repeatable for multiple addresses.
                                 Examples: `:9100` or `[::1]:9100` for http, `vsock://:9100` for vsock
      --web.config.file=""       Path to configuration file that can enable TLS or authentication. See:
                                 https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md
      --opnsense.protocol=OPNSENSE.PROTOCOL
                                 Protocol to use to connect to OPNsense API. One of: [http, https]
                                 ($OPNSENSE_EXPORTER_OPS_PROTOCOL)
      --opnsense.address=OPNSENSE.ADDRESS
                                 Hostname or IP address of OPNsense API ($OPNSENSE_EXPORTER_OPS_API)
      --opnsense.api-key=""      API key to use to connect to OPNsense API. This flag/ENV or the OPS_API_KEY_FILE my be set.
                                 ($OPNSENSE_EXPORTER_OPS_API_KEY)
      --opnsense.api-secret=""   API secret to use to connect to OPNsense API. This flag/ENV or the OPS_API_SECRET_FILE my be
                                 set. ($OPNSENSE_EXPORTER_OPS_API_SECRET)
      --[no-]opnsense.insecure   Disable TLS certificate verification ($OPNSENSE_EXPORTER_OPS_INSECURE)
      --opnsense.max-concurrent-requests=5
                                 Maximum number of OPNsense API requests in flight at the same time. OPNsense allows 8
                                 HTTP/2 streams per connection, so values above 8 open extra connections on every scrape
                                 ($OPNSENSE_EXPORTER_OPS_MAX_CONCURRENT_REQUESTS)
      --log.level=info           Only log messages with the given severity or above. One of: [debug, info, warn, error]
      --log.format=logfmt        Output format of log messages. One of: [logfmt, json]

関連プロジェクトを探す

読み込み中…