Skip to content

Commit

Permalink
feat(example): add example
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxin688 committed Jun 7, 2024
1 parent 27eaf68 commit 38a1049
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
77 changes: 77 additions & 0 deletions _examples/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package main

import (
"fmt"

"github.com/wangxin688/gopromql"
)

func main() {

pb1 := example1()

pb2 := example2()

pb3 := example3()

pb4 := example4()

fmt.Println(pb1, pb2, pb3, pb4)
}

func example1() string {

pb, err := gopromql.NewPromqlBuilder("http_requests_total").
WithFuncName("last_over_time").
WithWindow("5m").
Build()
if err != nil {
panic(err)
}

return pb
}

func example2() string {

pb, err := gopromql.NewPromqlBuilder("http_requests_total").
WithFuncName("sum_over_time").
WithLabels(gopromql.Label{Name: "status_code", Matcher: "=", Value: "200"}).
WithLabels(gopromql.Label{Name: "method", Matcher: "=~", Value: "GET|POST|PUT"}).
WithLabels(gopromql.Label{Name: "path", Matcher: "!=", Value: "/health"}).
WithWindow("5m").
Build()
if err != nil {
panic(err)
}
return pb
}

func example3() string {
pb, err := gopromql.NewPromqlBuilder("http_requests_total").
WithFuncName("sum_over_time").
WithLabels(gopromql.Label{Name: "status_code", Matcher: "=", Value: "200"}).
WithLabels(gopromql.Label{Name: "method", Matcher: "=~", Value: "GET|POST|PUT"}).
WithLabels(gopromql.Label{Name: "path", Matcher: "!=", Value: "/health"}).
WithComp(gopromql.Compare{Op: gopromql.GreaterThan, Value: 0}).
WithWindow("5m").
Build()
if err != nil {
panic(err)
}

return pb
}

func example4() string {
pb, err := gopromql.NewPromqlBuilder("http_requests_total").
WithFuncName("sum_over_time").
WithLabels(gopromql.Label{Name: "status_code", Matcher: "=", Value: "200"}).
WithAgg(gopromql.Aggregation{Op: gopromql.Max, AggWay: gopromql.GroupBy, By: []string{"method", "path"}}).
WithWindow("5m").
Build()
if err != nil {
panic(err)
}
return pb
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module gopromql
module github.com/wangxin688/gopromql

go 1.22.1

0 comments on commit 38a1049

Please sign in to comment.