Skip to content

Commit b077391

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 1740a06 commit b077391

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
@@ -158,6 +159,7 @@ func (e *Exporter) makeRegistry(ctx context.Context, client *mongo.Client, topol
158159
e.opts.EnableCollStats = true
159160
e.opts.EnableTopMetrics = true
160161
e.opts.EnableReplicasetStatus = true
162+
e.opts.EnableServerStatus = true
161163
e.opts.EnableIndexStats = true
162164
}
163165

@@ -202,6 +204,12 @@ func (e *Exporter) makeRegistry(ctx context.Context, client *mongo.Client, topol
202204
registry.MustRegister(rsgsc)
203205
}
204206

207+
if e.opts.EnableServerStatus {
208+
ssc := newServerStatusCollector(ctx, client, e.opts.Logger,
209+
e.opts.CompatibleMode, topologyInfo)
210+
registry.MustRegister(ssc)
211+
}
212+
205213
return registry
206214
}
207215

@@ -263,6 +271,8 @@ func (e *Exporter) Handler() http.Handler {
263271
requestOpts.EnableDiagnosticData = true
264272
case "replicasetstatus":
265273
requestOpts.EnableReplicasetStatus = true
274+
case "serverstatus":
275+
requestOpts.EnableServerStatus = true
266276
case "dbstats":
267277
requestOpts.EnableDBStats = true
268278
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)