From 4bdfc5c4994d265cda52cb0f473d023b0bdee665 Mon Sep 17 00:00:00 2001
From: Shashank Saxena <smaller-branch0h@icloud.com>
Date: Wed, 30 Oct 2024 00:15:03 +0530
Subject: [PATCH] Adding MongoDB Atlas Collstats + DB Stats metrics (#2491)

* Updating metadata csv by adding db stats and collstats metrics

* Fixing typo

* Fixing orientation field

* Fixing some more fields

* Using object instead of collection

* Ran metadata validation locally

* Using table instead of object after internal discussion

* Updating ownership information

* Adding new dashboard and adding descriptions to metrics

* Adding new dashboard and adding descriptions to metrics

* Adding dashboard to manifest.json
---
 .github/CODEOWNERS                            |   2 +-
 ...oDB-Atlas-dbStats-collStats_dashboard.json | 231 ++++++++++++++++++
 mongodb_atlas/manifest.json                   |  11 +-
 mongodb_atlas/metadata.csv                    |  32 ++-
 4 files changed, 269 insertions(+), 7 deletions(-)
 create mode 100644 mongodb_atlas/assets/dashboards/MongoDB-Atlas-dbStats-collStats_dashboard.json

diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index ea0f02f195..4733eba6ab 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -114,7 +114,7 @@
 /loadrunner_professional/                @mihneavelinOT
 /logstash/                               @ervansetiawan ervansetiawan@gmail.com
 /logzio/                                 @DataDog/agent-integrations
-/mongodb_atlas/                          @DataDog/saas-integrations
+/mongodb_atlas/                          @Salil999 frank.sun@mongodb.com tonya.edmonds@mongodb.com
 /moovingon_ai/                           @tomm24 info@moovingon.com
 /modal/                                  @modal-labs support@modal.com @irfansharif irfan@modal.com
 /mendix/                                 @mendix/cloud @DataDog/agent-integrations @DataDog/ecosystems-review
diff --git a/mongodb_atlas/assets/dashboards/MongoDB-Atlas-dbStats-collStats_dashboard.json b/mongodb_atlas/assets/dashboards/MongoDB-Atlas-dbStats-collStats_dashboard.json
new file mode 100644
index 0000000000..9ad33921da
--- /dev/null
+++ b/mongodb_atlas/assets/dashboards/MongoDB-Atlas-dbStats-collStats_dashboard.json
@@ -0,0 +1,231 @@
+{
+  "description": null,
+  "layout_type": "ordered",
+  "notify_list": [],
+  "reflow_type": "fixed",
+  "template_variables": [],
+  "title": "DB Stats + Collstats Dashboard",
+  "widgets": [
+    {
+      "definition": {
+        "background_color": "vivid_green",
+        "layout_type": "ordered",
+        "show_title": true,
+        "title": "dbStats",
+        "type": "group",
+        "widgets": [
+          {
+            "definition": {
+              "autoscale": true,
+              "precision": 0,
+              "requests": [
+                {
+                  "formulas": [
+                    {
+                      "formula": "query1"
+                    }
+                  ],
+                  "queries": [
+                    {
+                      "aggregator": "avg",
+                      "data_source": "metrics",
+                      "name": "query1",
+                      "query": "avg:mongodb.atlas.dbstats.collections{*}"
+                    }
+                  ],
+                  "response_format": "scalar"
+                }
+              ],
+              "title": "# of collections",
+              "title_align": "left",
+              "title_size": "16",
+              "type": "query_value"
+            },
+            "id": 1906095404858910,
+            "layout": {
+              "height": 3,
+              "width": 4,
+              "x": 0,
+              "y": 0
+            }
+          },
+          {
+            "definition": {
+              "autoscale": true,
+              "precision": 2,
+              "requests": [
+                {
+                  "formulas": [
+                    {
+                      "formula": "query1",
+                      "number_format": {
+                        "unit": {
+                          "type": "canonical_unit",
+                          "unit_name": "byte"
+                        }
+                      }
+                    }
+                  ],
+                  "queries": [
+                    {
+                      "aggregator": "avg",
+                      "data_source": "metrics",
+                      "name": "query1",
+                      "query": "avg:mongodb.atlas.dbstats.avg.object.size{*}"
+                    }
+                  ],
+                  "response_format": "scalar"
+                }
+              ],
+              "title": "avg object size",
+              "title_align": "left",
+              "title_size": "16",
+              "type": "query_value"
+            },
+            "id": 3604488985938846,
+            "layout": {
+              "height": 3,
+              "width": 4,
+              "x": 4,
+              "y": 0
+            }
+          },
+          {
+            "definition": {
+              "autoscale": true,
+              "precision": 2,
+              "requests": [
+                {
+                  "formulas": [
+                    {
+                      "formula": "query1",
+                      "number_format": {
+                        "unit": {
+                          "type": "canonical_unit",
+                          "unit_name": "byte"
+                        }
+                      }
+                    }
+                  ],
+                  "queries": [
+                    {
+                      "aggregator": "avg",
+                      "data_source": "metrics",
+                      "name": "query1",
+                      "query": "avg:mongodb.atlas.dbstats.index.size{*}"
+                    }
+                  ],
+                  "response_format": "scalar"
+                }
+              ],
+              "title": "index size",
+              "title_align": "left",
+              "title_size": "16",
+              "type": "query_value"
+            },
+            "id": 8687938053301306,
+            "layout": {
+              "height": 3,
+              "width": 4,
+              "x": 8,
+              "y": 0
+            }
+          }
+        ]
+      },
+      "id": 7480463324232016,
+      "layout": {
+        "height": 4,
+        "width": 12,
+        "x": 0,
+        "y": 0
+      }
+    },
+    {
+      "definition": {
+        "background_color": "vivid_green",
+        "layout_type": "ordered",
+        "show_title": true,
+        "title": "latencyStats",
+        "type": "group",
+        "widgets": [
+          {
+            "definition": {
+              "legend_columns": [
+                "avg",
+                "min",
+                "max",
+                "value",
+                "sum"
+              ],
+              "legend_layout": "auto",
+              "requests": [
+                {
+                  "display_type": "line",
+                  "formulas": [
+                    {
+                      "alias": "p50 reads",
+                      "formula": "query1"
+                    },
+                    {
+                      "alias": "p95 reads",
+                      "formula": "query2"
+                    },
+                    {
+                      "alias": "p99 reads",
+                      "formula": "query3"
+                    }
+                  ],
+                  "queries": [
+                    {
+                      "data_source": "metrics",
+                      "name": "query1",
+                      "query": "avg:mongodb.atlas.latencyStats.reads.p50{*}.as_count()"
+                    },
+                    {
+                      "data_source": "metrics",
+                      "name": "query2",
+                      "query": "avg:mongodb.atlas.latencyStats.reads.p95{*}.as_count()"
+                    },
+                    {
+                      "data_source": "metrics",
+                      "name": "query3",
+                      "query": "avg:mongodb.atlas.latencyStats.reads.p99{*}.as_count()"
+                    }
+                  ],
+                  "response_format": "timeseries",
+                  "style": {
+                    "line_type": "solid",
+                    "line_width": "normal",
+                    "order_by": "values",
+                    "palette": "dog_classic"
+                  }
+                }
+              ],
+              "show_legend": true,
+              "title": "number of read operations at p50, p95 and p99",
+              "title_align": "left",
+              "title_size": "16",
+              "type": "timeseries"
+            },
+            "id": 5846352545448276,
+            "layout": {
+              "height": 5,
+              "width": 12,
+              "x": 0,
+              "y": 0
+            }
+          }
+        ]
+      },
+      "id": 7805862455900080,
+      "layout": {
+        "height": 6,
+        "is_column_break": true,
+        "width": 12,
+        "x": 0,
+        "y": 0
+      }
+    }
+  ]
+}
\ No newline at end of file
diff --git a/mongodb_atlas/manifest.json b/mongodb_atlas/manifest.json
index 5c52a180d2..9a305cae03 100644
--- a/mongodb_atlas/manifest.json
+++ b/mongodb_atlas/manifest.json
@@ -68,13 +68,14 @@
     },
     "dashboards": {
       "MongoDB-Atlas-Overview": "assets/dashboards/MongoDB-Atlas-Overview_dashboard.json",
-      "MongoDB-Atlas-Vector-Search-Overview": "assets/dashboards/MongoDB-Atlas-Vector-Search-Overview_dashboard.json"
+      "MongoDB-Atlas-Vector-Search-Overview": "assets/dashboards/MongoDB-Atlas-Vector-Search-Overview_dashboard.json",
+      "MongoDB-dbStats-collStats-Dashboard": "assets/dashboards/MongoDB-Atlas-dbStats-collStats_dashboard.json"
     }
   },
   "author": {
-    "support_email": "help@datadoghq.com",
-    "name": "Datadog",
-    "homepage": "https://www.datadoghq.com",
-    "sales_email": "info@datadoghq.com"
+    "support_email": "frank.sun@mongodb.com",
+    "name": "MongoDB",
+    "homepage": "https://www.mongodb.com",
+    "sales_email": "field@mongodb.com"
   }
 }
diff --git a/mongodb_atlas/metadata.csv b/mongodb_atlas/metadata.csv
index 3e5546f8f8..465392c87a 100644
--- a/mongodb_atlas/metadata.csv
+++ b/mongodb_atlas/metadata.csv
@@ -1,9 +1,39 @@
 metric_name,metric_type,interval,unit_name,per_unit_name,description,orientation,integration,short_name,curated_metric
 mongodb.atlas.connections.current,gauge,,connection,,Number of current connections,0,mongodb_atlas,current connections,
 mongodb.atlas.cursors.totalopen,gauge,,cursor,,Total number of open cursors,0,mongodb_atlas,total open cursors,
+mongodb.atlas.dbStats.avg_object_size,gauge,,byte,,Average size of each document. This is the dataSize divided by the number of documents,0,mongodb_atlas,average document size,
+mongodb.atlas.dbstats.collections,gauge,,table,,Number of collections in the database,0,mongodb_atlas,collections,
+mongodb.atlas.dbstats.data_size,gauge,,,,Total size of the uncompressed data held in the database,0,mongodb_atlas,database size,
+mongodb.atlas.dbstats.file_size,gauge,,,,Total size of the data files on disk allocated for the database,0,mongodb_atlas,,
+mongodb.atlas.dbstats.index_size,gauge,,,,Sum of the disk space allocated to all indexes in the database including free index space,0,mongodb_atlas,mongodb_atlas,
+mongodb.atlas.dbstats.indexes,gauge,,index,,Total number of indexes across all collections in the database,0,mongodb_atlas,index total,
+mongodb.atlas.dbstats.num_extents,gauge,,,,Number of contiguous blocks of space in a data file allocated for a collection or index,0,mongodb_atlas,,
+mongodb.atlas.dbstats.objects,gauge,,object,,Number of objects (specifically documents) in the database across all collections,0,mongodb_atlas,total objects,
+mongodb.atlas.dbstats.storage_size,gauge,,,,Sum of the disk space allocated to all collections in the database for document storage including free space,0,mongodb_atlas,storage size,
+mongodb.atlas.dbstats.views,gauge,,object,,Number of views in the database,0,mongodb_atlas,views,
 mongodb.atlas.global.lock.current.queue.reads,gauge,,operation,,The number of operations queued waiting for a read lock,0,mongodb_atlas,current queue reads,
 mongodb.atlas.global.lock.current.queue.total,gauge,,operation,,The number of operations queued waiting for any lock,0,mongodb_atlas,current queue total,
 mongodb.atlas.global.lock.current.queue.writes,gauge,,operation,,The number of operations queued waiting for a write lock,0,mongodb_atlas,current queue writes,
+mongodb.atlas.latencyStats.read.sum,rate,600,,,Latency for total read requests,0,mongodb_atlas,collection read latency,
+mongodb.atlas.latencyStats.read.count,rate,,,,Number of operations performed on the collection since startup for read requests,0,mongodb_atlas,collection read ops,
+mongodb.atlas.latencyStats.read.p50,rate,,,,Number of operations on the 50th percentile in the latency histogram for read requests,0,mongodb_atlas,read histogram p50,
+mongodb.atlas.latencyStats.read.p95,rate,,,,Number of operations on the 95th percentile in the latency histogram for read requests,0,mongodb_atlas,read histogram p95,
+mongodb.atlas.latencyStats.read.p99,rate,,,,Number of operations on the 99th percentile in the latency histogram for read requests,0,mongodb_atlas,read histogram p99,
+mongodb.atlas.latencyStats.write.sum,rate,,,,Latency for total write requests,0,mongodb_atlas,collection write latency,
+mongodb.atlas.latencyStats.write.count,rate,,,,Number of operations performed on the collection since startup for write requests,0,mongodb_atlas,collection write ops,
+mongodb.atlas.latencyStats.write.p50,rate,,,,Number of operations on the 50th percentile in the latency histogram for write requests,0,mongodb_atlas,write histogram p50,
+mongodb.atlas.latencyStats.write.p95,rate,,,,Number of operations on the 95th percentile in the latency histogram for write requests,0,mongodb_atlas,write histogram p95,
+mongodb.atlas.latencyStats.write.p99,rate,,,,Number of operations on the 99th percentile in the latency histogram for write requests,0,mongodb_atlas,write histogram p99,
+mongodb.atlas.latencyStats.commands.sum,rate,,,,Latency for total database command requests,0,mongodb_atlas,database commands read latency,
+mongodb.atlas.latencyStats.commands.count,rate,,,,Number of operations performed on the collection since startup for database command requests,0,mongodb_atlas,database commands read ops,
+mongodb.atlas.latencyStats.commands.p50,rate,,,,Number of operations on the 50th percentile in the latency histogram for database command requests,0,mongodb_atlas,database commands histogram p50,
+mongodb.atlas.latencyStats.commands.p95,rate,,,,Number of operations on the 95th percentile in the latency histogram for database command requests,0,mongodb_atlas,database commands histogram p95,
+mongodb.atlas.latencyStats.commands.p99,rate,,,,Number of operations on the 99th percentile in the latency histogram for database command requests,0,mongodb_atlas,database commands histogram p99,
+mongodb.atlas.latencyStats.total.sum,rate,,,,Latency for total all database transactions,0,mongodb_atlas,collection write latency,
+mongodb.atlas.latencyStats.total.count,rate,,,,Number of operations performed on the collection since startup for all database transactions,0,mongodb_atlas,collection write ops,
+mongodb.atlas.latencyStats.total.p50,rate,,,,Number of operations on the 50th percentile in the latency histogram for all database transactions,0,mongodb_atlas,write histogram p50,
+mongodb.atlas.latencyStats.total.p95,rate,,,,Number of operations on the 95th percentile in the latency histogram for all database transactions,0,mongodb_atlas,write histogram p95,
+mongodb.atlas.latencyStats.total.p99,rate,,,,Number of operations on the 99th percentile in the latency histogram for all database transactions,0,mongodb_atlas,write histogram p99,
 mongodb.atlas.mem.resident,gauge,,mebibyte,,Resident memory consumed by the MongoDB process on server,0,mongodb_atlas,resident memory,
 mongodb.atlas.mem.virtual,gauge,,mebibyte,,Virtual memory consumed by the MongoDB process on server,0,mongodb_atlas,virtual memory,
 mongodb.atlas.metrics.document.deleted,rate,60,document,second,Documents deleted,0,mongodb_atlas,documents deleted,
@@ -106,4 +136,4 @@ mongodb.atlas.wiredtiger.cache.bytes_read_into_cache,rate,60,byte,second,Average
 mongodb.atlas.wiredtiger.cache.bytes_written_from_cache,rate,60,byte,second,Average rate of bytes per second written from WiredTiger's cache,0,mongodb_atlas,bytes written from cache,
 mongodb.atlas.wiredtiger.cache.tracked_dirty_bytes_in_cache,gauge,,byte,,Number of tracked dirty bytes currently in the WiredTiger cache,0,mongodb_atlas,dirty bytes in cache,
 mongodb.atlas.wiredtiger.concurrenttransactions.read.available,gauge,,operation,,Number of available read operations allowed into the storage engine,0,mongodb_atlas,concurrent reads available,
-mongodb.atlas.wiredtiger.concurrenttransactions.write.available,gauge,,operation,,Number of available write operations allowed into the storage engine,0,mongodb_atlas,concurrent writes available,
+mongodb.atlas.wiredtiger.concurrenttransactions.write.available,gauge,,operation,,Number of available write operations allowed into the storage engine,0,mongodb_atlas,concurrent writes available,
\ No newline at end of file