Example #1
0
def do_watch(request, deployment_id):
    service = str(request.GET.get('service', 'nova'))

    model = _model_factory(service)
    deployment_id = int(deployment_id)
    since = request.GET.get('since')
    event_name = request.GET.get('event_name')

    deployment_map = {}
    for d in get_deployments():
        deployment_map[d.id] = d
    events = get_event_names()
    max_event_width = max([len(event['event']) for event in events])

    base_events = model.order_by('when')
    if deployment_id > 0:
        base_events = base_events.filter(deployment=deployment_id)

    if event_name:
        base_events = base_events.filter(event=event_name)

    # Ok, this may seem a little wonky, but I'm clamping the
    # query time to the closest second. The implication is we
    # may not return the absolute latest data (which will have
    # to wait for the next query). The upside of doing this
    # is we can effectively cache the responses. So, with a
    # caching proxy server we can service a lot more clients
    # without having to worry about microsecond differences
    # causing cache misses.

    now = datetime.datetime.utcnow()
    now = now.replace(microsecond=0)  # clamp it down.
    dec_now = dt.dt_to_decimal(now)
    if since:
        since = decimal.Decimal(since)
    else:
        since = now - datetime.timedelta(seconds=2)
        since = dt.dt_to_decimal(since)
    base_events = base_events.filter(when__gt=since)
    events = base_events.filter(when__lte=dec_now)

    c = [10, 1, 15, 20, max_event_width, 36]

    results = []

    for raw in events:
        uuid = raw.uuid
        if not uuid:
            uuid = "-"
        typ = routing_key_type(raw.routing_key)
        when = dt.dt_from_decimal(raw.when)
        results.append([raw.id, typ,
                       str(when.date()), str(when.time()),
                       deployment_map[raw.deployment.id].name,
                       raw.event,
                       uuid])
    results_json = json.dumps([c, results, str(dec_now)])

    return rsp(results_json)
Example #2
0
def _parse_created(created):
    try:
        created_datetime = datetime.datetime.strptime(created, '%Y-%m-%d')
        return dt.dt_to_decimal(created_datetime)
    except ValueError:
        raise BadRequestException(
            "'%s' value has an invalid format. It must be in YYYY-MM-DD format."
            % created)
Example #3
0
def do_jsonreports(request):
    yesterday = datetime.datetime.utcnow() - datetime.timedelta(days=1)
    now = datetime.datetime.utcnow()
    yesterday = dt.dt_to_decimal(yesterday)
    now = dt.dt_to_decimal(now)
    _from = request.GET.get('created_from', yesterday)
    _to = request.GET.get('created_to', now)
    reports = models.JsonReport.objects.filter(created__gte=_from,
                                               created__lte=_to)
    results = [['Id', 'Start', 'End', 'Created', 'Name', 'Version']]
    for report in reports:
        results.append([report.id,
                        float(dt.dt_to_decimal(report.period_start)),
                        float(dt.dt_to_decimal(report.period_end)),
                        float(report.created),
                        report.name,
                        report.version])
    return rsp(json.dumps(results))
Example #4
0
def str_time_to_unix(when):
    if 'Z' in when:
        when = _try_parse(when, ["%Y-%m-%dT%H:%M:%SZ", "%Y-%m-%dT%H:%M:%S.%fZ"])
    elif 'T' in when:
        when = _try_parse(when, ["%Y-%m-%dT%H:%M:%S.%f", "%Y-%m-%dT%H:%M:%S"])
    else:
        when = _try_parse(when, ["%Y-%m-%d %H:%M:%S.%f", "%Y-%m-%d %H:%M:%S"])

    return dt.dt_to_decimal(when)
Example #5
0
def do_jsonreports(request):
    yesterday = datetime.datetime.utcnow() - datetime.timedelta(days=1)
    now = datetime.datetime.utcnow()
    yesterday = dt.dt_to_decimal(yesterday)
    now = dt.dt_to_decimal(now)
    _from = request.GET.get("created_from", yesterday)
    _to = request.GET.get("created_to", now)
    reports = models.JsonReport.objects.filter(created__gte=_from, created__lte=_to)
    results = [["Id", "Start", "End", "Created", "Name", "Version"]]
    for report in reports:
        results.append(
            [
                report.id,
                float(dt.dt_to_decimal(report.period_start)),
                float(dt.dt_to_decimal(report.period_end)),
                float(report.created),
                report.name,
                report.version,
            ]
        )
    return rsp(results)
Example #6
0
def do_kpi(request, tenant_id=None):
    yesterday = datetime.datetime.utcnow() - datetime.timedelta(days=1)
    yesterday = dt.dt_to_decimal(yesterday)
    trackers = models.RequestTracker.objects.select_related() \
                                   .exclude(last_timing=None)  \
                                   .exclude(start__lt=yesterday) \
                                   .order_by('duration')

    results = []
    results.append(["Event", "Time", "UUID", "Deployment"])
    for track in trackers:
        end_event = track.last_timing.end_raw
        event = end_event.event[:-len(".end")]
        uuid = track.lifecycle.instance
        if tenant_id == None or (tenant_id == end_event.tenant):
            results.append([event, sec_to_time(track.duration),
                   uuid, end_event.deployment.name])
    return rsp(results)
Example #7
0
def do_kpi(request, tenant_id=None):
    if tenant_id:
        if models.RawData.objects.filter(tenant=tenant_id).count() == 0:
            message = "Could not find raws for tenant %s" % tenant_id
            return error_response(404, 'Not Found', message)

    yesterday = datetime.datetime.utcnow() - datetime.timedelta(days=1)
    yesterday = dt.dt_to_decimal(yesterday)
    trackers = models.RequestTracker.objects.select_related()\
                                    .exclude(last_timing=None)\
                                    .exclude(start__lt=yesterday)\
                                    .order_by('duration')

    results = [["Event", "Time", "UUID", "Deployment"]]
    for track in trackers:
        end_event = track.last_timing.end_raw
        event = end_event.event[:-len(".end")]
        uuid = track.lifecycle.instance
        if tenant_id is None or (tenant_id == end_event.tenant):
            results.append([event, sec_to_time(track.duration),
                            uuid, end_event.deployment.name])
    return rsp(json.dumps(results))