-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
State-aggregate #117
Comments
Similar sort of problem that could be solved by the same agg: https://stackoverflow.com/questions/68544600/postgresql-looping-through-array-agg |
i think edit: there also needs to be a workaround for not being able to use time_bucket_gapfill for caggs |
We're trying to calculate machine uptime, downtime, and other metrics, and will need a function like this. Posted a question here - https://stackoverflow.com/questions/69246220/timescaledb-how-get-timestamp-differences-between-rows-and-group-results-into. In the meantime, we'll write some nodejs code to dump data into a bins table for a viz lib (grafana) to consume. It'll be a bit complex, and have fixed bin size (an hour?), but I guess the alternative is to write some complex Postgres code. Eventually we might move the code into a grafana (or superset) plugin - then bin sizes can be dynamic, and use an in-memory bin table, instead of needing to go through the db bins table intermediary. Anyway, yes this would be a nice function to have! |
Hey folks, Currently, I am running query to get calculate it real-time (recent 10 alarms), I want a way to create aggregate continuously. (may be using triggers/procedures) so that I can have historical alarms per device with start/end time. It would be nice to have some built-in function or automated way to achieve this.!edit: I tried creating a trigger, which will execute after insert and will record aggregates into another table named alarms_history, If I can, somehow, calculate the ended_on, and update the ended_on in alarms_history, then it might work as expected.
|
an example of this might look like SELECT duration_in('STOPPED', states) as run_time, duration_in('ERROR', states) as error_time FROM (
SELECT state_agg(time, status) as states FROM ...
); which would return the amount of time a service spends stopped or in an error state. |
This issue should have been closed by PR #324 We released the |
timescale/timescaledb#1324 describes an interesting and possibly common problem of devices switching between different (error/non-error etc) states. A state aggregate would add up the time spent in each state following the ordered list of things. This would be very difficult to put into continuous aggregates otherwise as it would need window functions and other bits to get right. In concept it looks reasonably similar to
time_weighted_average
though with a list of distinct items and their durations as well as the starting and ending values, it'd be nicely combinable and all that and would really help folks who want to answer the "how long was my device in an error state" type question (common uptime question).The text was updated successfully, but these errors were encountered: