def charts(): cpu = False trxs = gen_trxs(21600, 5) d = {} d['t'] = '# Transactions on remchain, 5 seconds interval.' if request.method == "POST" and request.form and 'roundTo' in request.form and 'seconds' in request.form: roundTo = request.form['roundTo'] seconds = request.form['seconds'] cpu = cpu_usage(float(roundTo), float(seconds)) else: cpu = cpu_usage() if request.method == "POST" and request.form and 'trxs' in request.form and 'seconds' in request.form and request.form[ 'seconds'] == '300': try: d['t'] = '# Transactions on remchain, 300 seconds interval.' tag = int(request.form['seconds']) trxs = gen_trxs(172800, tag) except: jlog.critical('chart ERROR: {}'.format(sys.exc_info())) if request.method == "POST" and request.form and 'trxs' in request.form and 'seconds' in request.form and request.form[ 'seconds'] == '3600': try: d['t'] = '# Transactions on remchain, 3600 seconds interval.' tag = int(request.form['seconds']) trxs = gen_trxs(572800, tag) except: jlog.critical('chart ERROR: {}'.format(sys.exc_info())) if request.method == "POST" and request.form and 'trxs' in request.form and 'seconds' in request.form and request.form[ 'seconds'] == '86400': try: d['t'] = '# Transactions on remchain, 86400 seconds interval.' tag = int(request.form['seconds']) trxs = gen_trxs(172800, tag) except: jlog.critical('chart ERROR: {}'.format(sys.exc_info())) return render_template('charts.html', cpu_usage=cpu, trxs=trxs, d=d)
def _listproducers(): get_info = remcli_get_info() producing = False if get_info: producing = get_info['head_block_producer'] owners = db.producers.find() lp = listproducers() producers = [] if lp and isinstance(lp, dict): for row in lp['rows']: d = {} d['owner'] = row['owner'] d['last_block_time'] = row['last_block_time'] d['is_active'] = row['is_active'] d['punished_until'] = False d['total_votes'] = row['total_votes'] try: dt = parse(row['punished_until']) days = dt - datetime.now() if days.days > 0: d['punished_until'] = days.days except: jlog.critical('punished_until ERROR: {}'.format( sys.exc_info())) producers.append(d) if owners: d = {} d['data'] = [] for owner in owners: health = '<div><ul class="health">' if owner['health']: for issue in owner['health']: health += gen_health(issue['title']) i = {} i['position'] = owner['position'] i['owner'] = '<a href={0}>{1}</a>'.format( url_for('owner', owner=owner['name']), owner['name']) if producers and isinstance(producers, list): for producer in producers: if owner['name'] == producer['owner'] and producer[ 'punished_until']: health += gen_health(title='punished_until {}'.format( producer['punished_until']), text=' {}'.format( producer['punished_until'])) try: if producers and isinstance(producers, list): for producer in producers: if producer['owner'] == owner['name']: total_votes = (float(producer['total_votes']) / 10000) i['total_votes'] = '{:0,.0f}'.format(total_votes) except: i['total_votes'] = False i['voters'] = owner['voters_count'] i['social'] = owner['social'] i['cpu_usage_us'] = False ''' try: if owner['cpu_usage_us']: cpu_usage_ms = owner['cpu_usage_us'] / 1000 if cpu_usage_ms > 1: i['cpu_usage_us'] = "<medium class='text-warning'>{:.2f} ms</medium>".format(cpu_usage_ms) if cpu_usage_ms < 1: i['cpu_usage_us'] = "<medium class='text-success'>{:.2f} ms</medium>".format(cpu_usage_ms) if cpu_usage_ms > 2: health += gen_health(title='Slow CPU') i['cpu_usage_us'] = "<medium class='text-danger'>{:.2f} ms</medium>".format(cpu_usage_ms) except: jlog.critical('cpu_usage_us ERROR: {}'.format(sys.exc_info())) ''' i['last_work_done'] = False if owner['name'] == producing: i['last_work_done'] = '<i class="fas fa-sync fa-spin fa-1x"></i>' else: try: if producers and isinstance(producers, list): for lbt in producers: if owner['name'] == lbt['owner']: ldt = parse(lbt['last_block_time']) ld = datetime.now() - ldt if ld.seconds < 1800: i['last_work_done'] = ( "<medium class='text-success'>{:.0f}</medium>" .format(ld.seconds)) if ld.seconds > 1801: i['last_work_done'] = ( "<medium class='text-warning'>{:.0f} Minutes</medium>" .format(ld.seconds / 60)) health += gen_health( title= 'Not producing blocks for at least 30 minutes' ) #if ld.seconds > 3600: # i['last_work_done'] = ("<medium class='text-danger'>{:.0f} Hours</medium>".format(ld.seconds / 60 / 60)) except: jlog.critical('last_work_done ERROR: {}'.format( sys.exc_info())) i['is_active'] = '' if producers and isinstance(producers, list): for producer in producers: if owner['name'] == producer['owner']: i['is_active'] = producer['is_active'] if producer['is_active']: i['is_active'] = '<span style="display:inline-block; width:60px" class="badge badge-success">Active</span>' if producer['is_active'] and owner['position'] > 21: i['is_active'] = '<span style="display:inline-block; width:60px" class="badge badge-warning">Rotated</span>' if producer['is_active'] and owner['position'] > 25: i['is_active'] = '<span style="display:inline-block; width:60px" class="badge badge-danger">Standby</span>' if not producer['is_active']: i['is_active'] = '<span style="color: Tomato;"><i class="fa fa-times"></i></text></span>' if owner['bp_json_url']: i['bp_json'] = '<a target="_blank" href="{}"><i class="fa fa-check"></i></a>'.format( owner['bp_json_url']) else: health += gen_health(title='bp.json is missing') i['bp_json'] = '' health += '</div></ul>' i['health'] = health d['data'].append(i) return jsonify(d)
def _listvoters(): price = False d = {} d['data'] = [] lv = listvoters() #print(sorted(lv['rows'], key=lambda k: (float(k['last_vote_weight'])), reverse=True)) if lv and 'rows' in lv and isinstance(lv['rows'], list): usd_rem = db.cache.find_one({"tag": "usd_rem"}, sort=[('created_at', pymongo.DESCENDING)]) if usd_rem and 'data' in usd_rem and 'USD' in usd_rem['data']: price = usd_rem['data']['USD'] r = 1 for g in lv['rows']: if not 'error' in g.keys(): if (float(g['staked']) > 2499999999): i = {} i['pending_perstake_reward_usd'] = '' try: dt = parse(g['last_reassertion_time']) days = datetime.now() - dt i['last_reassertion_time'] = '{}'.format(days.days) if days.days > 20: i['last_reassertion_time'] = '<medium class="text-warning">{}</medium>'.format( days.days) if days.days > 25: i['last_reassertion_time'] = '<medium class="text-danger">{}</medium>'.format( days.days) if days.days == 18267: i['last_reassertion_time'] = '' except: i['last_reassertion_time'] = '' i['position'] = r r += 1 i['owner'] = '<a href={0}>{1}</a>'.format( url_for('owner', owner=g['owner']), g['owner']) try: i['staked'] = "{:0,.0f}".format( (float(g['staked']) / 10000)) except: i['staked'] = '' jlog.critical('STAKED FLOAT ERROR: {}'.format( sys.exc_info())) try: i['last_vote_weight'] = "{:0,.0f}".format( (float(g['last_vote_weight']) / 10000)) except: i['last_vote_weight'] = '' jlog.critical( 'LAST_VOTE_WEIGHT FLOAT ERROR: {}'.format( sys.exc_info())) try: dt = parse(g['last_claim_time']) days = datetime.now() - dt if not days.days > 18000: i['last_claim_time'] = '{}'.format(days.days) else: i['last_claim_time'] = '{}'.format('-') except: i['last_claim_time'] = '' try: dt = parse(g['stake_lock_time']) days = dt - datetime.now() i['stake_lock_time'] = '{}'.format(days.days) #i['stake_lock_time'] = '{:%Y-%m-%d - %H:%M:%S}'.format(dt) except: i['stake_lock_time'] = '' try: remme = (g['pending_perstake_reward'] / 10000) if price: rem_usd = remme * price i['pending_perstake_reward_usd'] = '${:.2f}'.format( rem_usd) i['pending_perstake_reward'] = '{:.2f}'.format( remme) #i['pending_perstake_reward'] = '{:.2f} <small class="text-muted">${:.2f}</small>'.format(remme, rem_usd) else: i['pending_perstake_reward'] = "REM: {:.2f}".format( remme) except: i['pending_perstake_reward'] = '' try: i['producers'] = ' '.join(g['producers']) except: i['producers'] = '' d['data'].append(i) return jsonify(d)
def _dev(): get_info = remcli_get_info() producing = False if get_info: producing = get_info['head_block_producer'] lp = listproducers() rows = lp['rows'] owners = db.producers.find() data = [] for owner in owners: health = '<div><ul class="health">' if owner['health']: for issue in owner['health']: health += gen_health(issue['title']) html = '<div class="alert alert-info alert-dismissible fade show" role="alert">' name = owner['name'] html += '<h4>{}</h4>'.format(name) producer = next((item for item in rows if item["owner"] == name), None) if producer and producing: d = {} d['punished_until'] = False dt = parse(producer['punished_until']) days = dt - datetime.now() if days.days > 0: d['punished_until'] = days.days if d['punished_until']: health += gen_health(title='punished_until {}'.format( d['punished_until']), text=' {}'.format(d['punished_until'])) html += '<h4 class="alert-heading"><i class="fas fa-exclamation-triangle"></i> Punished for {} days.</h4>'.format( d['punished_until']) d['position'] = owner['position'] d['name'] = name d['total_votes'] = '{:0,.0f}'.format( float(producer['total_votes']) / 10000) d['voters'] = owner['voters_count'] d['social'] = owner['social'] d['cpu_usage_us'] = False try: if owner['cpu_usage_us']: cpu_usage_ms = owner['cpu_usage_us'] / 1000 if cpu_usage_ms > 1: d['cpu_usage_us'] = "<medium class='text-warning'>{:.2f} ms</medium>".format( cpu_usage_ms) if cpu_usage_ms < 1: d['cpu_usage_us'] = "<medium class='text-success'>{:.2f} ms</medium>".format( cpu_usage_ms) if cpu_usage_ms > 2: d['cpu_usage_us'] = "<medium class='text-danger'>{:.2f} ms</medium>".format( cpu_usage_ms) html += '<h4 class="alert-heading"><i class="fas fa-exclamation-triangle"></i> Slow CPU execution time.</h4>'.format( ) health += gen_health(title='Slow CPU') except: jlog.critical('cpu_usage_us ERROR: {}'.format(sys.exc_info())) d['last_work_done'] = False ldt = parse(producer['last_block_time']) ld = datetime.now() - ldt if owner['name'] == producing: d['last_work_done'] = '<i class="fas fa-sync fa-spin fa-1x"></i>' else: if ld.seconds < 1800: d['last_work_done'] = ( "<medium class='text-success'>{:.0f}</medium>".format( ld.seconds)) if ld.seconds > 1801: d['last_work_done'] = ( "<medium class='text-warning'>{:.0f} Minutes</medium>". format(ld.seconds / 60)) if owner['bp_json_url']: d['bp_json'] = '<a target="_blank" href="{}"><i class="fa fa-check"></i></a>'.format( owner['bp_json_url']) else: health += gen_health(title='bp.json is missing') html += '<h4 class="alert-heading"><i class="fas fa-exclamation-triangle"></i> bp.json is missing.</h4>'.format( ) d['bp_json'] = '' d['is_active'] = '' if producer['is_active']: d['is_active'] = '<span style="display:inline-block; width:60px" class="badge badge-success">Active</span>' if producer['is_active'] and owner['position'] > 21: d['is_active'] = '<span style="display:inline-block; width:60px" class="badge badge-warning">Rotated</span>' if producer['is_active'] and owner['position'] > 25: d['is_active'] = '<span style="display:inline-block; width:60px" class="badge badge-danger">Standby</span>' if not producer['is_active']: d['is_active'] = '<span style="color: Tomato;"><i class="fa fa-times"></i></text></span>' #if not owner['health']: # html += '<h4 class="alert-heading"><i class="far fa-thumbs-up"></i></h4>' #else: for h in owner['health']: html += '<h4 class="alert-heading"><i class="fas fa-exclamation-triangle"></i> {}!</h4>'.format( h['title']) for voter in owner['voters']: pass html += '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' html += '</div>' #d['dev'] = '<div data-toggle="tooltip" data-placement="top" title="dev!">dev</div>' d['html'] = html health += '</div></ul>' d['health'] = health data.append(d) return jsonify(data)
def cpu_usage(roundTo=7200, seconds=1209600): dt = (datetime.now() - timedelta(seconds=seconds)) producers = db.producers.find({}, { "name": 1, "position": 1, "color": 1, "_id": 0 }).limit(30) resp = [] if producers: for p in producers: if p['position'] < 22: #color = random_color() color = p['color'] red = '#FF2323' chart = {} chart['backgroundColor'] = color chart['borderColor'] = color chart['borderWidth'] = "1.8" chart['fill'] = 'false' chart['label'] = p['name'] chart['data'] = [] cpu_usage = db.cpu_usage_us.find_one( {"producer": "{}".format(p['name'])}, { "_id": 0, "data.block": 0, }, sort=([('time', pymongo.DESCENDING)])) l = [] low = [] if cpu_usage: for data in cpu_usage['data']: if data['timestamp'] > dt: y = data['cpu_usage_us'] / 10000 t = chart_time(data['timestamp'], roundTo=roundTo) d = {} d['t'] = t d['y'] = y low.append(t) l.append(d) try: low = min(low) except: low = False jlog.critical('low: {} {}'.format(p['name'], sys.exc_info())) ty = [] for xo in l: if low and xo['t'] == low: ty.append(xo['y']) else: low = xo['t'] d = {} try: av = "{:.4f}".format(sum(ty) / len(ty)) if float(av) > 0.3: chart['backgroundColor'] = red chart['borderColor'] = red d = {} d['t'] = xo['t'] d['y'] = av chart['data'].append(d) except: jlog.critical('cpu_usage ERROR: {}'.format( sys.exc_info())) ty = [] resp.append(chart) return (resp)