pfSense stat monitor

This great! Do you also have Temperature OID and, CPU, Memory usage?
thanks!

Lately I found the CPU utilization stays fixed at 2.7%. By looking at the json “cpu” data, though the data is changing overtime, the resulted calculation will always gives value 2.7%. I therefore use the “load_average” 1-minute value instead. So the CPU load (my CPU has 4 cores, so divided the value by 4) in my configuration.yaml is:

  - platform: file
    file_path: pfSense_stats.json
    name: pfSense_cpu
#   below formula used to work, but lately "cpu" always produced fixed value 2.7%, then use "load_average" 1-min value instead
#    value_template: '{{ ( ( ((value_json["data"]["stats"]["cpu"].split("|")[0] | float) / (value_json["data"]["stats"]["cpu"].split("|")[1] | float)) - 1.0 ) * 100.0 ) | round(1) }}'
    value_template: '{{ ((value_json["data"]["stats"]["load_average"][0] | float) * 100.0 / 4.0 ) | round(0) }}'
    unit_of_measurement : '%'

Good find! :+1: I have the same problem… but I never looked into it.

1 Like

I needed a way to restart my ISP’s crappy modem whenever the internet stopped operating.

I’ve put together a small custom component for Home Assistant which based on alexpmorris’s pfsense-status-gateways-json script checks the gateway’s status in pfSense every 3 minutes.

Multiple gateways can be added to the config, so for every gateway it will create a sensor returning True while the gateway monitoring in pfSense says it’s up, and False whenever pfSense says it’s down.

I power the ISP modem through a Sonoff Mini running Tasmota, connected to a Normally Closed relay, and set with parameter PulseTime 120. This results in the modem being powered on normally, but whenever the gateway goes down for more than 5 mins (according to the automation set in HA), the Sonoff turns on, which cuts the power with the relay. PulseTime 120 means that the Sonoff will turn off after 20 seconds, power will be restored to the modem - this is how I get a 20-second power-cycle on the modem. So in the automation it’s just enough to turn on the switch - it will turn itself off after 20 seconds.

1 Like

I just implemented this. It was considerably easier than having to deploy additional components.

Thanks for providing this information!

I can get the python script to work in terminal, but it fails when run from the command line sensor.

I don’t want to hijack the tread so posted here: Python script works in terminal, but fails in command line sensor

Any help appreciated!

After many tries, I got it mostly working
I complied mine into a github repo in case anyone wants to check it out

4 Likes

Ooo. I like those rule switches. I might have to dig into that :nerd_face:

1 Like

Updated a bit and added HACS install support

Wow … Just what i was looking for… Started using HA today… Integrated it with Fibaro HC2, Philips HUE and NetAtmo so far… This integration with PfSense is a dream come true!! Thanks for taking time posting this!

2 Likes

I have tried everything in this thread. But i still got this unknown on my sensors. What has gone wrong?

image

Did you install the required support script onto your pfSense device? You need to put the following script into /usr/local/www on your pfSense device.

I use OPNsense and will see if this works.

I have the same issue, did you get it to work?

Maybe someone else know this? The error I see in the logs are:

Timeout for command: python3 /config/custom_components/pfsense_fauxapi/function-gateway.py

EDIT: got this fixed by adding the port to the IP of the pfSense server (default 10443)

If anyone is interested in an alternative approach, there is a telegraf package for pfsense that will dump data into an influxdb database. From influxdb, there are a ton of options. I’m using influxdb sensors for the basic stats, and then using grafana for the full dashboard. There’s an awesome pfsense dashboard available to download already.

Here’s a few influxdb sensors for the proxmox box thatI use to host pfsense (proxmox will also dump to influxdb):

And here’s a few shots from grafana. This is the community dashboard available for download:

5 Likes

Would you mind to share some details how to make it running?

For sure. I’ll post up more details later. The stack is pretty well documented (TICK, or Telegraf+Influxdb+Chronograf+Kapacitor), so Google it. Basically, get influx going, install telegraf on pfsense, then visualize the data. I use grafana, but chronograf is also great.

Edit:

  1. First things first, get influxdb up and running somewhere (the “I” in the TICK stack). You can use the home assistant addon, you can spin up a docker container on another host (what I’m doing) or any other method available.

  2. If you are using the addon, then Chronograf is included in the package. If you are not using the addon, then I HIGHLY reccomend you also spin up a a Chronograf container (the “C” in the TICK stack). Chronograf is an awesome data visualization tool for Influxdb. But even better, it’s also a web based admin GUI. It makes things like adding new users and databases a breeze. The visualization parts also make it super easy to quickly query the data in a pinch. Use Chronograf to create new database called “pfsense” and make sure you give your non-admin user read and write access:

  1. Now it is time to install Telegraf (the “T”). This is the tool that will pump data into your new Influxdb that you setup and administrate in Chronograf. Go to your package manager in the GUI, look for Telegraf, and install it:

  1. Configure Telegraf to send data to your new Influxdb database. Its as simple as services>telegraf and then fill in the details:

  1. To visualize the data you can use Chronograf. But I like Grafana because it is super easy to imbed graphics in lovelace, or just click right into the environment from the side bar. If you use Grafana, then download the pfsense dashboard and install it:

  1. Bonus points: if you want to pull in a few values from you Influxdb source, you can create influxdb sensors. The configuration is a bit of a bear, but once you get the syntax right it is pretty straight forward. You can use Chronograf to help you construct a query.

With this stack you can start getting all kinds of data from other sources. I have two proxmox hosts that dump into other databases. I have a few linux containers and another host where I also use Telegraf. Oh, and the “K” is for Kapacitor. You can use this last tool in the stack for reporting and alerting. I haven’t leveraged it too much yet since I can also do this in node-red or home assistant, but it is there and seems really powerful.

7 Likes

Did ya get it to work? Another opnsenser here.

No, but I will try the method above. TrueNAS has a Grafana plugin so I will give it a go.
BTW, I think OPNsense beats all routers out there.

image

I got everything working except for the gateway stats. I cannot figure out what I am missing. I did make the change in function-int-wan.py, but still noting.