6
6
import logging
7
7
import re
8
8
import time
9
- from typing import Dict , List , Optional , Set
9
+ from typing import Any , Dict , List , Optional , Set
10
10
11
11
import jinja2
12
12
from charms .grafana_k8s .v0 .grafana_dashboard import GrafanaDashboardProvider
@@ -126,8 +126,14 @@ def __init__(self, *args):
126
126
self .tls = MongoDBTLS (self , Config .Relations .PEERS , Config .SUBSTRATE )
127
127
self .backups = MongoDBBackups (self )
128
128
129
+ self .status = MongoDBStatusHandler (self )
130
+ self .secrets = SecretCache (self )
131
+
132
+ self .shard = ConfigServerRequirer (self )
133
+ self .config_server = ShardingProvider (self )
134
+ self .cluster = ClusterProvider (self )
129
135
self .metrics_endpoint = MetricsEndpointProvider (
130
- self , refresh_event = self .on .start , jobs = Config . Monitoring . JOBS
136
+ self , refresh_event = [ self .on .start , self . on . update_status ], jobs = self . monitoring_jobs
131
137
)
132
138
self .grafana_dashboards = GrafanaDashboardProvider (self )
133
139
self .loki_push = LogProxyConsumer (
@@ -136,12 +142,6 @@ def __init__(self, *args):
136
142
relation_name = Config .Relations .LOGGING ,
137
143
container_name = Config .CONTAINER_NAME ,
138
144
)
139
- self .status = MongoDBStatusHandler (self )
140
- self .secrets = SecretCache (self )
141
-
142
- self .shard = ConfigServerRequirer (self )
143
- self .config_server = ShardingProvider (self )
144
- self .cluster = ClusterProvider (self )
145
145
146
146
self .version_checker = CrossAppVersionChecker (
147
147
self ,
@@ -154,6 +154,20 @@ def __init__(self, *args):
154
154
155
155
# BEGIN: properties
156
156
157
+ @property
158
+ def monitoring_jobs (self ) -> list [dict [str , Any ]]:
159
+ """Defines the labels and targets for metrics."""
160
+ return [
161
+ {
162
+ "static_configs" : [
163
+ {
164
+ "targets" : [f"*:{ Config .Monitoring .MONGODB_EXPORTER_PORT } " ],
165
+ "labels" : {"cluster" : self .get_config_server_name () or self .app .name },
166
+ }
167
+ ]
168
+ }
169
+ ]
170
+
157
171
@property
158
172
def app_hosts (self ) -> List [str ]:
159
173
"""Retrieve IP addresses associated with MongoDB application.
0 commit comments