Package: opnsense-prom-exporter
OPNSense Prometheus exporterI've configures OPNSense with High Availability settings using 2 servers.https://docs.opnsense.org/manual/hacarp.htmlhttps://docs.opnsense.org/manual/how-tos/carp.htmlSo I've 2 servers:MAINandBACKUP, in normal situationMAINserver
is expected to beactiveand theBACKUPserver to be inhot_standbystate.The initial needs was to be able to make sure thatBACKUPserver is ready (hot standby)
to get the main server role with theactivestate at any time.Unfortunately I've not found a proper configuration to call OPNSense HTTP API over
opnvpn on backup server using blackbox configuratoin. That why I've started to develop
this exporter install on a server on the LAN to be able to resquest both OPNSense servers.MetricsThis exporter gives following metrics, all metrics received following labels:instance: by default this is set with the hostname where is running this exporter servicehost: the host of the OPNSenserole:mainorbackupto determine the OPNSense server role.Enumsopnsense_main_ha_state: (deprecated) OPNSense HA state of the MAIN serveropnsense_backup_ha_state: (deprecated) OPNSense HA state of the BACKUP serveropnsense_server_ha_state: OPNSense HA state, on of following value:active: that OPNSense server is receiving traffichot_standby: the OPNSense server is ready to be promote as active servermaintenancemode: the OPNSense server was turned into maintenance modeunavailable: the OPNSense server wasn't accessible or return unexpected valueGaugesopnsense_active_server_traffic_rate: Active OPNSense server traffic rate per interfaces bits/s
add following labels:interface: the interface to export (values given using--opnsense-interfaces)metric: the metric name (as today one ofrate_bits_in,rate_bits_in)UsageNote: Most updated documentation from command line !opnsense-exporter --help
usage: opnsense-exporter [-h] [--check-frequency-seconds FREQUENCY]
                         [--main-host MAIN] [--backup-host BACKUP]
                         [--opnsense-user USER]
                         [--opnsense-interfaces INTERFACES]
                         [--opnsense-password PASSWORD]
                         [--prometheus-instance PROM_INSTANCE]

OPNSense prometheus exporter

optional arguments:
  -h, --help            show this help message and exit
  --check-frequency-seconds FREQUENCY, -c FREQUENCY
                        How often (in seconds) this server requests
                        OPNSense servers (default: 2)
  --main-host MAIN, -m MAIN
                        MAIN OPNsense server that should be in `active`
                        state in normal configuration.
  --backup-host BACKUP, -b BACKUP
                        BACKUP OPNsense server that should be `hot_standby`
                        state in normal configuration.
  --opnsense-user USER, -u USER
                        OPNsense user. Expect to be the same on MAIN and
                        BACKUP servers
  --opnsense-interfaces INTERFACES, -i INTERFACES
                        OPNsense interfaces (coma separated) list to
                        export trafic rates (bytes/s). An empty string ''
                        means not calling the traffic diagnostic REST API
                        so no `opnsense_active_server_traffic_rate`
                        metric. (default: wan,lan)
  --opnsense-timeout-sec-get-vip-status GET_VIP_STATUS_TIMEOUT_SEC
                        Allow to configure timeout while requesting
                        OPNSense REST API
                        /api/diagnostics/interface/get_vip_status/
                        (default: 5)
  --opnsense-timeout-sec-get-traffic GET_TRAFFIC_TIMEOUT_SEC
                        Allow to configure timeout while requesting
                        OPNSense REST API
                        /api/diagnostics/traffic/top/[INTERFACES]
                        (default: 15)
  --opnsense-password PASSWORD, -p PASSWORD
                        OPNsense password. Expect to be the same on MAIN
                        and BACKUP servers
  --prometheus-instance PROM_INSTANCE
                        Exporter Instance name, default value computed with
                        hostname where the server is running. Use to set
                        the instance label. (default: my-opnsense-prom-exporter-server)You can setup env through.envfile or environment variables with defined as default values
(so command line will get the precedent):CHECK_FREQUENCY_SECONDS: default value for--check-frequency-secondsparamOPNSENSE_MAIN_HOST: default value for--main-hostparamOPNSENSE_BACKUP_HOST: default value for--backup-hostparamOPNSENSE_USERNAME: default value for--opnsense-userparamOPNSENSE_PASSWORD: default value for--opnsense-passwordparamOPNSENSE_INTERFACES: default value for--opnsense-interfacesparamOPNSENSE_TIMEOUT_SEC_GET_VIP_STATUS: default value for--opnsense-timeout-sec-get-vip-statusparamOPNSENSE_TIMEOUT_SEC_GET_TRAFFIC: default value for--opnsense-timeout-sec-get-trafficparamRoadmapallow to change the listening port (today it force using8000)improves logging to get a debug mode to understand errors based on unexpected payloadsChangelogVersion 1.1.0 (2023-09-06)allow to configure OPNSense REST API calls timeout per REST API endpoint adding--opnsense-timeout-sec-get-vip-statusand--opnsense-timeout-sec-get-trafficparameters.Version 1.0.0 (2023-09-06)removeopnsense_main_ha_stateandopnsense_backup_ha_statemetrics marked as deprecated on version 0.5.0 and replace
byopnsense_server_ha_stateandrolelabelallow empty string interfaces tonotcall diagnostic
traffic REST APIVersion 0.5.1 (2023-09-04)FIXopnsense_server_ha_statecalls were not
implementedVersion 0.5.0 (2023-09-04)add role label in metricsall to configure supervised interfaces using--opnsense-interfacesreplaceactive_server_bytes_receivedandactive_server_bytes_transmittedbyopnsense_active_server_traffic_rateaddopnsense_server_ha_stateand markopnsense_main_ha_stateandopnsense_backup_ha_stateas deprecated.Version 0.4.0 (2023-09-02)Higher timeout while getting WAN traffic infoVersion 0.3.0 (2023-09-02)Use proper method to compute WAN trafficVersion 0.2.0 (2023-09-01)Setup automatic release from gitlab while pushing new tagVersion 0.1.0 (2023-09-01)Initial version