added metric for failed attempts to persist the content history

This commit is contained in:
Philipp Mieden 2019-05-29 14:14:15 +02:00
parent 581e68599c
commit 6381c7c0c2
4 changed files with 19 additions and 11 deletions

View File

@ -58,13 +58,11 @@ func main() {
}()
if *flagFreeOSMem > 0 {
Log.Info("dumping heap every $interval minutes", zap.Int("interval", *flagHeapDump))
Log.Info("freeing OS memory every $interval minutes", zap.Int("interval", *flagFreeOSMem))
go func() {
for {
select {
case <-time.After(time.Duration(*flagFreeOSMem) * time.Minute):
Log.Info("dumping heap every $interval minutes", zap.Int("interval", *flagHeapDump))
log.Info("FreeOSMemory")
debug.FreeOSMemory()
}

View File

@ -249,6 +249,7 @@ func (repo *Repo) loadJSONBytes() error {
historyErr := repo.history.add(repo.jsonBuf.Bytes())
if historyErr != nil {
Log.Error("could not add valid json to history", zap.Error(historyErr))
status.M.HistoryPersistFailedCounter.WithLabelValues(historyErr.Error()).Inc()
} else {
Log.Info("added valid json to history")
}

View File

@ -10,6 +10,8 @@ import (
"strings"
"time"
"github.com/foomo/contentserver/status"
"github.com/mgutz/ansi"
"github.com/foomo/contentserver/content"
@ -275,7 +277,8 @@ func (repo *Repo) Update() (updateResponse *responses.Update) {
// persist the currently loaded one
historyErr := repo.history.add(repo.jsonBuf.Bytes())
if historyErr != nil {
Log.Warn("could not persist current repo in history", zap.Error(historyErr))
Log.Error("could not persist current repo in history", zap.Error(historyErr))
status.M.HistoryPersistFailedCounter.WithLabelValues(historyErr.Error()).Inc()
}
// add some stats
for dimension := range repo.Directory {

View File

@ -19,14 +19,15 @@ const (
// Metrics is the structure that holds all prometheus metrics
type Metrics struct {
ServiceRequestCounter *prometheus.CounterVec // count the number of requests for each service function
ServiceRequestDuration *prometheus.SummaryVec // observe the duration of requests for each service function
UpdatesRejectedCounter *prometheus.CounterVec // count the number of completed updates
UpdatesCompletedCounter *prometheus.CounterVec // count the number of rejected updates
UpdatesFailedCounter *prometheus.CounterVec // count the number of updates that had an error
UpdateDuration *prometheus.SummaryVec // observe the duration of each repo.update() call
ContentRequestCounter *prometheus.CounterVec // count the total number of content requests
NumSocketsGauge *prometheus.GaugeVec // keep track of the total number of open sockets
ServiceRequestCounter *prometheus.CounterVec // count the number of requests for each service function
ServiceRequestDuration *prometheus.SummaryVec // observe the duration of requests for each service function
UpdatesRejectedCounter *prometheus.CounterVec // count the number of completed updates
UpdatesCompletedCounter *prometheus.CounterVec // count the number of rejected updates
UpdatesFailedCounter *prometheus.CounterVec // count the number of updates that had an error
UpdateDuration *prometheus.SummaryVec // observe the duration of each repo.update() call
ContentRequestCounter *prometheus.CounterVec // count the total number of content requests
NumSocketsGauge *prometheus.GaugeVec // keep track of the total number of open sockets
HistoryPersistFailedCounter *prometheus.CounterVec // count the number of failed attempts to persist the content history
}
// newMetrics can be used to instantiate a metrics instance
@ -72,6 +73,11 @@ func newMetrics() *Metrics {
"Total number of currently open socket connections",
metricLabelRemote,
),
HistoryPersistFailedCounter: newCounterVec(
"history_persist_failed_count",
"Number of failures to store the content history on the filesystem",
metricLabelError,
),
}
}