def org_summary_from_org_timeseries(org): """ Rollup org timeseries => org summary. """ ts_query = QueryOrgMetricTimeseries(org, [org.id], unit=None) ts_query.computed = False metrics, ss = _summary_select(org.timeseries_to_summary_metric_rollups) qkw = { 'org_id': org.id, 'select_statements': ss, 'metrics': metrics, 'ts_query': ts_query.query } q = \ """SELECT upsert_org_metric_summary({org_id}, metrics::text) FROM ( SELECT (SELECT row_to_json(_) from (SELECT {metrics}) as _) as metrics FROM ( SELECT {select_statements} FROM ({ts_query}) zzzz ) t1 ) t2 """.format(**qkw) db.session.execute(q) db.session.commit() return True
def org_summary_from_org_timeseries(org): """ Rollup org timeseries => org summary. """ ts_query = QueryOrgMetricTimeseries(org, [org.id], unit=None) ts_query.computed = False metrics, ss = _summary_select(org.timeseries_to_summary_metric_rollups) qkw = { 'org_id': org.id, 'select_statements': ss, 'metrics': metrics, 'ts_query': ts_query.query } q = \ """SELECT upsert_org_metric_summary({org_id}, metrics::text) FROM ( SELECT (SELECT row_to_json(_) from (SELECT {metrics}) as _) as metrics FROM ( SELECT {select_statements} FROM ({ts_query}) zzzz ) t1 ) t2 """.format(**qkw) db.session.execute(q) db.session.commit() return True
def get_org_timeseries(user, org_id_slug): # fetch org org = fetch_by_id_or_field(Org, "slug", org_id_slug) # if it still doesn't exist, raise an error. if not org: raise NotFoundError("This Org does not exist.") # ensure the active user can edit this Org if user.id not in org.user_ids: raise ForbiddenError("You are not allowed to access this Org") kw = request_ts() q = QueryOrgMetricTimeseries(org, [org.id], **kw) return jsonify(list(q.execute()))
def get_org_timeseries(user, org_id_slug): # fetch org org = fetch_by_id_or_field(Org, 'slug', org_id_slug) # if it still doesn't exist, raise an error. if not org: raise NotFoundError('This Org does not exist.') # ensure the active user can edit this Org if user.id not in org.user_ids: raise ForbiddenError('You are not allowed to access this Org') kw = request_ts() q = QueryOrgMetricTimeseries(org, [org.id], **kw) return jsonify(list(q.execute()))
def get_org_timeseries(user, org_id_slug): # fetch org org = fetch_by_id_or_field(Org, 'slug', org_id_slug) # if it still doesn't exist, raise an error. if not org: raise NotFoundError( 'This Org does not exist.') # ensure the active user can edit this Org if user.id not in org.user_ids: raise ForbiddenError( 'You are not allowed to access this Org') # todo: validate which metrics you can select. # select / exclude select, exclude = arg_list( 'select', typ=str, exclusions=True, default=['all']) if 'all' in select: exclude = [] select = "all" kw = dict( unit=arg_str('unit', default='hour'), sparse=arg_bool('sparse', default=True), sig_digits=arg_int('sig_digits', default=2), select=select, exclude=exclude, group_by_id=arg_bool('group_by_id', default=True), rm_nulls=arg_bool('rm_nulls', default=False), time_since_start=arg_bool('time_since_start', default=False), transform=arg_str('transform', default=None), before=arg_date('before', default=None), after=arg_date('after', default=None) ) q = QueryOrgMetricTimeseries(org, [org.id], **kw) return jsonify(list(q.execute()))