Skip to content

Commit 5339cd5

Browse files
committed
✨ New prometheus metrics to reflect cluster status
1 parent 13f2422 commit 5339cd5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pkg/cluster/sync.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"reflect"
8+
"github.com/prometheus/client_golang/prometheus"
89
"regexp"
910
"strings"
1011
"time"
@@ -20,6 +21,20 @@ import (
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
)
2223

24+
var(
25+
pgStatus = prometheus.NewGaugeVec(
26+
prometheus.GaugeOpts{
27+
Name: "pg_sync_status",
28+
Help: "Postgres sync status (1 = ok, 0 = error).",
29+
},
30+
[]string{"namespace", "clusterName"},
31+
)
32+
)
33+
34+
func init() {
35+
prometheus.MustRegister(pgStatus)
36+
}
37+
2338
// Sync syncs the cluster, making sure the actual Kubernetes objects correspond to what is defined in the manifest.
2439
// Unlike the update, sync does not error out if some objects do not exist and takes care of creating them.
2540
func (c *Cluster) Sync(newSpec *acidv1.Postgresql) error {
@@ -31,7 +46,10 @@ func (c *Cluster) Sync(newSpec *acidv1.Postgresql) error {
3146
c.setSpec(newSpec)
3247

3348
defer func() {
49+
labels := prometheus.Labels{"namespace":c.clusterName().Namespace,"clusterName":c.clusterName().Name}
50+
pgStatus.With(labels).Set(1)
3451
if err != nil {
52+
pgStatus.With(labels).Set(0)
3553
c.logger.Warningf("error while syncing cluster state: %v", err)
3654
c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusSyncFailed)
3755
} else if !c.Status.Running() {

0 commit comments

Comments
 (0)