Example #1
0
def on_connect():
    """Verifies that the user is logged in and that the app they want to monitor
    exists. Joins them to a "room" for that app. Emits an event containing a
    history of activity for the past 900 seconds. Starts polling for real time
    stats on the app's performance.
    """

    print('connecting')
    app_id = request.args.get('app_id', None)
    if not app_id:
        print ('app_id is required')
        return disconnect()
    app = App.find_by_id(app_id)
    if not app:
        print ('app not found')
        return disconnect()

    print ('watching app', app_id)
    sockets.join_room(get_app_room_id(app_id))

    interval = request.args.get('history_interval', 900)
    app_stats = AppStats.get_history(app_id, interval=interval)
    socketio.emit('history', util.to_dict(app_stats),
                  room=request.sid, namespace=namespace)

    resume_stats()
Example #2
0
def send_stats():
    """Runs forever in a socket.io background task and sends updates on all
    monitored apps. Updates are checked and sent on the configured interval
    `scaling.monitor_interval`.
    """
    while True:
        global track_stats
        if track_stats:
            try:
                apps = sockets.rooms_with_members('apps/')
                print ('getting stats for apps', apps)
                for room in apps:
                    app_id = room.split('/')[-1]
                    try:
                        app = App.find_by_id(app_id)
                        stats = app.get_current_stats(
                            include_instance_stats=True)
                        update_app_watchers(app_id, 'stats',
                                                    stats.to_dict())
                    except Exception as e:
                        import traceback
                        print(traceback.format_exc())
                        print(type(e), e.message)

            except Exception as e:
                print (e)
        # else:
            # print ('No clients active, sleeping.')

        socketio.sleep(config.scaling_monitor_interval)
Example #3
0
 def wrapped_f(app_id):
     app = App.find_by_id(app_id, use_cache=False)
     if not app:
         raise ApiError('App not found.', 404)
     return func(app)