-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding analyzer code - so far reading query list, next add actual ana…
…lysis Signed-off-by: Kedar Vijay Kulkarni <[email protected]>
- Loading branch information
Kedar Vijay Kulkarni
committed
Nov 1, 2021
1 parent
291d0db
commit 2c7d3a4
Showing
6 changed files
with
157 additions
and
68 deletions.
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
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,50 @@ | ||
package analyze | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
|
||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
/* | ||
This package will read the queries from relevant config file under `config/` dir | ||
and run relevant queries using prometheus package. Then retrieve the result and | ||
analyze it against the threshold. | ||
*/ | ||
|
||
const configPath = "./config/" | ||
|
||
type queryList []queries | ||
|
||
type queries struct { | ||
Query string `json:"query"` | ||
WatchFor []watchList | ||
} | ||
|
||
type watchList struct { | ||
Key string `json:"Key"` | ||
Val string `json:"Val"` | ||
Threshold string `json:"threshold"` | ||
} | ||
|
||
func (q *queryList) Parse(data []byte) error { | ||
return yaml.Unmarshal(data, q) | ||
} | ||
|
||
func ReadPrometheusQueries() (queriesList queryList, err error) { | ||
data, err := ioutil.ReadFile(configPath + "queries.yaml") | ||
if err != nil { | ||
log.Printf("Cound't read %s/queries.yaml", configPath) | ||
return queriesList, err | ||
} | ||
if err := queriesList.Parse(data); err != nil { | ||
log.Fatal(err) | ||
} | ||
// fmt.Println(queriesList) | ||
if len(queriesList) == 0 { | ||
return queriesList, nil | ||
} | ||
|
||
return queriesList, nil | ||
} |
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
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,15 @@ | ||
--- | ||
- query: "sum(kube_pod_status_phase{}) by (phase) > 0" | ||
watchFor: | ||
- key: Phase | ||
val: "Pending" | ||
threshold: 10 | ||
- key: Phase | ||
val: "Failed" | ||
threshold: 0 | ||
- query: "sum(kube_namespace_status_phase) by (phase)" | ||
watchFor: | ||
- key: Phase | ||
val: "Terminating" | ||
threshold: 0 | ||
|
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
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