I am trying to get files_total and dfs_capacity_used metrics for last 1 week with code shared in https://cloudera.github.io/cm_api/docs/python-client/
import time
import datetime
from_time = datetime.datetime.fromtimestamp(time.time() - 1800)
to_time = datetime.datetime.fromtimestamp(time.time())
query = "select files_total, dfs_capacity_used " \
"where serviceName = HDFS-1 " \
" and category = SERVICE"
result = api.query_timeseries(query, from_time, to_time)
ts_list = result[0]
for ts in ts_list.timeSeries:
print "--- %s: %s ---" % (ts.metadata.entityName, ts.metadata.metricName)
for point in ts.data:
print "%s:\t%s" % (point.timestamp.isoformat(), point.value)
I am getting the output. But the Data Granuality is showing on daily basis. Is there a way to get the output every 6 hours like the option in snapshot shared from Cloudera UI as below,
query_timeseries does not provide Data Granularity option. It will auto-determine by the time period that which could cover the time period that we set.
With below get function we can retrieve based on Data Granularity
api=ApiResource('CM_HOST',username='admin',password='admin') api.get(relpath='timeseries',params={'query':'select files_total, dfs_capacity_used where serviceName = HDFS-1 and category = SERVICE','desiredRollup':'RAW','mustUseDesiredRollup':'True','from':'2020-08-10','to':2020-08-17})
If we would like to hardly set our granularity as 6 hourly, then we could set 'desiredRollup' as 'SIX_HOURLY' and 'mustUseDesiredRollup' as 'True' .