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 { 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)) Log.Info("freeing OS memory every $interval minutes", zap.Int("interval", *flagFreeOSMem))
go func() { go func() {
for { for {
select { select {
case <-time.After(time.Duration(*flagFreeOSMem) * time.Minute): case <-time.After(time.Duration(*flagFreeOSMem) * time.Minute):
Log.Info("dumping heap every $interval minutes", zap.Int("interval", *flagHeapDump))
log.Info("FreeOSMemory") log.Info("FreeOSMemory")
debug.FreeOSMemory() debug.FreeOSMemory()
} }

View File

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

View File

@ -10,6 +10,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/foomo/contentserver/status"
"github.com/mgutz/ansi" "github.com/mgutz/ansi"
"github.com/foomo/contentserver/content" "github.com/foomo/contentserver/content"
@ -275,7 +277,8 @@ func (repo *Repo) Update() (updateResponse *responses.Update) {
// persist the currently loaded one // persist the currently loaded one
historyErr := repo.history.add(repo.jsonBuf.Bytes()) historyErr := repo.history.add(repo.jsonBuf.Bytes())
if historyErr != nil { 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 // add some stats
for dimension := range repo.Directory { for dimension := range repo.Directory {

View File

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