File: backrest_repo_metrics.go

package info (click to toggle)
prometheus-pgbackrest-exporter 0.19.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 480 kB
  • sloc: sh: 141; makefile: 136
file content (60 lines) | stat: -rw-r--r-- 1,400 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package backrest

import (
	"strconv"

	"github.com/go-kit/log"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promauto"
)

var pgbrRepoStatusMetric = promauto.NewGaugeVec(prometheus.GaugeOpts{
	Name: "pgbackrest_repo_status",
	Help: "Current repository status.",
},
	[]string{
		"cipher",
		"repo_key",
		"stanza",
	})

// Set repo metrics:
//   - pgbackrest_repo_status
func getRepoMetrics(stanzaName string, repoData *[]repo, setUpMetricValueFun setUpMetricValueFunType, logger log.Logger) {
	// Repo status.
	// The same statuses as for stanza.
	// For pgBackRest < v2.32 repo info is not available.
	// To avoid flapping this metric, set up metric with value 0 (ok) and repo_key="0":
	//   pgbackrest_repo_status{cipher="none",repo_key="0",stanza="stanza_name"} 0
	defaultMetricRepoKey := "0"
	defaultMetricCipher := "none"
	if repoData != nil {
		for _, repo := range *repoData {
			setUpMetric(
				pgbrRepoStatusMetric,
				"pgbackrest_repo_status",
				float64(repo.Status.Code),
				setUpMetricValueFun,
				logger,
				repo.Cipher,
				strconv.Itoa(repo.Key),
				stanzaName,
			)
		}
	} else {
		setUpMetric(
			pgbrRepoStatusMetric,
			"pgbackrest_repo_status",
			0,
			setUpMetricValueFun,
			logger,
			defaultMetricCipher,
			defaultMetricRepoKey,
			stanzaName,
		)
	}
}

func resetRepoMetrics() {
	pgbrRepoStatusMetric.Reset()
}