Skip to content

Commit

Permalink
Fix Cluster and Replica Set labels in Metrics (#394)
Browse files Browse the repository at this point in the history
## Issue
Cluster and replica set labels in Grafana showed None

## Solution
Update how we scrape those configs

---------

Co-authored-by: Ubuntu <ubuntu@ip-172-31-17-108.eu-central-1.compute.internal>
  • Loading branch information
MiaAltieri and Ubuntu committed Apr 8, 2024
1 parent 44223eb commit c00e06d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,30 @@ def __init__(self, *args):
# relation events for Prometheus metrics are handled in the MetricsEndpointProvider
self._grafana_agent = COSAgentProvider(
self,
metrics_endpoints=Config.Monitoring.METRICS_ENDPOINTS,
metrics_rules_dir=Config.Monitoring.METRICS_RULES_DIR,
logs_rules_dir=Config.Monitoring.LOGS_RULES_DIR,
log_slots=Config.Monitoring.LOG_SLOTS,
scrape_configs=self._mongo_scrape_config,
)

self.secrets = SecretCache(self)

# BEGIN: properties
def _mongo_scrape_config(self) -> List[Dict]:
"""Generates scrape config for the mongo metrics endpoint."""
return [
{
"metrics_path": "/metrics",
"static_configs": [
{
"targets": [
f"{self._unit_ip(self.unit)}:{Config.Monitoring.MONGODB_EXPORTER_PORT}"
],
"labels": {"cluster": self.app.name, "replication_set": self.app.name},
}
],
}
]

@property
def primary(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/grafana_dashboards/MongoDB_ReplSet_Summary.json
Original file line number Diff line number Diff line change
Expand Up @@ -2810,7 +2810,7 @@
"label": "Replica Set",
"multi": false,
"multiFormat": "glob",
"name": "replset",
"name": "replication_set",
"options": [],
"query": {
"query": "label_values(mongodb_mongod_replset_my_state{cluster=~\"$cluster\"}, set)",
Expand Down

0 comments on commit c00e06d

Please sign in to comment.