Skip to content

Commit

Permalink
feat: add fetch-interval option
Browse files Browse the repository at this point in the history
  • Loading branch information
arsiesys committed May 18, 2021
1 parent c763426 commit d8f5bee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ Usage:
jenkins-node-state-exporter [flags]
Flags:
-a, --address string address of the jenkins server (default "http://localhost/jenkins")
--disable-authentication disable authentication
-h, --help help for jenkins-node-state-exporter
-p, --password string password of the jenkins user account (default "admin")
--port int port to listen on (default 9723)
-u, --username string username of the jenkins user account (default "admin")
-a, --address string address of the jenkins server (default "http://localhost/jenkins")
--disable-authentication disable authentication
--fetch-interval duration fetch-interval in seconds (default 30s)
-h, --help help for jenkins-node-state-exporter
-p, --password string password of the jenkins user account (default "admin")
--port int port to listen on (default 9827)
-u, --username string username of the jenkins user account (default "admin")
```
15 changes: 10 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ package cmd

import (
"fmt"
"github.com/spf13/cobra"
"log"
"os"

exporter "github.com/arsiesys/jenkins-node-state-exporter/pkg/exporter"
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"log"
"os"
"time"
)

var cfgFile string
Expand Down Expand Up @@ -58,6 +58,10 @@ func init() {
if err := viper.BindPFlag("port", rootCmd.Flags().Lookup("port")); err != nil {
log.Fatal(err)
}
rootCmd.Flags().Duration("fetch-interval",30*time.Second,"fetch-interval in seconds")
if err := viper.BindPFlag("fetch-interval", rootCmd.Flags().Lookup("fetch-interval")); err != nil {
log.Fatal(err)
}
rootCmd.Flags().Bool("disable-authentication",false,"disable authentication")
if err := viper.BindPFlag("disable-authentication", rootCmd.Flags().Lookup("disable-authentication")); err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -102,5 +106,6 @@ func initConfig() {
} else {
log.Printf("Using username: %s", viper.GetString("username"))
}
log.Printf("Listening on port :%d",viper.GetInt("port"))
log.Printf("Listening on port: %d",viper.GetInt("port"))
log.Printf("Parsing interval: %fs",viper.GetDuration("fetch-interval").Seconds())
}
3 changes: 1 addition & 2 deletions pkg/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ func promWatchJenkinsNodes(registry prometheus.Registry) {
delete(listOfKnownComputer, k)
}


time.Sleep(10 * time.Second)
time.Sleep(time.Duration(viper.GetDuration("fetch-interval")))
}
}()
}
Expand Down

0 comments on commit d8f5bee

Please sign in to comment.