def mql_thresholds_single(project, quota_metric, threshold): """Returns all quota limit, usage, consumption percentage values. Args: project: obj, representing project details. quota_metric: str, metric that is of interest. threshold: int, the threshold to use for fetching the values. Returns: generator object, which will yield the results as a dict. """ mql = _MQL + _MQL_THRESHOLDS mql %= (project.id, quota_metric, project.id, quota_metric, threshold) results = monitoring_lib.query_timeseries_mql(project.id, mql) rate_mql = _MQL_RATE + _MQL_THRESHOLDS rate_mql %= (project.id, quota_metric, project.id, quota_metric, threshold) rate_results = monitoring_lib.query_timeseries_mql(project.id, rate_mql) # Since this returns both quota and limit, metric_type is empty. return _results_as_json(project, '', itertools.chain.from_iterable( (results, rate_results)), data_op='to_alerts_dict', additional_values={'threshold': threshold})
def mql_all(project): """Returns all quota limit, usage, consumption percentage values. Args: project: obj, representing project details. Returns: generator object, which will yield the results as a dict. """ mql = _MQL_ALL % (project.id, project.id) results = monitoring_lib.query_timeseries_mql(project.id, mql) rate_mql = _MQL_RATE_ALL % (project.id, project.id) rate_results = monitoring_lib.query_timeseries_mql(project.id, rate_mql) # Since this returns both quota and limit, metric_type is empty. return _results_as_json( project, '', itertools.chain.from_iterable((results, rate_results)))
def usage_mql_all(project): """Query and return quota metric usage details using MQL. Args: project: obj, representing project details. Returns: generator object, which will yield the results as a dict. """ mql = _USAGE_MQL_ALL % ', '.join(_USAGE_GROUP_BY_FIELDS) results = monitoring_lib.query_timeseries_mql(project.id, mql) return _results_as_json(project, _USAGE_METRIC_TYPE, results)
def limit_mql(project, quota_metric): """Query and return quota metric limit details using MQL. Args: project: obj, representing project details. quota_metric: str, metric that is of interest. Returns: generator object, which will yield the results as a dict. """ mql = _LIMIT_MQL % (quota_metric, ', '.join(_LIMIT_GROUP_BY_FIELDS)) results = monitoring_lib.query_timeseries_mql(project.id, mql) return _results_as_json(project, _LIMIT_METRIC_TYPE, results)