-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27eaf68
commit 38a1049
Showing
2 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |