Skip to content

Commit e551393

Browse files
authored
PMM-13575 use self label for agent metric (#1033)
* PMM-13575: add self label to agent status * tidy go mod * use own role to determine self-label
1 parent f26ffbf commit e551393

File tree

3 files changed

+132
-43
lines changed

3 files changed

+132
-43
lines changed

exporter/pbm_collector.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
"github.com/prometheus/client_golang/prometheus"
2626
"github.com/sirupsen/logrus"
2727
"go.mongodb.org/mongo-driver/mongo"
28+
29+
"github.com/percona/mongodb_exporter/internal/util"
2830
)
2931

3032
// pbm collector collects metrics from PBM (Percona Backup for MongoDb).
@@ -125,14 +127,19 @@ func (p *pbmCollector) collect(ch chan<- prometheus.Metric) {
125127
}
126128

127129
func (p *pbmCollector) pbmAgentMetrics(ctx context.Context, pbmClient *sdk.Client, l *logrus.Entry) []prometheus.Metric {
130+
currentNode, err := util.MyRole(ctx, p.base.client)
131+
if err != nil {
132+
l.Errorf("failed to get current node info: %s", err.Error())
133+
return nil
134+
}
135+
128136
clusterStatus, err := cli.ClusterStatus(ctx, pbmClient, cli.RSConfGetter(p.mongoURI))
129137
if err != nil {
130138
l.Errorf("failed to get cluster status: %s", err.Error())
131139
return nil
132140
}
133141

134142
metrics := make([]prometheus.Metric, 0, len(clusterStatus))
135-
136143
for replsetName, nodes := range clusterStatus {
137144
for _, node := range nodes {
138145
var pbmStatusMetric float64
@@ -146,14 +153,20 @@ func (p *pbmCollector) pbmAgentMetrics(ctx context.Context, pbmClient *sdk.Clien
146153
default: // !node.OK
147154
pbmStatusMetric = float64(pbmAgentStatusError)
148155
}
156+
labels := map[string]string{
157+
"host": node.Host,
158+
"replica_set": replsetName,
159+
"role": string(node.Role),
160+
"self": "0",
161+
}
162+
if node.Host == currentNode.Me {
163+
labels["self"] = "1"
164+
}
149165
metrics = append(metrics, createPBMMetric("agent_status",
150166
"PBM Agent Status",
151167
pbmStatusMetric,
152-
map[string]string{
153-
"host": node.Host,
154-
"replica_set": replsetName,
155-
"role": string(node.Role),
156-
}),
168+
labels,
169+
),
157170
)
158171
}
159172
}

go.mod

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ require github.com/foxcpp/go-mockdns v1.1.0
2222

2323
require github.com/hashicorp/go-version v1.7.0
2424

25-
require github.com/percona/percona-backup-mongodb v1.8.1-0.20241022111827-8d3ad8a6eb7a
25+
require github.com/percona/percona-backup-mongodb v1.8.1-0.20250218045950-7e9f38fe06ab
2626

2727
require (
2828
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.10.0 // indirect
2929
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2 // indirect
3030
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.3.1 // indirect
31-
github.com/aws/aws-sdk-go v1.55.1 // indirect
31+
github.com/aws/aws-sdk-go v1.55.5 // indirect
3232
github.com/beorn7/perks v1.0.1 // indirect
3333
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3434
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
35-
github.com/davecgh/go-spew v1.1.1 // indirect
36-
github.com/go-ini/ini v1.67.0 // indirect
35+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
36+
github.com/frankban/quicktest v1.14.6 // indirect
3737
github.com/golang/snappy v0.0.4 // indirect
3838
github.com/google/uuid v1.6.0 // indirect
3939
github.com/jessevdk/go-flags v1.5.0 // indirect
@@ -45,29 +45,27 @@ require (
4545
github.com/mdlayher/socket v0.4.1 // indirect
4646
github.com/mdlayher/vsock v1.2.1 // indirect
4747
github.com/miekg/dns v1.1.57 // indirect
48-
github.com/minio/minio-go v6.0.14+incompatible // indirect
49-
github.com/mitchellh/go-homedir v1.1.0 // indirect
5048
github.com/mongodb/mongo-tools v0.0.0-20240723193119-837c2bc263f4 // indirect
5149
github.com/montanaflynn/stats v0.7.1 // indirect
5250
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
5351
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
5452
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
55-
github.com/pmezard/go-difflib v1.0.0 // indirect
53+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
5654
github.com/prometheus/procfs v0.15.1 // indirect
5755
github.com/rogpeppe/go-internal v1.11.0 // indirect
5856
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
5957
github.com/xdg-go/scram v1.1.2 // indirect
6058
github.com/xdg-go/stringprep v1.0.4 // indirect
6159
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
62-
golang.org/x/crypto v0.32.0 // indirect
60+
golang.org/x/crypto v0.33.0 // indirect
6361
golang.org/x/exp v0.0.0-20240529005216-23cca8864a10 // indirect
6462
golang.org/x/mod v0.19.0 // indirect
65-
golang.org/x/net v0.33.0 // indirect
63+
golang.org/x/net v0.35.0 // indirect
6664
golang.org/x/oauth2 v0.24.0 // indirect
67-
golang.org/x/sync v0.10.0 // indirect
68-
golang.org/x/sys v0.29.0 // indirect
69-
golang.org/x/term v0.28.0 // indirect
70-
golang.org/x/text v0.21.0 // indirect
65+
golang.org/x/sync v0.11.0 // indirect
66+
golang.org/x/sys v0.30.0 // indirect
67+
golang.org/x/term v0.29.0 // indirect
68+
golang.org/x/text v0.22.0 // indirect
7169
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
7270
google.golang.org/protobuf v1.36.1 // indirect
7371
gopkg.in/yaml.v2 v2.4.0 // indirect

0 commit comments

Comments
 (0)