File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 55 "encoding/json"
66 "fmt"
77 "reflect"
8+ "github.com/prometheus/client_golang/prometheus"
89 "regexp"
910 "strconv"
1011 "strings"
@@ -27,6 +28,19 @@ var requireMasterRestartWhenDecreased = []string{
2728 "max_locks_per_transaction" ,
2829 "max_worker_processes" ,
2930 "max_wal_senders" ,
31+
32+ var (
33+ pgStatus = prometheus .NewGaugeVec (
34+ prometheus.GaugeOpts {
35+ Name : "pg_sync_status" ,
36+ Help : "Postgres sync status (1 = ok, 0 = error)." ,
37+ },
38+ []string {"namespace" , "clusterName" },
39+ )
40+ )
41+
42+ func init () {
43+ prometheus .MustRegister (pgStatus )
3044}
3145
3246// Sync syncs the cluster, making sure the actual Kubernetes objects correspond to what is defined in the manifest.
@@ -40,7 +54,10 @@ func (c *Cluster) Sync(newSpec *acidv1.Postgresql) error {
4054 c .setSpec (newSpec )
4155
4256 defer func () {
57+ labels := prometheus.Labels {"namespace" :c .clusterName ().Namespace ,"clusterName" :c .clusterName ().Name }
58+ pgStatus .With (labels ).Set (1 )
4359 if err != nil {
60+ pgStatus .With (labels ).Set (0 )
4461 c .logger .Warningf ("error while syncing cluster state: %v" , err )
4562 c .KubeClient .SetPostgresCRDStatus (c .clusterName (), acidv1 .ClusterStatusSyncFailed )
4663 } else if ! c .Status .Running () {
You can’t perform that action at this time.
0 commit comments