Implement metrics and cli

This commit is contained in:
2022-09-12 00:15:47 +02:00
parent 620cef3310
commit ebc15cb394
338 changed files with 93223 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package cleaner
import (
"fmt"
"github.com/cyrilix/pod-cleaner/pkg/metrics"
"github.com/cyrilix/pod-cleaner/pkg/monitor"
"go.uber.org/zap"
"regexp"
@ -34,6 +35,17 @@ type PodWatcher struct {
podIdErrors string
}
func (w *PodWatcher) Close() error {
close(w.cancel)
if w.m != nil {
err := w.m.Close()
if err != nil {
zap.S().Errorf("unable to close monitor resource: %v", err)
}
}
return nil
}
func (w *PodWatcher) GetNumErrors() int {
w.muPodError.RLock()
defer w.muPodError.RUnlock()
@ -79,4 +91,6 @@ func (w *PodWatcher) processLogRecord(line string) {
defer w.muPodError.Unlock()
w.numErrors = numErrors
w.podIdErrors = w.rex.FindStringSubmatch(line)[w.rex.SubexpIndex("podId")]
metrics.NumErrors.Set(float64(numErrors))
}

17
pkg/metrics/metrics.go Normal file
View File

@ -0,0 +1,17 @@
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var (
NumErrors = promauto.NewGauge(
prometheus.GaugeOpts{
Namespace: "infra",
Subsystem: "pod_cleaner",
Name: "orphans_pod_error_count",
Help: "Number of orphan pods that failed to be cleaned",
},
)
)