Skip to content
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

downsample algorithm #22

Closed
2 of 3 tasks
AnalogJ opened this issue Sep 18, 2020 · 6 comments
Closed
2 of 3 tasks

downsample algorithm #22

AnalogJ opened this issue Sep 18, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@AnalogJ
Copy link
Owner

AnalogJ commented Sep 18, 2020

Outstanding Tasks

  • Fix tests (mock out the scrutiny repository and use it in tests)
  • Change queries so they query multiple buckets from InfluxDB.
  • Ensure that downsampled data still works in the UI and is correctly decoded.

Links to InfluxDB downsampling

@AnalogJ
Copy link
Owner Author

AnalogJ commented Sep 18, 2020

@bergernetch said:


You could use influx, can handle this by itself.

@AnalogJ
Copy link
Owner Author

AnalogJ commented Sep 21, 2020

hmm. it would be interesting to only store the last snapshot of SMART data in sqlite, and use influx for all historical data... then I only really need to pull it up for the details page (and temp graph on dashboard)

Discussed in Linuxserver.io chat: https://discordapp.com/channels/354974912613449730/506828136869265408/756938882657943612

@AnalogJ AnalogJ added the enhancement New feature or request label Sep 21, 2020
@AnalogJ
Copy link
Owner Author

AnalogJ commented Oct 24, 2021

potentially working

  import "influxdata/influxdb/schema"
  data = from(bucket: "metrics")
  |> range(start: -2y, stop: now())
  |> filter(fn: (r) => r["_measurement"] == "smart" )
  |> filter(fn: (r) => r["device_wwn"] == "0x5000cca264eb01d7" )
  |> filter(fn: (r) => r["_field"] !~ /(raw_string|_measurement|device_protocol|device_wwn|attribute_id|name|status|when_failed)/)
  |> aggregateWindow(fn: mean, every: 1y)
  |> schema.fieldsAsCols()
  |> yield(name: "last")

@AnalogJ
Copy link
Owner Author

AnalogJ commented Apr 27, 2022

influxdata/flux#2159 has been merged, we can re-write the aggregation logic and do type specific aggregation now .

https://github.com/influxdata/flux/pull/4366/files

        testing.load(tables: tableData)
            |> range(start: -100)
            |> filter(fn: (r) => types.isType(v: r._value, type: "string"))
            |> drop(columns: ["_start", "_stop"])

https://docs.influxdata.com/flux/v0.x/stdlib/types/istype/#aggregate-or-select-data-based-on-type

data = () => from(bucket: "example-bucket")
    |> range(start: -1m)

nonNumericData = data()
    |> filter(fn: (r) => types.isType(v: r._value, type: "string") or types.isType(v: r._value, type: "bool"))
    |> aggregateWindow(every: 30s, fn: last)

numericData = data()
    |> filter(fn: (r) => types.isType(v: r._value, type: "int") or types.isType(v: r._value, type: "float"))
    |> aggregateWindow(every: 30s, fn: mean)

> union(tables: [nonNumericData, numericData])

@AnalogJ
Copy link
Owner Author

AnalogJ commented Apr 28, 2022

working

https://www.reddit.com/r/influxdb/comments/s4zb80/aggregatewindow_with_mixed_types/

import "influxdata/influxdb/schema"
import "types"

sourceBucket = "metrics"
rangeStart = -2w
rangeEnd = -1w
aggWindow = 1w
destBucket = "metrics_weekly"
destOrg = "scrutiny"

smart_data = from(bucket: sourceBucket)
|> range(start: rangeStart, stop: rangeEnd)
|> filter(fn: (r) => r["_measurement"] == "smart" )
|> group(columns: ["device_wwn", "_field"])


nonNumericData = smart_data
    |> filter(fn: (r) => types.isType(v: r._value, type: "string") or types.isType(v: r._value, type: "bool"))
    |> aggregateWindow(every: aggWindow, fn: last, createEmpty: false)

numericData = smart_data
    |> filter(fn: (r) => types.isType(v: r._value, type: "int") or types.isType(v: r._value, type: "float"))
    |> aggregateWindow(every: aggWindow, fn: mean, createEmpty: false)

union(tables: [nonNumericData, numericData])
|> schema.fieldsAsCols()
|> yield()


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant