Sign inSign up

ncareau/pfsense-to-influxdb

By ncareau

Updated over 6 years ago

Image
0

1.6K

ncareau/pfsense-to-influxdb repository overview

pfSense-to-InfluxDB

This program is built to collect information from pfSense and send it to InfluxDB. The eventual goal in creating this program was to provide pfSense metrics and alerts to Grafana. The program uses FauxAPI to call the native PHP functions pfSense uses to create widgets on its dashboard.

Note: pfSense-to-InfluxDB is not intended to be installed on pfSense since pfSense doesn't ship with python3 installed. Installing on your InfluxDB host or another host is recommended.

Installation

  1. Install and configure FauxAPI on your pfSense router. Remember to add a new user to /etc/fauxapi/credentials.ini with permissions: config_get, function_call
  • Then add the following lines to /etc/fauxapi/pfsense_function_calls.txt:
gwlb.inc:function return_gateways_status($byname = false)
util.inc:function get_configured_interface_with_descr($only_opt = false, $with disabled = false)
pfsense-utils.inc:function get_interface_info($ifdescr)
openvpn.inc:function openvpn_get_active_clients()
openvpn.inc:function openvpn_get_active_servers($type="multipoint")
service-utils.inc:function get_services()
service-utils.inc:function get_service_status($service)
  1. Install latest release of pfSense-to-InfluxDB.
  • Using git:
git clone https://github.com/ArmaanT/pfsense-to-influxdb.git --branch v1.1.0
cd pfsense-to-influxdb
  • Or download directly:
wget -O pfsense-to-influxdb.tar.gz "https://github.com/ArmaanT/pfsense-to-influxdb/archive/v1.1.0.tar.gz"
tar -xf pfsense-to-influxdb.tar.gz
mv pfsense-to-influxdb-* pfsense-to-influxdb
rm pfsense-to-influxdb.tar.gz
cd pfsense-to-influxdb
  1. Install requirements:
pip3 install -r requirements.txt

Docker

You can use docker to run this application quickly.

docker run -v settings.conf:/app/config/settings.conf ncareau/pfsense-to-influxdb:latest

Configuration

Rename settings.sample.conf to settings.conf and add your desired settings:

General
KeyDescription
DelayTime (in seconds) between updates sent to InfluxDB
FauxAPI
KeyDescription
APIHostIP Address or FQDN of pfSense Router
APIKeyAPI Key created in /etc/fauxapi/credentials.ini
APISecretAPI Secret created in /etc/fauxapi/credentials.ini
InfluxDB
KeyDescription
InfluxDBHostIP Address or FQDN of InfluxDB Host
PortInfluxDB port. Normally 8086
UsernameInfluxDB Username
PasswordInfluxDB Password
DatabaseInfluxDB Database
Modules
KeyDescription
Gateway_StatusEnable metric gathering on gateway statuses (true/false)
Interface_StatisticsEnable metric gathering on interface statistics (true/false)
Interface_StatusEnable metric gathering on interface statuses (true/false)
OpenVPN_Client_StatusEnable metric gathering on pfSense OpenVPN clients (true/false)
OpenVPN_Connected_ClientsEnable metric gathering on clients connected to pfSense OpenVPN servers (true/false)
Services_StatusEnable metric gathering on service statuses (true/false)

Start at boot

A sample systemd service file, pfsense_influx_collector.service, is included to automatically run pfSense-to-InfluxDB on boot. Open the file to change the following lines to reflect your user and path to pfSenseInfluxCollector.py:

User=CHANGEME
ExecStart=/usr/bin/python3 /path/to/pfSenseInfluxCollector.py

Then install, enable, and start pfsense_influx_collector.service:

sudo cp pfsense_influx_collector.service /etc/systemd/system/pfsense_influx_collector.service
sudo systemctl enable pfsense_influx_collector.service
sudo systemctl start pfsense_influx_collector.service

Grafana

A sample pfsense_dashboard.json is provided. First, add your pfsense InfluxDB database as a Grafana Data Source. Then to import the dashboard: hover over the create dashboard button (the plus sign) in Grafana, click "Import" and upload the dashboard.json file or paste the contents of the file in the text box and click "Load".

Updating

  • Using git:
cd /path/to/pfsense-to-influxdb
git pull origin v1.1.0
  • Downloading directly
cd /tmp/
wget -O pfsense-to-influxdb.tar.gz "https://github.com/ArmaanT/pfsense-to-influxdb/archive/v1.1.0.tar.gz"
tar -xf pfsense-to-influxdb.tar.gz
mv pfsense-to-influxdb-*/* /path/to/previously-installed/pfsense-to-influxdb/
rm pfsense-to-influxdb.tar.gz
rm -r pfsense-to-influxdb-*

InfluxDB Schema

Measurement: gateway_status
FieldDescription
nameName of gateway
rttRound-trip time
rttsdStandard deviation of RTT
statusStatus of gateway (1 for online, 0 for other statuses)
TagDescription
hostpfSense hostname with domain
Measurement: interface_statistics
FieldDescription
bytes_inNumber of bytes in
bytes_outNumber of bytes out
collisionsNumber of collisions
errors_inNumber of errors in
errors_outNumber of errors out
nameName of gateway
packets_inNumber of packets in
packets_outNumber of packets out
TagDescription
hostpfSense hostname with domain
interfaceInterface being polled
Measurement: interface_status
FieldDescription
ip_addressIP address of interface
nameName of interface
statusStatus of interface (1 for online, 0 for offline)
TagDescription
hostpfSense hostname with domain
interfaceInterface being polled
Measurement: openvpn_client_status
FieldDescription
remote_hostRemote IP address of OpenVPN client
statusStatus of OpenVPN client (1 for online, 0 for offline)
virtual_addressVirtual IP address of OpenVPN client
TagDescription
hostpfSense hostname with domain
vpnidID of OpenVPN Client
Measurement: openvpn_connected_clients
FieldDescription
client_idClient ID of connection
common_nameName connected user
connected_clientsNumber of connected clients
remote_hostRemote IP address of user
virtual_addressVirtual IP address of user
TagDescription
hostpfSense hostname with domain
serverpfSense OpenVPN Server client is connected to
Measurement: services_status
FieldDescription
descriptionDescription of service
statusStatus of service (1 for online, 0 for offline)
TagDescription
hostpfSense hostname with domain
serviceService being polled

License

Licensed under the terms of the MIT license. See LICENSE.md

Tag summary

Content type

Image

Digest

Size

39.5 MB

Last updated

over 6 years ago

docker pull ncareau/pfsense-to-influxdb