mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/metricsql: add example for ExpandWithExprs
This commit is contained in:
parent
192b51c246
commit
a21d786d3c
1 changed files with 28 additions and 0 deletions
28
lib/metricsql/utils_example_test.go
Normal file
28
lib/metricsql/utils_example_test.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package metricsql_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/metricsql"
|
||||
)
|
||||
|
||||
func ExampleExpandWithExprs() {
|
||||
// mql can contain arbitrary MetricsQL extensions - see https://github.com/VictoriaMetrics/VictoriaMetrics/wiki/ExtendedPromQL
|
||||
mql := `WITH (
|
||||
commonFilters = {job="$job", instance="$instance"},
|
||||
f(a, b) = 100*(a/b),
|
||||
)
|
||||
f(disk_free_bytes{commonFilters}, disk_total_bytes{commonFilters})`
|
||||
|
||||
// Convert mql to PromQL
|
||||
pql, err := metricsql.ExpandWithExprs(mql)
|
||||
if err != nil {
|
||||
log.Fatalf("cannot expand with expressions: %s", err)
|
||||
}
|
||||
|
||||
fmt.Printf("%s\n", pql)
|
||||
|
||||
// Output:
|
||||
// 100 * (disk_free_bytes{job="$job", instance="$instance"} / disk_total_bytes{job="$job", instance="$instance"})
|
||||
}
|
Loading…
Reference in a new issue