- try:
- # get metric_id
- metric_id = self.get_metric_id(endpoint, auth_token, METRIC_MAPPINGS[values['metric_name']],
- values['resource_uuid'], verify_ssl)
- # Try and collect measures
- collection_unit = values['collection_unit'].upper()
- collection_period = values['collection_period']
-
- # Define the start and end time based on configurations
- # FIXME: Local timezone may differ from timezone set in Gnocchi, causing discrepancies in measures
- stop_time = time.strftime("%Y-%m-%d") + "T" + time.strftime("%X")
- end_time = int(round(time.time() * 1000))
- if collection_unit == 'YEAR':
- diff = PERIOD_MS[collection_unit]
- else:
- diff = collection_period * PERIOD_MS[collection_unit]
- s_time = (end_time - diff) / 1000.0
- start_time = datetime.datetime.fromtimestamp(s_time).strftime(
- '%Y-%m-%dT%H:%M:%S.%f')
- base_url = "{}/v1/metric/%(0)s/measures?start=%(1)s&stop=%(2)s"
- url = base_url.format(endpoint) % {
- "0": metric_id, "1": start_time, "2": stop_time}
-
- # Perform metric data request
- metric_data = Common.perform_request(
- url,
- auth_token,
- req_type="get",
- verify_ssl=verify_ssl)
-
- # Generate a list of the requested timestamps and data
- for r in json.loads(metric_data.text):
- timestamp = r[0].replace("T", " ")
- timestamps.append(timestamp)
- data.append(r[2])
+ # get metric_id
+ metric_id = self.get_metric_id(endpoint, auth_token, METRIC_MAPPINGS[values['metric_name']],
+ values['resource_uuid'], verify_ssl)
+ # Try and collect measures
+ collection_unit = values['collection_unit'].upper()
+ collection_period = values['collection_period']
+
+ # Define the start and end time based on configurations
+ # FIXME: Local timezone may differ from timezone set in Gnocchi, causing discrepancies in measures
+ stop_time = time.strftime("%Y-%m-%d") + "T" + time.strftime("%X")
+ end_time = int(round(time.time() * 1000))
+ if collection_unit == 'YEAR':
+ diff = PERIOD_MS[collection_unit]
+ else:
+ diff = collection_period * PERIOD_MS[collection_unit]
+ s_time = (end_time - diff) / 1000.0
+ start_time = datetime.datetime.fromtimestamp(s_time).strftime(
+ '%Y-%m-%dT%H:%M:%S.%f')
+ base_url = "{}/v1/metric/%(0)s/measures?start=%(1)s&stop=%(2)s"
+ url = base_url.format(endpoint) % {
+ "0": metric_id, "1": start_time, "2": stop_time}
+
+ # Perform metric data request
+ metric_data = Common.perform_request(
+ url,
+ auth_token,
+ req_type="get",
+ verify_ssl=verify_ssl)
+
+ # Generate a list of the requested timestamps and data
+ for r in json.loads(metric_data.text):
+ timestamp = r[0].replace("T", " ")
+ timestamps.append(timestamp)
+ data.append(r[2])