Skip to content

Commit

Permalink
Added frequency control feature
Browse files Browse the repository at this point in the history
Signed-off-by: Kedar Vijay Kulkarni <[email protected]>
  • Loading branch information
Kedar Vijay Kulkarni committed Nov 8, 2021
1 parent c6cdc83 commit 38905e6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ update: clean build
OUT_DIR=bin
build:
mkdir -p "${OUT_DIR}"
go build -o "${OUT_DIR}/cpa" main.go
go build -v -o "${OUT_DIR}/cpa" main.go

clean:
$(RM) ./bin/cpa
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This tool allows OpenShift users to run a watcher for Prometheus queries and def
* [x] Add a Makefile
* [x] File logging the output
* [x] Print output to screen even when logging enabled - simultaneously
* [x] Let user decide query frequency
* [ ] Notify/Do Something when results don't match conditions
* [ ] Spawn goroutines to keep running queries and evaluating results to handle scale - e.g. when we have very large number of queries in the yaml file, we can divide and concurrently run queries

Expand Down
16 changes: 9 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build go1.17

package main

import (
Expand All @@ -17,10 +19,11 @@ import (

func main() {
var args struct {
NoClrscr bool `arg:"--noclrscr" help:"Do not clear screen after each iteration. Clears screen by default." default:"false"`
Queries string `arg:"-q,--queries" help:"queries file to use" default:"queries.yaml"`
Timeout time.Duration `arg:"-t,--timeout" help:"Duration to run Continuous Performance Analysis. You can pass values like 4h or 1h10m10s" default:"4h"`
LogOutput bool `arg:"-l,--log-output" help:"Output will be stored in a log file instead of stdout." default:"false"`
NoClrscr bool `arg:"--noclrscr" help:"Do not clear screen after each iteration. Clears screen by default." default:"false"`
Queries string `arg:"-q,--queries" help:"queries file to use" default:"queries.yaml"`
QueryFrequency time.Duration `arg:"-f,--query-frequency" help:"How often do we run queries. You can pass values like 4h or 1h10m10s" default:"20s"`
Timeout time.Duration `arg:"-t,--timeout" help:"Duration to run Continuous Performance Analysis. You can pass values like 4h or 1h10m10s" default:"4h"`
LogOutput bool `arg:"-l,--log-output" help:"Output will be stored in a log file instead of stdout." default:"false"`
}
arg.MustParse(&args)

Expand Down Expand Up @@ -86,9 +89,8 @@ func main() {
return
}
analyze.Queries(queryList, oc, url, bearerToken, c)
d := time.Second * 20
log.Printf("\n Sleeping for %.2f mins.\n\n\n\n", d.Minutes())
time.Sleep(d)
log.Printf("\n Sleeping for %.2f mins.\n\n\n\n", args.QueryFrequency.Minutes())
time.Sleep(args.QueryFrequency)
if !args.NoClrscr {
log.Print("\033[H\033[2J") // clears screen before printing next iteration
}
Expand Down

0 comments on commit 38905e6

Please sign in to comment.