Add metric counting report publish attempts and errors

This commit is contained in:
Bryan Boreham
2019-07-09 13:01:26 +00:00
parent cf3812094b
commit 20e7d5d476

View File

@@ -11,6 +11,7 @@ import (
"sync"
"time"
"github.com/armon/go-metrics"
"github.com/gorilla/websocket"
"github.com/hashicorp/go-cleanhttp"
log "github.com/sirupsen/logrus"
@@ -299,6 +300,10 @@ func (c *appClient) publish(r io.Reader) error {
}
defer resp.Body.Close()
metrics.IncrCounterWithLabels([]string{"publishes"}, 1, []metrics.Label{
{Name: "destination", Value: req.Host},
{Name: "status", Value: fmt.Sprint(resp.StatusCode)},
})
if resp.StatusCode != http.StatusOK {
text, _ := ioutil.ReadAll(resp.Body)
return fmt.Errorf(resp.Status + ": " + string(text))