diff --git a/internal/pages/metrics.go b/internal/pages/metrics.go index 1b882e6..bcf52ee 100644 --- a/internal/pages/metrics.go +++ b/internal/pages/metrics.go @@ -2,6 +2,7 @@ package pages import ( "encoding/json" + "io/ioutil" "net/http" "strconv" "strings" @@ -45,12 +46,29 @@ func (c *LokiMetricConfig) sendMetricPing(domain, path string) { return } + log.Debugf("Sending payload %s", string(jsonData)) + // Send the ping to the Loki server go func() { - http.Post( + res, err := http.Post( c.Url, "application/json", strings.NewReader(string(jsonData)), ) + if err != nil { + log.Errorf("Failed to send payload to Loki: %v", err) + return + } + + defer res.Body.Close() + if res.StatusCode != 204 { + log.Errorf("Loki returned non-204 status code %d", res.StatusCode) + body, err := ioutil.ReadAll(res.Body) + if err != nil { + log.Warnf("Failed to read body. No more specific error message") + return + } + log.Errorf("-> %s", body) + } }() }