Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
feat: add count-days param to resources subcommand
Browse files Browse the repository at this point in the history
close #31

Signed-off-by: Christian Kotzbauer <christian.kotzbauer@gmail.com>
  • Loading branch information
ckotzbauer committed Jun 2, 2021
1 parent 20b1867 commit fb3fd59
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
11 changes: 7 additions & 4 deletions cmd/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ var resourcesCmd = &cobra.Command{
url, _ := cmd.Flags().GetString("prometheus-url")
username, _ := cmd.Flags().GetString("prometheus-username")
password, _ := cmd.Flags().GetString("prometheus-password")
countDays, _ := cmd.Flags().GetInt64("count-days")
timeout, _ := cmd.Flags().GetDuration("timeout")

selector, _ := cmd.Flags().GetString("selector")
namespace, _ := cmd.Flags().GetString("namespace")

r := resources.Resource{
Prometheus: prometheus.Prometheus{
Url: url,
UserName: username,
Password: config.Secret(password),
Timeout: timeout,
Url: url,
UserName: username,
Password: config.Secret(password),
CountDays: countDays,
Timeout: timeout,
},
KubeOverrides: overrides,
KubeClient: kubernetes.NewClient(overrides),
Expand Down Expand Up @@ -59,6 +61,7 @@ func init() {
resourcesCmd.Flags().StringP("prometheus-url", "u", "", "Prometheus-URL")
resourcesCmd.Flags().StringP("prometheus-username", "U", "", "Prometheus-Username")
resourcesCmd.Flags().StringP("prometheus-password", "P", "", "Prometheus-Password")
resourcesCmd.Flags().Int64P("count-days", "d", 30, "Count of days to analyze metrics from (until now).")
resourcesCmd.Flags().DurationP("timeout", "t", time.Duration(30)*time.Second, "Timeout")

resourcesCmd.Flags().StringP("selector", "l", "", "Label-Selector")
Expand Down
9 changes: 5 additions & 4 deletions pkg/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (
)

type Prometheus struct {
Url string
UserName string
Password config.Secret
Timeout time.Duration
Url string
UserName string
Password config.Secret
CountDays int64
Timeout time.Duration
}

func (prom Prometheus) InitPrometheus() v1.API {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func (r Resource) Execute() (printer.PrintableList, error) {
v1api := r.Prometheus.InitPrometheus()
queryRange := v1.Range{
Start: time.Now().Add(-time.Hour * 24 * 30),
Start: time.Now().Add(-time.Hour * 24 * time.Duration(r.Prometheus.CountDays)),
End: time.Now(),
Step: time.Minute * 5,
}
Expand Down

0 comments on commit fb3fd59

Please sign in to comment.