prometheus prefix

This commit is contained in:
rasmus 2022-11-06 17:02:49 +02:00
parent b323e34ff2
commit 28a518be7f
3 changed files with 18 additions and 4 deletions

View File

@ -26,8 +26,9 @@ import (
) )
const ( const (
MACHINEID = "/etc/machine-id" MachineId = "/etc/machine-id"
MONGO_TIMEOUT = 10 * time.Second MongoTimeout = 10 * time.Second
PrometheusPrefix = "logmower-shipper"
) )
// wrapper to force copying before use // wrapper to force copying before use
@ -41,7 +42,7 @@ func defaultBackoff() wait.Backoff {
} }
func mongoTimeoutCtx(ctx context.Context) context.Context { func mongoTimeoutCtx(ctx context.Context) context.Context {
ctx, _ = context.WithTimeout(ctx, MONGO_TIMEOUT) //nolint:lostcancel (cancelled by mongo, should be bug on them //TODO) ctx, _ = context.WithTimeout(ctx, MongoTimeout) //nolint:lostcancel (cancelled by mongo, should be bug on them //TODO)
return ctx return ctx
} }
@ -78,17 +79,20 @@ var App = &cli.App{
var ( var (
promWatcherOnline = promauto.NewGauge(prom.GaugeOpts{ promWatcherOnline = promauto.NewGauge(prom.GaugeOpts{
Namespace: PrometheusPrefix,
Subsystem: "watcher", Subsystem: "watcher",
Name: "online", Name: "online",
Help: "1 if initialized, and directory watcher has been engaged successfully", Help: "1 if initialized, and directory watcher has been engaged successfully",
}) })
promErrWatching = promauto.NewCounter(prom.CounterOpts{ promErrWatching = promauto.NewCounter(prom.CounterOpts{
Namespace: PrometheusPrefix,
Subsystem: "watcher", Subsystem: "watcher",
Name: "errors", Name: "errors",
Help: "Error in logmower watching log files", Help: "Error in logmower watching log files",
}) })
promFilesRead = promauto.NewCounter(prom.CounterOpts{ promFilesRead = promauto.NewCounter(prom.CounterOpts{
Namespace: PrometheusPrefix,
Subsystem: "watcher", Subsystem: "watcher",
Name: "seen_files", Name: "seen_files",
Help: "Number of tracked log files", Help: "Number of tracked log files",
@ -214,7 +218,7 @@ func getHostInfo(nodeName string) (h HostInfo, err error) {
} }
h.name = strings.TrimSpace(nodeName) h.name = strings.TrimSpace(nodeName)
id, errL := os.ReadFile(MACHINEID) id, errL := os.ReadFile(MachineId)
if errL != nil { if errL != nil {
err = errAppend(err, fmt.Errorf("id: %w", errL)) err = errAppend(err, fmt.Errorf("id: %w", errL))
} }

View File

@ -13,26 +13,31 @@ import (
var ( var (
promShipperMongoSent = promauto.NewCounterVec(prom.CounterOpts{ promShipperMongoSent = promauto.NewCounterVec(prom.CounterOpts{
Namespace: PrometheusPrefix,
Subsystem: "shipper", Subsystem: "shipper",
Name: "sent", Name: "sent",
Help: "Log lines successfully committed to mongo", Help: "Log lines successfully committed to mongo",
}, []string{"filename"}) }, []string{"filename"})
promShipperMongoSentError = promauto.NewCounterVec(prom.CounterOpts{ promShipperMongoSentError = promauto.NewCounterVec(prom.CounterOpts{
Namespace: PrometheusPrefix,
Subsystem: "shipper", Subsystem: "shipper",
Name: "mongo_errors", Name: "mongo_errors",
Help: "Errors while submitting to mongo", // TODO: Help: "Errors while submitting to mongo", // TODO:
}, []string{"filename"}) }, []string{"filename"})
promLineParsingErr = promauto.NewCounterVec(prom.CounterOpts{ promLineParsingErr = promauto.NewCounterVec(prom.CounterOpts{
Namespace: PrometheusPrefix,
Subsystem: "shipper", Subsystem: "shipper",
Name: "lines_parsing_errors", Name: "lines_parsing_errors",
Help: "Errors while parsing log line suffixes", Help: "Errors while parsing log line suffixes",
}, []string{"filename"}) }, []string{"filename"})
promShipperQueued = promauto.NewGaugeVec(prom.GaugeOpts{ promShipperQueued = promauto.NewGaugeVec(prom.GaugeOpts{
Namespace: PrometheusPrefix,
Subsystem: "shipper", Subsystem: "shipper",
Name: "queued", Name: "queued",
Help: "Log lines in queue to be batched and sent to mongo", Help: "Log lines in queue to be batched and sent to mongo",
}, []string{"filename"}) }, []string{"filename"})
promShipperSynced = promauto.NewGaugeVec(prom.GaugeOpts{ promShipperSynced = promauto.NewGaugeVec(prom.GaugeOpts{
Namespace: PrometheusPrefix,
Subsystem: "shipper", Subsystem: "shipper",
Name: "batches_synced", Name: "batches_synced",
Help: "All batches available have been sent to mongo", Help: "All batches available have been sent to mongo",
@ -46,6 +51,7 @@ const (
func init() { func init() {
promauto.NewGaugeFunc(prom.GaugeOpts{ promauto.NewGaugeFunc(prom.GaugeOpts{
Namespace: PrometheusPrefix,
Subsystem: "shipper", Subsystem: "shipper",
Name: "queue_size", Name: "queue_size",
Help: "Submit queue size cap", Help: "Submit queue size cap",
@ -53,6 +59,7 @@ func init() {
return float64(SendQueueLimit) return float64(SendQueueLimit)
}) })
promauto.NewGaugeFunc(prom.GaugeOpts{ promauto.NewGaugeFunc(prom.GaugeOpts{
Namespace: PrometheusPrefix,
Subsystem: "shipper", Subsystem: "shipper",
Name: "batch_size", Name: "batch_size",
Help: "batching size cap", Help: "batching size cap",
@ -60,6 +67,7 @@ func init() {
return float64(MaxBatchItems) return float64(MaxBatchItems)
}) })
promauto.NewGaugeFunc(prom.GaugeOpts{ promauto.NewGaugeFunc(prom.GaugeOpts{
Namespace: PrometheusPrefix,
Subsystem: "shipper", Subsystem: "shipper",
Name: "batch_time", Name: "batch_time",
Help: "batching delay cap", Help: "batching delay cap",

View File

@ -23,11 +23,13 @@ import (
var ( var (
promCatchupDone = promauto.NewGaugeVec(prom.GaugeOpts{ promCatchupDone = promauto.NewGaugeVec(prom.GaugeOpts{
Namespace: PrometheusPrefix,
Subsystem: "file", Subsystem: "file",
Name: "catchupped", Name: "catchupped",
Help: "Files where initial backlog has been sent; (total <= watcher_file_count)", Help: "Files where initial backlog has been sent; (total <= watcher_file_count)",
}, []string{"filename"}) // TODO: rm filename? }, []string{"filename"}) // TODO: rm filename?
promFileErr = promauto.NewCounterVec(prom.CounterOpts{ promFileErr = promauto.NewCounterVec(prom.CounterOpts{
Namespace: PrometheusPrefix,
Subsystem: "file", Subsystem: "file",
Name: "errors_count", Name: "errors_count",
Help: "Error count for reading files", Help: "Error count for reading files",