Improve error logging when metrics cannot be pushed to pushURL passed to InitPush*()
This commit is contained in:
parent
5710165c4b
commit
195ac63dbf
13
push.go
13
push.go
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@ -108,14 +109,16 @@ func InitPushExt(pushURL string, interval time.Duration, extraLabels string, wri
|
|||||||
}
|
}
|
||||||
resp, err := c.Post(pushURL, "text/plain", &bb)
|
resp, err := c.Post(pushURL, "text/plain", &bb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("cannot push metrics to %q: %s", pushURL, err)
|
log.Printf("ERROR: metrics.push: cannot push metrics to %q: %s", pushURL, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if resp.StatusCode/100 != 2 {
|
||||||
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
log.Printf("ERROR: metrics.push: unexpected status code in response from %q: %d; expecting 2xx; response body: %q", pushURL, resp.StatusCode, body)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
_ = resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
if resp.StatusCode/100 != 2 {
|
|
||||||
log.Printf("unexpected status code in response from %q: %d; expecting 2xx", pushURL, resp.StatusCode)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user