Commit ded9a2fc authored by Robert Jacob's avatar Robert Jacob

Set client timeout.

parent fc1465f4
......@@ -6,6 +6,7 @@ import (
"log"
"net/http"
"net/url"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/xperimental/nextcloud-exporter/serverinfo"
......@@ -21,12 +22,14 @@ type nextcloudCollector struct {
scrapeErrorsMetric prometheus.Counter
}
func newCollector(infoURL *url.URL, username, password string) *nextcloudCollector {
func newCollector(infoURL *url.URL, username, password string, timeout time.Duration) *nextcloudCollector {
return &nextcloudCollector{
infoURL: infoURL,
username: username,
password: password,
client: &http.Client{},
client: &http.Client{
Timeout: timeout,
},
upMetric: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "nextcloud_up",
Help: "Shows if nextcloud is deemed up by the collector.",
......
......@@ -6,6 +6,7 @@ import (
"log"
"net/http"
"net/url"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/pflag"
......@@ -13,6 +14,7 @@ import (
type config struct {
ListenAddr string
Timeout time.Duration
InfoURL *url.URL
Username string
Password string
......@@ -21,10 +23,12 @@ type config struct {
func parseConfig() (config, error) {
result := config{
ListenAddr: ":8080",
Timeout: 2 * time.Second,
}
var rawURL string
pflag.StringVarP(&result.ListenAddr, "addr", "a", result.ListenAddr, "Address to listen on for connections.")
pflag.DurationVarP(&result.Timeout, "timeout", "t", result.Timeout, "Timeout for getting server info document.")
pflag.StringVarP(&rawURL, "url", "l", "", "URL to nextcloud serverinfo page.")
pflag.StringVarP(&result.Username, "username", "u", "", "Username for connecting to nextcloud.")
pflag.StringVarP(&result.Password, "password", "p", "", "Password for connecting to nextcloud.")
......@@ -58,7 +62,7 @@ func main() {
}
log.Printf("Nextcloud server: %s User: %s", config.InfoURL.Hostname(), config.Username)
collector := newCollector(config.InfoURL, config.Username, config.Password)
collector := newCollector(config.InfoURL, config.Username, config.Password, config.Timeout)
if err := prometheus.Register(collector); err != nil {
log.Fatalf("Failed to register collector: %s", err)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment