Skip to content

Instantly share code, notes, and snippets.

@canimus
Created March 16, 2019 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save canimus/8727f0122db78c0b5863a64f28378ba9 to your computer and use it in GitHub Desktop.
Save canimus/8727f0122db78c0b5863a64f28378ba9 to your computer and use it in GitHub Desktop.
Flux - Pearson of CPUs
// Calculate the correlation between 2 CPU Usage
cpu0 = from(bucket: "telegraf")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == "cpu")
|> filter(fn: (r) => r._field == "usage_idle")
|> filter(fn: (r) => r.cpu == "cpu0")
cpu1 = from(bucket: "telegraf")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == "cpu")
|> filter(fn: (r) => r._field == "usage_idle")
|> filter(fn: (r) => r.cpu == "cpu1")
pearsonr(x: cpu0, y: cpu1, on: ["_time", "_field"])
|> keep(columns: ["_value"])
|> yield(name: "r1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment