Repository: mgmonteleone/python-atlasapi (language: python)

Issue:
Support for Database level Metrics
Thanks so much for building this library, it is super helpful!

Is there any support yet for database level metric retrieval ([these](https://www.mongodb.com/docs/atlas/reference/api/process-databases-measurements/#measurement-values) specifically)?

DATABASE_AVERAGE_OBJECT_SIZE
DATABASE_COLLECTION_COUNT
DATABASE_DATA_SIZE
DATABASE_STORAGE_SIZE
DATABASE_INDEX_SIZE
DATABASE_INDEX_COUNT
DATABASE_EXTENT_COUNT
DATABASE_OBJECT_COUNT
DATABASE_VIEW_COUNT

I've been looking through the source and documentation but haven't been able to find anything close to it other than the host level metrics.


-------------

Two Components:

- [x]  Get all databases
- [x] Get metrics for database
Add host disk metrics to measurements


- [x]  Get Available Disks for a MongoDB Process
      `https://www.mongodb.com/docs/atlas/reference/api/process-disks/`

`GET api/atlas/v1.0/groups/{GROUP-ID}/processes/{HOST}:{PORT}/disks`


------
- [x]  Get Measurements of a Disk for a MongoDB Process

`https://www.mongodb.com/docs/atlas/reference/api/process-disks-measurements/`

`GET /groups/{GROUP-ID}/processes/{HOST}:{PORT}/disks/{DISK-NAME}/measurements`


------

```
DISK_PARTITION_IOPS_READ
MAX_DISK_PARTITION_IOPS_READ
DISK_PARTITION_IOPS_WRITE
MAX_DISK_PARTITION_IOPS_WRITE
DISK_PARTITION_IOPS_TOTAL
MAX_DISK_PARTITION_IOPS_TOTAL


DISK_PARTITION_UTILIZATION
MAX_DISK_PARTITION_UTILIZATION

DISK_PARTITION_LATENCY_READ
MAX_DISK_PARTITION_LATENCY_READ
DISK_PARTITION_LATENCY_WRITE
MAX_DISK_PARTITION_LATENCY_WRITE


DISK_PARTITION_SPACE_FREE
MAX_DISK_PARTITION_SPACE_FREE
DISK_PARTITION_SPACE_USED
MAX_DISK_PARTITION_SPACE_USED
DISK_PARTITION_SPACE_PERCENT_FREE
MAX_DISK_PARTITION_SPACE_PERCENT_FREE
DISK_PARTITION_SPACE_PERCENT_USED
MAX_DISK_PARTITION_SPACE_PERCENT_USED
```



Add host disk metrics to measurements


- [x]  Get Available Disks for a MongoDB Process
      `https://www.mongodb.com/docs/atlas/reference/api/process-disks/`

`GET api/atlas/v1.0/groups/{GROUP-ID}/processes/{HOST}:{PORT}/disks`


------
- [x]  Get Measurements of a Disk for a MongoDB Process

`https://www.mongodb.com/docs/atlas/reference/api/process-disks-measurements/`

`GET /groups/{GROUP-ID}/processes/{HOST}:{PORT}/disks/{DISK-NAME}/measurements`


------

```
DISK_PARTITION_IOPS_READ
MAX_DISK_PARTITION_IOPS_READ
DISK_PARTITION_IOPS_WRITE
MAX_DISK_PARTITION_IOPS_WRITE
DISK_PARTITION_IOPS_TOTAL
MAX_DISK_PARTITION_IOPS_TOTAL


DISK_PARTITION_UTILIZATION
MAX_DISK_PARTITION_UTILIZATION

DISK_PARTITION_LATENCY_READ
MAX_DISK_PARTITION_LATENCY_READ
DISK_PARTITION_LATENCY_WRITE
MAX_DISK_PARTITION_LATENCY_WRITE


DISK_PARTITION_SPACE_FREE
MAX_DISK_PARTITION_SPACE_FREE
DISK_PARTITION_SPACE_USED
MAX_DISK_PARTITION_SPACE_USED
DISK_PARTITION_SPACE_PERCENT_FREE
MAX_DISK_PARTITION_SPACE_PERCENT_FREE
DISK_PARTITION_SPACE_PERCENT_USED
MAX_DISK_PARTITION_SPACE_PERCENT_USED
```



Devel - Completed Wok on both #92 and #100
## Issue #92 

Work for issue #92, added both the get all databases as well as get metrics for database.

Added the database metrics to the Measurements class as well.

Currently only getting all metrics for database is supported. if there is need to pull individual metrics, perhaps we can add that later.

--- 

##  Issue #100
As part of completing #100 needed to refactor quite a bit with measurements, including:

- grabbing the unit description from the API
- Changing the _friendly method to use the unit description to properly render bytes of numbers.
- Moved measurements classes to its own module (`measurements.py`)
- had to refactor tests


Devel - Completed Wok on both #92 and #100
## Issue #92 

Work for issue #92, added both the get all databases as well as get metrics for database.

Added the database metrics to the Measurements class as well.

Currently only getting all metrics for database is supported. if there is need to pull individual metrics, perhaps we can add that later.

--- 

##  Issue #100
As part of completing #100 needed to refactor quite a bit with measurements, including:

- grabbing the unit description from the API
- Changing the _friendly method to use the unit description to properly render bytes of numbers.
- Moved measurements classes to its own module (`measurements.py`)
- had to refactor tests


Add the new ten second granularity to AtlasGranularities
Should be PT10S


Discussion / hints:
Thanks @luffespresso for submitting this! 

Indeed, this has not yet been implemented. I will look into implementing this soon, and will update on this issue once work begins.

Scheduled for measurements v2 release next week.






Fix patch:
diff --git a/atlasapi/__init__.py b/atlasapi/__init__.py
index f1b29e5..ed90048 100644
--- a/atlasapi/__init__.py
+++ b/atlasapi/__init__.py
@@ -15,4 +15,4 @@
 # __init__.py
 
 # Version of the realpython-reader package
-__version__ = "2.0.0"
\ No newline at end of file
+__version__ = "2.0.1"
\ No newline at end of file
diff --git a/atlasapi/lib.py b/atlasapi/lib.py
index d44b27e..43da08f 100644
--- a/atlasapi/lib.py
+++ b/atlasapi/lib.py
@@ -72,12 +72,14 @@ class AtlasGranularities(object):
     To add more possible granularities, add them here.
 
     """
+    TEN_SECOND = duration_isoformat(Duration(seconds=10))
     MINUTE = duration_isoformat(Duration(minutes=1))
     FIVE_MINUTE = duration_isoformat(Duration(minutes=5))
     HOUR = duration_isoformat(Duration(hours=1))
     DAY = duration_isoformat(Duration(days=1))
 
 
+
 class AtlasPeriods(object):
     """Helper class to create ISO 8601 durations to send to the Atlas period parameter.
 
diff --git a/setup.py b/setup.py
index 6eb0f7d..c84467e 100644
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@
 
 setup(
     name='atlasapi',
-    version='2.0.0',
+    version='2.0.1',
     python_requires='>=3.7',
     packages=find_packages(exclude=("tests",)),
     install_requires=['requests', 'python-dateutil', 'isodate', 'future', 'pytz','coolname', 'humanfriendly', 'nose'],


Test patch:
diff --git a/tests/test_monitoring.py b/tests/test_monitoring.py
index e6b0302..4501427 100644
--- a/tests/test_monitoring.py
+++ b/tests/test_monitoring.py
@@ -355,3 +355,16 @@ def test_25_get_measurements_for_configdb(self):
                                       atlasapi.measurements.StatisticalValuesFriendly)
 
     test_25_get_measurements_for_configdb.basic = True
+
+    def test_26_issue_114_add_ten_second_granularity(self):
+        cluster_name = 'pyAtlasTestCluster'
+        self.a.Hosts.fill_host_list(for_cluster=cluster_name)
+        host = list(self.a.Hosts.host_list)[0]
+        pprint(f"For Host: {host.hostname}")
+        output: AtlasMeasurement = host.get_measurements_for_disk(self.a,partition_name="data", granularity=AtlasGranularities.TEN_SECOND, period=AtlasPeriods.HOURS_24)
+        for each in output:
+            print('Measurement'.center(80, '*'))
+            print(f"Name: {each.name}: {each.measurement_stats_friendly.mean} {each.units} {each.granularity}")
+
+    # This test requires a cluster of m40 or higher , so will not run this in the automated suite.
+    test_26_issue_114_add_ten_second_granularity.basic = False