Monitor MongoDB Databases
11 min
overview this tutorial demonstrates how to view metrics for mongodb enterprise clusters the grafana https //grafana com/grafana instance, which is connected to the logging service https //docs ionos com/cloud/observability/logging service pipeline, is used to provide the data visualization of the metrics by collecting metrics with a monitoring system, such as prometheus through the official mongodb exporter, and visualizing them in a grafana dashboard, you can instantly detect anomalies, set proactive alerts on sla critical thresholds, troubleshoot latency or contention issues, and plan capacity upgrades with data driven confidence mongodb offers a set of observable metrics that describe the following server’s health and performance replication state—from low‑level resource usage such as cpu, memory, disk i/o, and network server‑wide counters such as connections, operations per second, cache hits, and page faults detailed replica‑set statistics such as election timestamps, primary‑secondary lag, and write‑concern success rates per‑command activity such as query, insert, update, delete, getmore, and lock counts mongodb metrics turn raw runtime data into actionable insight, enabling reliable operations, faster incident resolution, and efficient resource utilization for any production deployment metrics for mongodb the following metrics are offered to gauge the health of the mongodb clusters cpu and memory metric description ionos dbaas mongodb cpu rate5m an average cpu usage of the cluster over 5 minutes it displays how much processor capacity the database is using monitor this metric to gauge if the cpu usage is operating closer to its resource limits ionos dbaas mongodb memory total bytes the maximum memory allocated values, measured in bytes it refers to the fixed memory limit for the instance ionos dbaas mongodb memory available bytes the remaining free memory in the cluster, measured in bytes a lower value indicates that the database has limited available memory storage and disk metric description ionos dbaas mongodb storage total bytes the maximum storage capacity allocated values in bytes ionos dbaas mongodb storage available bytes the remaining free storage space in the cluster, measured in bytes a lower value indicates that the database has limited available storage ionos dbaas mongodb disk io time weighted seconds rate5m the average time the disk spends handling read or write operations a higher value indicates that the disk is busy connections and health metric description ionos dbaas mongodb connections count the total number of active client connections to the cluster if the value is near the maximum count, new connections may fail monitor connections to determine whether the current connection limits are sufficient ionos dbaas mongodb health indicates whether the cluster is healthy or not if the value is 1, the cluster is considered healthy; if the value is 0, the cluster is considered unhealthy query patterns metric description ionos dbaas mongodb scan and order rate5m scans and orders data using an in memory sort it is averaged over a 5 minute window monitor this metric to determine whether your queries need indexes indexes metric description ionos dbaas mongodb index count total the total number of indexes across collections monitor this metric to review unused indexes and free up memory and disk space ionos dbaas mongodb index size bytes the total disk size of all indexes in the database, measured in bytes monitor this metric to manage your indexes cluster or replica set state metric description ionos dbaas mongodb instance count the total number of mongodb instances, which together form a replica set if the count is lower, then a node may be down ionos dbaas mongodb member state the state of the replica set member if the value is 1, it is in a primary state, and a value of 2 indicates it is in a secondary state replication or oplog metric description ionos dbaas mongodb oplog size bytes the size of the operations log, measured in bytes it stores recent database changes, which act as a buffer to create replicas monitor this metric to ensure it is not smaller than the write activity, as this may lead to replication delays ionos dbaas mongodb oplog window seconds the time span of the operations logs up to where the replicas are possible it is measured in seconds monitor this metric to ensure the operations log window is not too short, as this can cause replication to slow down ionos dbaas mongodb replication headroom seconds the maximum replication lag, measured in seconds, among all secondary members in a mongodb replica set this metric indicates how far behind the most delayed secondary is compared to the primary monitor this metric to keep replication lag minimal and ensure data consistency and reliable failover behavior across the replica set ionos dbaas mongodb replication lag seconds the delay between the primary and secondary copies of data is measured in seconds monitor this metric to spot any slow or unhealthy secondaries early on and ensure read‑consistency, and trigger alerts or scaling actions before replication delays affect application performance or data‑loss risk ionos dbaas mongodb replication last election timestamp seconds the time when the most recent primary election occurred in the mongodb replica set, measured in seconds monitor this metric to detect unexpected failovers and trigger alerts or investigations before they impact application availability top operations (per 5m) window metric description ionos dbaas mongodb top commands count the number of active mongodb command operations monitor this metric to spot workload spikes or long running queries ionos dbaas mongodb top getmore count the number of active getmore operations on each mongodb node monitor this metric to detect any heavy cursor paging workloads ionos dbaas mongodb top insert count the number of active insert operations on each mongodb node monitor this metric to identify any bulk inserts ionos dbaas mongodb top queries count the number of active query operations per mongodb node monitor this metric to identify long running queries and tune indexes ionos dbaas mongodb top readlock count the number of active operations that hold a readlock on each mongodb node monitor this metric to identify read heavy operations and optimize query patterns ionos dbaas mongodb top remove count the number of active remove or delete operations on each mongodb node monitor this metric to identify workloads that need to be deleted ionos dbaas mongodb top total count the total number of active operations of all types, such as queries, inserts, updates, deletes, and so on monitor this metric to obtain a health snapshot of overall workload intensity ionos dbaas mongodb top update count the number of active update operations on each mongodb node monitor this metric to identify any workloads that are particularly update heavy ionos dbaas mongodb top writelock count the number of operations holding a write lock on each mongodb node monitor this metric to detect any write lock contentions and adjust indexes accordingly target audience this tutorial is intended to help both developers and technical decision makers what you will learn by following this tutorial, you will learn how to access mongodb cluster metrics using grafana understand key mongodb performance and health metrics configure grafana to visualize mongodb metrics set up authentication for secure metric access explore and interpret mongodb metrics for monitoring and troubleshooting before you begin you need to activate the logging service https //docs ionos com/cloud/observability/logging service to create the necessary setup to view the grafana dashboard to do so, create a logging pipeline https //docs ionos com/cloud/observability/logging service/dcd how tos/create logging service pipeline this establishes a successful logging pipeline connection you can view the created logging pipeline in the logging service page for more information, see view logging pipelines https //docs ionos com/cloud/observability/logging service/dcd how tos/view logging pipelines cost considerations the following resources outlined in this tutorial are billable and will incur costs when used storage or retention retaining data for extended periods and using metrics with many distinct label values increases storage usage for more information, see prices https //docs ionos com/cloud/support/general information/price list/ionos cloud eur en#ionos cloud object storage image or asset hosting for documentation at scale, storing and delivering images or assets through a cdn may incur additional costs authentication token management token issuance is free; it incurs operational overhead only to set up cost alerts and estimate costs based on your traffic, see cost alert https //docs ionos com/cloud/set up ionos cloud/management/usage/cost alert and cost & usage https //docs ionos com/cloud/set up ionos cloud/management/usage/cost and usage procedure use the following procedure to access the mongodb metrics using grafana open grafana dashboard 1 from the logging service page, click grafana dashboard the url to the grafana sign in page opens in the browser 2 click sign in with ionos from the grafana sign in page 3 use the data center designer (dcd) single sign on (sso) credentials and click sign in configure the data source 1 from the grafana home page, on the left hand menu, go to connections > data sources 2 from the data sources page, select ionos telemetry 3 in the settings tab, go to the authentication section > http headers 4 select add header you need to add an authorization header with a bearer token to do so, configure the following header in this field, enter authorization value obtain the bearer token value from the token manager section in the dcd and prefix bearer before the token value and add it here for more information, see generate authentication token https //docs ionos com/cloud/set up ionos cloud/management/identity access management/token manager#generate authentication token 5 in the other section, select the http method as get 6 click save & test , available at the end of the settings page view mongodb database metrics 1 from the grafana home page, on the left hand menu, go to explore > metrics 2 select let's start! to start metrics exploration and choose ionos telemetry as the data source 3 in the search metrics , type the keywords such as mongodb to view metrics related to mongodb final result the metrics for mongodb clusters are successfully available in the grafana dashboard for details on the metrics available, see metrics for mongodb https //docs ionos com/cloud/tutorials/databases/mongodb/monitor mongodb databases#metrics for mongodb conclusion mongodb cluster metrics are accessible through the grafana dashboard this functionality is available when a logging pipeline connection is established and the cluster is active within your contract alternatively, you can deploy and configure their own grafana instance in this case, establishing a logging pipeline connection is not required instead, you can directly configure the appropriate data sources in grafana to visualize and monitor mongodb cluster metrics
