Skip to content

Commit 4c9222e

Browse files
committed
Allow use of server status collector with new flag
This is useful when running the exporter against mongos instances where getDiagnosticData is not available.
1 parent 30f9038 commit 4c9222e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

exporter/exporter.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type Opts struct {
6565
EnableDBStats bool
6666
EnableDiagnosticData bool
6767
EnableReplicasetStatus bool
68+
EnableServerStatus bool
6869
EnableTopMetrics bool
6970
EnableIndexStats bool
7071
EnableCollStats bool
@@ -168,6 +169,7 @@ func (e *Exporter) makeRegistry(ctx context.Context, client *mongo.Client, topol
168169
e.opts.EnableCollStats = true
169170
e.opts.EnableTopMetrics = true
170171
e.opts.EnableReplicasetStatus = true
172+
e.opts.EnableServerStatus = true
171173
e.opts.EnableIndexStats = true
172174
}
173175

@@ -221,6 +223,12 @@ func (e *Exporter) makeRegistry(ctx context.Context, client *mongo.Client, topol
221223
registry.MustRegister(rsgsc)
222224
}
223225

226+
if e.opts.EnableServerStatus {
227+
ssc := newServerStatusCollector(ctx, client, e.opts.Logger,
228+
e.opts.CompatibleMode, topologyInfo)
229+
registry.MustRegister(ssc)
230+
}
231+
224232
return registry
225233
}
226234

@@ -282,6 +290,8 @@ func (e *Exporter) Handler() http.Handler {
282290
requestOpts.EnableDiagnosticData = true
283291
case "replicasetstatus":
284292
requestOpts.EnableReplicasetStatus = true
293+
case "serverstatus":
294+
requestOpts.EnableServerStatus = true
285295
case "dbstats":
286296
requestOpts.EnableDBStats = true
287297
case "topmetrics":

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type GlobalFlags struct {
4747

4848
EnableDiagnosticData bool `name:"collector.diagnosticdata" help:"Enable collecting metrics from getDiagnosticData"`
4949
EnableReplicasetStatus bool `name:"collector.replicasetstatus" help:"Enable collecting metrics from replSetGetStatus"`
50+
EnableServerStatus bool `name:"collector.serverstatus" help:"Enable collecting metrics from serverStatus"`
5051
EnableDBStats bool `name:"collector.dbstats" help:"Enable collecting metrics from dbStats"`
5152
EnableTopMetrics bool `name:"collector.topmetrics" help:"Enable collecting metrics from top admin command"`
5253
EnableIndexStats bool `name:"collector.indexstats" help:"Enable collecting metrics from $indexStats"`
@@ -125,6 +126,7 @@ func buildExporter(opts GlobalFlags) *exporter.Exporter {
125126

126127
EnableDiagnosticData: opts.EnableDiagnosticData,
127128
EnableReplicasetStatus: opts.EnableReplicasetStatus,
129+
EnableServerStatus: opts.EnableServerStatus,
128130
EnableTopMetrics: opts.EnableTopMetrics,
129131
EnableDBStats: opts.EnableDBStats,
130132
EnableIndexStats: opts.EnableIndexStats,

0 commit comments

Comments
 (0)