Skip to content

Commit

Permalink
enable mongodb metrics collection and whitelisting (#299)
Browse files Browse the repository at this point in the history
* enable mongodb metrics collection and whitelisting

* [MONGO-2670] Better flag help message for mongodb metrics collection

* [MONGO-2670] Add collector and aggregation spec

---------

Co-authored-by: Govind Srinivasaraghavan <[email protected]>
  • Loading branch information
dragon9786 and dragon9786 authored May 3, 2023
1 parent 46d9ffa commit 4bcc0f8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/do-agent/aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ var k8sAggregationSpec = map[string][]string{
"kube_statefulset_replicas": {"statefulset", "namespace"},
"kube_statefulset_status_replicas_ready": {"statefulset", "namespace"},
}

var mongoAggregationSpec = map[string][]string{
"mongodb_data_usage_percentage": {"cluster_uuid"},
}
20 changes: 20 additions & 0 deletions cmd/do-agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
noNode bool
kubernetes string
dbaas string
mongodb string
webListenAddress string
webListen bool
additionalLabels []string
Expand Down Expand Up @@ -116,6 +117,9 @@ func init() {
kingpin.Flag("dbaas-metrics-path", "enable DO DBAAS metrics collection (this must be a DO DBAAS metrics endpoint)").
StringVar(&config.dbaas)

kingpin.Flag("mongodb-metrics-path", "enable DO DBAAS MongoDB metrics collection (this must be a DO DBAAS metrics endpoint)").
StringVar(&config.mongodb)

kingpin.Flag("metrics-path", "enable metrics collection from a prometheus endpoint").
StringVar(&config.promAddr)

Expand Down Expand Up @@ -230,6 +234,13 @@ func initAggregatorSpecs() map[string][]string {
}
}

if config.mongodb != "" {
for k, v := range mongoAggregationSpec {
aggregateSpecs[k] = append(aggregateSpecs[k], v...)
}

}

if config.kubernetes != "" {
for k, v := range k8sAggregationSpec {
aggregateSpecs[k] = append(aggregateSpecs[k], v...)
Expand Down Expand Up @@ -292,6 +303,15 @@ func initCollectors() []prometheus.Collector {
}
}

if config.mongodb != "" {
k, err := collector.NewScraper("mongodb", config.mongodb, nil, dbaasWhitelist, collector.WithTimeout(config.scrapeTimeout))
if err != nil {
log.Error("Failed to initialize DO DBaaS MongoDB metrics collector: %+v", err)
} else {
cols = append(cols, k)
}
}

if config.promAddr != "" {
k, err := collector.NewScraper("prometheus", config.promAddr, nil, nil, collector.WithTimeout(config.scrapeTimeout))
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/do-agent/whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ var dbaasWhitelist = map[string]bool{
"postgresql_pg_stat_database_xact_rollback": true,
"postgresql_database_size_database_size": true,

"mongodb_data_usage_percentage": true,

"mysql_threads_created": true,
"mysql_threads_connected": true,
"mysql_threads_running": true,
Expand Down

0 comments on commit 4bcc0f8

Please sign in to comment.