Exemplo n.º 1
0
def add_stream_check(stream, server_status, stream_status, current_listeners,
                     average_listen_time, max_listen_time):
    stream_check = StreamCheckModel(stream=stream.key,
                                    server_status=server_status,
                                    stream_status=stream_status,
                                    current_listeners=current_listeners,
                                    average_listen_time=average_listen_time,
                                    max_listen_time=max_listen_time)
    try:
        stream_check.put()
    except CapabilityDisabledError:
        logging.error(u'App Engine Datastore is currently in read-only mode.')
Exemplo n.º 2
0
def add_stream_check(stream, server_status, stream_status, current_listeners, average_listen_time, max_listen_time):
	stream_check = StreamCheckModel(
		stream = stream.key,
		server_status = server_status,
		stream_status = stream_status,
		current_listeners = current_listeners,
		average_listen_time = average_listen_time,
		max_listen_time = max_listen_time
	)
	try:
		stream_check.put()
	except CapabilityDisabledError:
		logging.error(u'App Engine Datastore is currently in read-only mode.')
Exemplo n.º 3
0
def show_stream(stream_id):
    """Show stream object"""
    start_date_str = request.values.get('s', None)
    end_date_str = request.values.get('e', None)
    if start_date_str is not None:
        start_date = datetime.fromtimestamp(int(start_date_str) / 1000)
    else:
        start_date = datetime.utcnow()
        start_date += timedelta(days=-1)
    if end_date_str is not None:
        end_date = datetime.fromtimestamp(int(end_date_str) / 1000)
    else:
        end_date = datetime.utcnow()
    stream = StreamModel.get_by_id(stream_id)
    stream_checks_query = StreamCheckModel.query().filter(
        StreamCheckModel.stream == stream.key,
        StreamCheckModel.timestamp >= start_date,
        StreamCheckModel.timestamp <= end_date).order(
            StreamCheckModel.timestamp)
    stream_checks = stream_checks_query.fetch(1000)
    server_uptime_sum = 0
    stream_uptime_sum = 0
    average_listeners_sum = 0
    average_listeners_count = 0
    average_listen_time_count = 0
    average_listen_time_sum = 0

    for stream_check in stream_checks:
        if stream_check.server_status > 0:
            server_uptime_sum += 1
        if stream_check.stream_status > 0:
            stream_uptime_sum += 1
        if stream_check.current_listeners is not None:
            average_listeners_sum += stream_check.current_listeners
            average_listeners_count += 1
        if stream_check.average_listen_time is not None:
            average_listen_time_sum += stream_check.average_listen_time
            average_listen_time_count += 1

    status = 'Up'

    if len(stream_checks) > 0:
        server_uptime = round(((server_uptime_sum / len(stream_checks)) * 100),
                              2)
        stream_uptime = round(((stream_uptime_sum / len(stream_checks)) * 100),
                              2)
        server_uptime_moving_average = get_server_uptime_moving_average(
            stream_checks, 144)
        stream_uptime_moving_average = get_stream_uptime_moving_average(
            stream_checks, 144)
    else:
        server_uptime = 0.0
        stream_uptime = 0.0
        server_uptime_moving_average = []
        stream_uptime_moving_average = []
    if average_listeners_count > 0:
        average_listeners = round(
            (average_listeners_sum / average_listeners_count), 2)
    else:
        average_listeners = 0
    if average_listen_time_count > 0:
        average_listen_time = str(
            timedelta(seconds=int(average_listen_time_sum /
                                  average_listen_time_count)))
    else:
        average_listen_time = 0

    return render_template(
        'show_stream.html',
        stream=stream,
        stream_checks=stream_checks,
        status=status,
        server_uptime=server_uptime,
        stream_uptime=stream_uptime,
        average_listeners=average_listeners,
        server_uptime_moving_average=server_uptime_moving_average,
        stream_uptime_moving_average=stream_uptime_moving_average,
        average_listen_time=average_listen_time,
        start_date=start_date.strftime("%B %d, %Y %H:%M:%S"),
        end_date=end_date.strftime("%B %d, %Y %H:%M:%S"))
Exemplo n.º 4
0
def show_stream(stream_id):
    """Show stream object"""
    start_date_str = request.values.get('s', None)
    end_date_str = request.values.get('e', None)
    if start_date_str is not None:
        start_date = datetime.fromtimestamp(int(start_date_str) / 1000)
    else:
        start_date = datetime.utcnow()
        start_date += timedelta(days=-1)
    if end_date_str is not None:
        end_date = datetime.fromtimestamp(int(end_date_str) / 1000)
    else:
        end_date = datetime.utcnow()
    stream = StreamModel.get_by_id(stream_id)
    stream_checks_query = StreamCheckModel.query().filter(StreamCheckModel.stream == stream.key, StreamCheckModel.timestamp >= start_date, StreamCheckModel.timestamp <= end_date).order(StreamCheckModel.timestamp)
    stream_checks = stream_checks_query.fetch(1000)
    server_uptime_sum = 0
    stream_uptime_sum = 0
    average_listeners_sum = 0
    average_listeners_count = 0
    average_listen_time_count = 0
    average_listen_time_sum = 0

    for stream_check in stream_checks:
        if stream_check.server_status > 0:
            server_uptime_sum += 1
        if stream_check.stream_status > 0:
            stream_uptime_sum += 1
        if stream_check.current_listeners is not None:
            average_listeners_sum += stream_check.current_listeners
            average_listeners_count += 1
        if stream_check.average_listen_time is not None:
            average_listen_time_sum += stream_check.average_listen_time
            average_listen_time_count += 1

    status = 'Up'

    if len(stream_checks) > 0:
        server_uptime = round(((server_uptime_sum / len(stream_checks)) * 100), 2)
        stream_uptime = round(((stream_uptime_sum / len(stream_checks)) * 100), 2)
        server_uptime_moving_average = get_server_uptime_moving_average(stream_checks, 144)
        stream_uptime_moving_average = get_stream_uptime_moving_average(stream_checks, 144)
    else:
        server_uptime = 0.0
        stream_uptime = 0.0
        server_uptime_moving_average = []
        stream_uptime_moving_average = []
    if average_listeners_count > 0:
        average_listeners = round((average_listeners_sum / average_listeners_count), 2)
    else:
        average_listeners = 0
    if average_listen_time_count > 0:
        average_listen_time = str(timedelta(seconds=int(average_listen_time_sum / average_listen_time_count)))
    else:
        average_listen_time = 0

    return render_template(
        'show_stream.html', 
        stream=stream, 
        stream_checks=stream_checks, 
        status=status, 
        server_uptime=server_uptime, 
        stream_uptime=stream_uptime, 
        average_listeners=average_listeners, 
        server_uptime_moving_average=server_uptime_moving_average,
        stream_uptime_moving_average=stream_uptime_moving_average,
        average_listen_time=average_listen_time,
        start_date=start_date.strftime("%B %d, %Y %H:%M:%S"),
        end_date=end_date.strftime("%B %d, %Y %H:%M:%S"))