Filtering metrics via Telegraf before output to InfluxDB #112
Replies: 6 comments 20 replies
-
Great work @mcbirse! While I don't have an immediate application for it, I'm guessing I'll be down the rabbit hole of tweaking my own data before too long.
This might be real - it looks like my Fronius inverter has an 8W continuous draw at night, while my ABB has a flatline 0W. I've got a vague memory that the Fronius webserver is available at night (on my to do list item to check/disable this). I'll take a look this evening and report back. |
Beta Was this translation helpful? Give feedback.
-
Very nice, thanks for the flexibility @mcbirse
… On Oct 24, 2022, at 7:34 PM, BuongiornoTexas ***@***.***> wrote:
Great work @mcbirse <https://github.com/mcbirse>! While I don't have an immediate application for it, I'm guessing I'll be down the rabbit hole of tweaking my own data before too long.
I see very small negative solar generation values, which I think cumulative amounts of may skew my solar generation totals - so the plugin can be used to set negative values to zero, for instance.
This might be real - it looks like my Fronius inverter has an 8W continuous draw at night, while my ABB has a flatline 0W. I've got a vague memory that the Fronius webserver is available at night (on my to do list item to check/disable this). I'll take a look this evening and report back.
—
Reply to this email directly, view it on GitHub <#112 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AJWC2EBDOLEN74YEEMFJRALWE5BKXANCNFSM6AAAAAARNQO4TM>.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
-
I always thought the pitch-black sky was trying to take some of the power back! :) Nice work on this. Seems like it could be very useful. |
Beta Was this translation helpful? Give feedback.
-
@mcbirse - I have never seen the power flow show negative like the screenshot you posted. |
Beta Was this translation helpful? Give feedback.
-
Just thought I would post an update this.... My Powerwall firmware updated from "22.18.3 21c0ad81" to "22.26.2 8cd8cac4" yesterday, and the filter script I added as per my example worked perfectly. So, during the firmware update, the gateway responds with zero values for the below metrics for a period of about 3.5 minutes.
The telegraf log above shows those metrics were removed, as per the script, which is what I wanted so the zero values would not be logged to InfluxDB and won't appear in the dashboard. Timing of firmware update events:
Confirmed the zero values were filtered out, otherwise the charge percentage would show a drop to zero at about 12:40pm below. I think there is a small issue with the pypowerwall proxy however after a firmware update... Everything was logging again correctly after the update, however the Power Flow meter was no longer working. It would just appear to be "flashing" on/off in the browser. I had to restart the pypowerwall container to fix this. If I have a chance I'll investigate further - quite hard to test though since firmware updates don't happen very often! |
Beta Was this translation helpful? Give feedback.
-
So far so good. Thanks! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
There was some discussion recently regarding "invalid" data being output to InfluxDB.
Specifically, it appears that during Powerwall firmware updates, the local gateway will return a value of "zero" for certain metrics, i.e. battery charge level and power usage values.
Since the local gateway is still returning values, rather than "no data", these "zero" values will be output to InfluxDB and can be seen in Powerwall-Dashboard - example can be seen in #109 with @cwagz's graph showing the battery level drop to zero during a firmware upgrade.
Also, @ibmaster noted in #101 and #103 he had invalid zero value data, that he did not want in the database, and was looking to remove them.
I had been thinking a change to pypowerwall to filter the output could be a solution. As @jasonacox has mentioned though, and I completely agree, the pyPowerwall library is an API for the Powerwall and the expectation is that it delivers accurately what Tesla is saying.
It does seem to be more of a personal choice if someone would prefer to filter out the zero value data, or allow it. If it is not filtered, it certainly is quite easy to identify a firmware update or issue by viewing the dashboard graphs.
However, my personal preference is actually that the zero value data being output is not really valid - the battery charge level did not suddenly drop to zero - so I don't want it to be logged like that and would prefer "no data" to be logged during this event.
As such, I found a way to filter any metrics before it is output to InfluxDB, and thought I would share this.
This is done by using the Telegraf Starlark Processor Plugin, which allows you to intercept metrics and manipulate them in some way based on whatever conditions you like (i.e. remove a metric, change a value, add a new metric, etc.) - and this is done before the metrics are output to InfluxDB.
I think this plugin could be useful in a number of circumstances - e.g. for some reason during nighttime, I see very small negative solar generation values, which I think cumulative amounts of may skew my solar generation totals - so the plugin can be used to set negative values to zero, for instance.
Here's an example of how you could implement this. The language used by the plugin is very similar to python.
Thanks to @BuongiornoTexas for localizing some of the telegraf configs, which has made this easy to implement for your own setup now. 😊
telegraf.local
file[[processors.starlark]]
and then add your source scriptThe example below does the following:
After saving
telegraf.local
with your changes, restart the container to start using the filter:# Restart telegraf docker restart telegraf
If you have log output in your filter, you can view this as follows:
# View telegraf logs docker logs -f telegraf
Some important things to note if you wish to implement your own filtering:
Because not all metrics and passed in the one call, I was doing some testing with shared state usage. This means you can store the previous value of a metric in a global shared state for later retrieval by a subsequent call to the plugin.
Below is an example which may be useful if you need to implement your own shared state type filter (important: the "state" dictionary variable name needs to be "state" - don't rename it!)
Hopefully the above info is useful for anyone that needs to filter metrics before they are output to InfluxDB.
I think there is potentially a number uses for this, and am using this myself now to filter out zero value data during firmware upgrades of my Powerwall (...hopefully 🤞 - waiting for the next firmware upgrade to actually happen so I can confirm it works).
Beta Was this translation helpful? Give feedback.
All reactions