コード例 #1
0
def get_num_of_all_rigs(panel_name=None):
    """Get number of all available rigs
    if poll_name is not give will count for all polls
    """
    all_rigs = 0
    if panel_name is None:
        all_coll_names = mongo.db.collection_names()
    else:
        all_coll_names = [str(panel_name)]
    for collection_name in all_coll_names:
        collection = mongo.db[collection_name]
        # find_one returns dict, find  returns cursor
        unique_hostnames = collection.find({}).distinct('hostname')  # Uniquie Hostnames = Rigs
        for host in unique_hostnames:
            cursor = collection.find({'hostname': str(host)}, {'received_at': 1}) \
                .sort('received_at', flask_pymongo.DESCENDING) \
                .limit(1)
            if cursor.count() > 0:
                res = list(cursor)
                dict_res = res[0]
                received_at_utc = dict_res['received_at']
                received_at_utc_local = curr_time_non_naive(received_at_utc)
                now_local = curr_time_naive(datetime.datetime.utcnow())
                dif = now_local - received_at_utc_local
                days, hours, minutes = days_hours_minutes(dif)
                if days < int(Config.APP_SETTINGS_PERIOD_TO_HIDE_RIG):
                    all_rigs += 1
    return all_rigs
コード例 #2
0
def get_num_of_alive_rigs(panel_name=None):
    """Get number of all rigs using APP_SETTINGS_PERIOD_TO_LIVE to define aliveness=)
    if poll_name is notFd= give will count for all polls
    """
    alive_rigs = 0
    if panel_name is None:
        all_coll_names = mongo.db.collection_names()
    else:
        all_coll_names = [str(panel_name)]
    for collection_name in all_coll_names:
        collection = mongo.db[collection_name]
        # find_one returns dict, find  returns cursor
        unique_hostnames = collection.find({}).distinct('hostname')  # Uniquie Hostnames = Rigs
        for host in unique_hostnames:
            cursor = collection.find({'hostname': str(host)}, {'received_at': 1, 'hash': 1}) \
                .sort('received_at', flask_pymongo.DESCENDING) \
                .limit(1)
            if cursor.count() > 0:
                res = list(cursor)
                dict_res = res[0]
                received_at_utc = dict_res['received_at']
                received_at_utc_local = curr_time_non_naive(received_at_utc)
                now_local = curr_time_naive(datetime.datetime.utcnow())
                dif = now_local - received_at_utc_local
                days, hours, minutes = days_hours_minutes(dif)
                if all_min_from_td(dif) <= int(Config.APP_SETTINGS_PERIOD_TO_LIVE) and days < int(
                        Config.APP_SETTINGS_PERIOD_TO_HIDE_RIG):
                    total_hash = re.findall(r"[-+]?\d*\.\d+|\d+", dict_res['hash'])
                    if total_hash:
                        if float(total_hash[0]) != 0.0:
                            alive_rigs += 1
                            a = 2
    return alive_rigs
コード例 #3
0
def get_num_and_list_of_alive_panels():
    """Get alive """
    alive_pools = 0
    list_of_alive_polls = []
    all_coll_names = mongo.db.collection_names()
    is_found_for_this_pool = {}
    for host in all_coll_names:
        is_found_for_this_pool[str(host)] = False
    for collection_name in all_coll_names:
        collection = mongo.db[collection_name]
        # find_one returns dict, find  returns cursor
        unique_hostnames = collection.find({}).distinct('hostname')  # Uniquie Hostnames = Rigs
        for host in unique_hostnames:
            if not is_found_for_this_pool[str(collection_name)]:
                cursor = collection.find({'hostname': str(host)}, {'hash': 1, 'received_at': 1}) \
                    .sort('received_at', flask_pymongo.DESCENDING) \
                    .limit(1)
                if cursor.count() > 0:
                    res = list(cursor)
                    dict_res = res[0]
                    received_at_utc = dict_res['received_at']
                    received_at_utc_local = curr_time_non_naive(received_at_utc)
                    now_local = curr_time_naive(datetime.datetime.utcnow())
                    dif = now_local - received_at_utc_local
                    days, hours, minutes = days_hours_minutes(dif)
                    if days <= int(Config.APP_SETTINGS_PERIOD_TO_HIDE_PANEL):
                        alive_pools += 1
                        list_of_alive_polls.append(str(collection_name))
                        is_found_for_this_pool[str(collection_name)] = True

    return alive_pools, list_of_alive_polls
コード例 #4
0
def get_dict_of_ip_info_all():
    dict_of_ip_info = {'Working local configuration': []}
    all_coll_names = mongo.db.collection_names()
    for collection_name in all_coll_names:
        collection = mongo.db[collection_name]
        # find_one returns dict, find  returns cursor
        unique_hostnames = collection.find({}).distinct('hostname')
        for host in unique_hostnames:
            cursor = collection.find({'hostname': str(host)}, {'received_at': 1, 'send_remote': 1, "config_status": 1}) \
                .sort('received_at', flask_pymongo.DESCENDING) \
                .limit(1)
            if cursor.count() > 0:
                res = list(cursor)
                dict_res = res[0]
                received_at_utc = dict_res['received_at']
                received_at_utc_local = curr_time_non_naive(received_at_utc)
                now_local = curr_time_naive(datetime.datetime.utcnow())
                dif = now_local - received_at_utc_local
                days, hours, minutes = days_hours_minutes(dif)
                if days < int(Config.APP_SETTINGS_PERIOD_TO_HIDE_RIG):
                    config_status = dict_res.get('config_status')
                    send_remote = dict_res.get('send_remote')
                    if not send_remote and config_status == 'singlerig':
                        dict_of_ip_info['Working local configuration'].append(
                            host)
                    else:
                        if not dict_of_ip_info.get(send_remote):
                            dict_of_ip_info[send_remote] = []
                            dict_of_ip_info[send_remote].append(host)
                        else:
                            dict_of_ip_info[send_remote].append(host)
    return dict_of_ip_info
コード例 #5
0
def get_num_of_gpus(panel_name=None):
    """Number of GPUs
    if poll_name is not give will count for all polls
    """
    all_gpus = 0
    if panel_name is None:
        all_coll_names = mongo.db.collection_names()
    else:
        all_coll_names = [str(panel_name)]
    for collection_name in all_coll_names:
        collection = mongo.db[collection_name]
        # find_one returns dict, find  returns cursor
        unique_hostnames = collection.find({}).distinct('hostname')  # Uniquie Hostnames = Rigs
        for host in unique_hostnames:
            cursor = collection.find({'hostname': str(host)}, {'gpus': 1, 'received_at': 1}) \
                .sort('received_at', flask_pymongo.DESCENDING) \
                .limit(1)
            if cursor.count() > 0:
                res = list(cursor)
                dict_res = res[0]
                gpus_string = dict_res['gpus']
                received_at_utc = dict_res['received_at']
                received_at_utc_local = curr_time_non_naive(received_at_utc)
                now_local = curr_time_naive(datetime.datetime.utcnow())
                dif = now_local - received_at_utc_local
                days, hours, minutes = days_hours_minutes(dif)
                if days < int(
                        Config.APP_SETTINGS_PERIOD_TO_HIDE_RIG):
                    res_list = [int(s) for s in re.findall(r'\d+', gpus_string)]
                    if res_list:
                        num_of_gpus = res_list[0]
                        all_gpus += num_of_gpus

    return all_gpus
コード例 #6
0
def get_list_of_offline_rigs(panel_name):
    offline_rigs_list = []
    all_coll_names = mongo.db.collection_names()
    if panel_name in all_coll_names:
        collection = mongo.db[str(panel_name)]
        # find_one returns dict, find  returns cursor
        unique_hostnames = collection.find({}).distinct('hostname')  # Uniquie Hostnames = Rigs
        for host in unique_hostnames:
            cursor = collection.find({'hostname': str(host)}, {'received_at': 1, 'hash': 1}) \
                .sort('received_at', flask_pymongo.DESCENDING) \
                .limit(1)
            if cursor.count() > 0:
                res = list(cursor)
                dict_res = res[0]
                received_at_utc = dict_res['received_at']
                received_at_utc_local = curr_time_non_naive(received_at_utc)
                now_local = curr_time_naive(datetime.datetime.utcnow())
                dif = now_local - received_at_utc_local
                days, hours, minutes = days_hours_minutes(dif)
                if all_min_from_td(dif) > int(Config.APP_SETTINGS_PERIOD_TO_LIVE) and days < int(
                        Config.APP_SETTINGS_PERIOD_TO_HIDE_RIG):
                    offline_rigs_list.append(host)
                total_hash = re.findall(r"[-+]?\d*\.\d+|\d+", dict_res['hash'])
                if total_hash:
                    if float(total_hash[0]) == 0.0:
                        if host not in offline_rigs_list:
                            offline_rigs_list.append(host)

    a = 2
    return offline_rigs_list
コード例 #7
0
def get_num_of_rigs_under_attack(panel_name=None):
    num_of_rigs_under_attack = 0
    if panel_name is None:
        all_coll_names = mongo.db.collection_names()
    else:
        all_coll_names = [str(panel_name)]
    for collection_name in all_coll_names:
        collection = mongo.db[collection_name]
        # find_one returns dict, find  returns cursor
        unique_hostnames = collection.find({}).distinct('hostname')  # Uniquie Hostnames = Rigs
        for host in unique_hostnames:
            cursor = collection.find({'hostname': str(host)}, {'received_at': 1, 'hash': 1, "rx_kbps": 1, "tx_kbps": 1}) \
                .sort('received _at', flask_pymongo.DESCENDING) \
                .limit(1)
            if cursor.count() > 0:
                res = list(cursor)
                dict_res = res[0]
                received_at_utc = dict_res['received_at']
                received_at_utc_local = curr_time_non_naive(received_at_utc)
                now_local = curr_time_naive(datetime.datetime.utcnow())
                dif = now_local - received_at_utc_local
                days, hours, minutes = days_hours_minutes(dif)
                if days < int(
                        Config.APP_SETTINGS_PERIOD_TO_HIDE_RIG):
                    rx_kbps = re.findall(r"[-+]?\d*\.\d+|\d+", dict_res['rx_kbps'])
                    tx_kbps = re.findall(r"[-+]?\d*\.\d+|\d+", dict_res['tx_kbps'])
                    if rx_kbps:
                        if float(rx_kbps[0]) >= Config.APP_RX_BAD_VALUE or float(tx_kbps[0]) >= Config.APP_TX_BAD_VALUE:
                            num_of_rigs_under_attack += 1
    return num_of_rigs_under_attack
コード例 #8
0
def get_list_of_not_hidden_rigs(panel_name):
    """Get list of all rigs using APP_SETTINGS_PERIOD_TO_LIVE to define aliveness=)
    if poll_name is not give will count for all polls
    """
    alive_rigs_list = []
    all_coll_names = mongo.db.collection_names()
    if panel_name in all_coll_names:
        collection = mongo.db[str(panel_name)]
        # find_one returns dict, find  returns cursor
        unique_hostnames = collection.find({}).distinct('hostname')  # Uniquie Hostnames = Rigs
        for host in unique_hostnames:
            cursor = collection.find({'hostname': str(host)}, {'received_at': 1}) \
                .sort('received_at', flask_pymongo.DESCENDING) \
                .limit(1)
            if cursor.count() > 0:
                res = list(cursor)
                dict_res = res[0]
                received_at_utc = dict_res['received_at']
                received_at_utc_local = curr_time_non_naive(received_at_utc)
                now_local = curr_time_naive(datetime.datetime.utcnow())
                dif = now_local - received_at_utc_local
                days, hours, minutes = days_hours_minutes(dif)
                if days < int(
                        Config.APP_SETTINGS_PERIOD_TO_HIDE_RIG):
                    alive_rigs_list.append(host)
    return alive_rigs_list
コード例 #9
0
def get_list_of_hostnames_with_crashed_gpus(panel_name):
    hosts_list = []
    all_coll_names = mongo.db.collection_names()
    if panel_name in all_coll_names:
        collection = mongo.db[str(panel_name)]
        # find_one returns dict, find  returns cursor
        unique_hostnames = collection.find({}).distinct('hostname')  # Uniquie Hostnames = Rigs
        for host in unique_hostnames:
            cursor = collection.find({'hostname': str(host)}, {'gpus': 1, 'received_at': 1, 'miner_hashes': 1}) \
                .sort('received_at', flask_pymongo.DESCENDING) \
                .limit(1)
            if cursor.count() > 0:
                res = list(cursor)
                dict_res = res[0]
                received_at_utc = dict_res['received_at']
                received_at_utc_local = curr_time_non_naive(received_at_utc)
                now_local = curr_time_naive(datetime.datetime.utcnow())
                dif = now_local - received_at_utc_local
                days, hours, minutes = days_hours_minutes(dif)
                if all_min_from_td(dif) <= int(Config.APP_SETTINGS_PERIOD_TO_LIVE) and days < int(
                        Config.APP_SETTINGS_PERIOD_TO_HIDE_RIG):
                    if dict_res['miner_hashes'] and dict_res['miner_hashes'] is not None:
                        hashes = dict_res['miner_hashes']
                        stripped = hashes.strip().split(' ')
                        if len(stripped) == 0:
                            gpu_hash = float(hashes)
                            if gpu_hash == 0.0:
                                hosts_list.append(host)
                        elif len(stripped) >= 2:
                            for _hash in stripped:
                                if (float(_hash)) == 0.0:
                                    hosts_list.append(host)
    return hosts_list
コード例 #10
0
def get_dict_of_bioses(panel_name=None):
    dict_of_bioses = {}
    if panel_name is None:
        all_coll_names = mongo.db.collection_names()
    else:
        all_coll_names = [str(panel_name)]
    for collection_name in all_coll_names:
        collection = mongo.db[collection_name]
        # find_one returns dict, find  returns cursor
        unique_hostnames = collection.find({}).distinct(
            'hostname')  # Uniquie Hostnames = Rigs
        for host in unique_hostnames:
            cursor = collection.find({'hostname': str(host)}, {'received_at': 1, 'bioses': 1}) \
                .sort('received_at', flask_pymongo.DESCENDING) \
                .limit(1)
            if cursor.count() > 0:
                res = list(cursor)
                dict_res = res[0]
                received_at_utc = dict_res['received_at']
                received_at_utc_local = curr_time_non_naive(received_at_utc)
                now_local = curr_time_naive(datetime.datetime.utcnow())
                dif = now_local - received_at_utc_local
                days, hours, minutes = days_hours_minutes(dif)
                if days < int(Config.APP_SETTINGS_PERIOD_TO_HIDE_RIG):
                    if dict_res.get("bioses"):
                        bioses_info = dict_res.get("bioses")
                        bioses_list = bioses_info.strip().split(' ')
                        for bios in bioses_list:
                            if bios not in dict_of_bioses:
                                dict_of_bioses[bios] = 1
                            else:
                                dict_of_bioses[bios] += 1

    return dict_of_bioses
コード例 #11
0
def get_total_hashrate(panel_name=None):
    """Get total hashrate
    if poll_name is not given will count for all polls
    """
    total_hashrate = 0
    if panel_name is None:
        all_coll_names = mongo.db.collection_names()
    else:
        all_coll_names = [str(panel_name)]
    for collection_name in all_coll_names:
        collection = mongo.db[collection_name]
        # find_one returns dict, find  returns cursor
        unique_hostnames = collection.find({}).distinct('hostname')  # Uniquie Hostnames = Rigs
        for host in unique_hostnames:
            cursor = collection.find({'hostname': str(host)}, {'hash': 1, 'received_at': 1}) \
                .sort('received_at', flask_pymongo.DESCENDING) \
                .limit(1)
            if cursor.count() > 0:
                res = list(cursor)
                dict_res = res[0]
                received_at_utc = dict_res['received_at']
                received_at_utc_local = curr_time_non_naive(received_at_utc)
                now_local = curr_time_naive(datetime.datetime.utcnow())
                dif = now_local - received_at_utc_local
                days, hours, minutes = days_hours_minutes(dif)
                if all_min_from_td(dif) <= int(Config.APP_SETTINGS_PERIOD_TO_LIVE) and days < int(
                        Config.APP_SETTINGS_PERIOD_TO_HIDE_RIG):
                    if dict_res['hash'] and dict_res['hash'] is not None:
                        total_hashrate += float(dict_res['hash'])
                    total_hashrate = round(total_hashrate, 3)
    return total_hashrate
コード例 #12
0
def get_dual_miners_list(panel_name=None):
    dual_miners_rigs = []
    if panel_name is None:
        all_coll_names = mongo.db.collection_names()
    else:
        all_coll_names = [str(panel_name)]
    for collection_name in all_coll_names:
        collection = mongo.db[collection_name]
        # find_one returns dict, find  returns cursor
        unique_hostnames = collection.find({}).distinct('hostname')  # Uniquie Hostnames = Rigs
        for host in unique_hostnames:
            cursor = collection.find({'hostname': str(host)}, {'received_at': 1, 'dualminer_status': 1}) \
                .sort('received_at', flask_pymongo.DESCENDING) \
                .limit(1)
            if cursor.count() > 0:
                res = list(cursor)
                dict_res = res[0]
                received_at_utc = dict_res['received_at']
                received_at_utc_local = curr_time_non_naive(received_at_utc)
                now_local = curr_time_naive(datetime.datetime.utcnow())
                dif = now_local - received_at_utc_local
                days, hours, minutes = days_hours_minutes(dif)
                if days < int(
                        Config.APP_SETTINGS_PERIOD_TO_HIDE_RIG):
                    if dict_res.get("dualminer_status"):
                        dual_miner_status = dict_res.get("dualminer_status")
                        if dual_miner_status == "enabled":
                            dual_miners_rigs.append(host)

    return dual_miners_rigs
コード例 #13
0
def get_unique_poll_info_list(panel_name=None):
    ret_list = []
    unique_pool_info_fields = []
    dict_of_rigs_with_unique_pool_info = {}
    if panel_name is None:
        all_coll_names = mongo.db.collection_names()
    else:
        all_coll_names = [str(panel_name)]
    for collection_name in all_coll_names:
        collection = mongo.db[collection_name]
        # find_one returns dict, find  returns cursor
        unique_hostnames = collection.find({}).distinct('hostname')
        for host in unique_hostnames:
            cursor = collection.find({'hostname': str(host)}, {'received_at': 1, 'pool_info': 1}) \
                .sort('received_at', flask_pymongo.DESCENDING) \
                .limit(1)
            if cursor.count() > 0:
                res = list(cursor)
                dict_res = res[0]
                received_at_utc = dict_res['received_at']
                received_at_utc_local = curr_time_non_naive(received_at_utc)
                now_local = curr_time_naive(datetime.datetime.utcnow())
                dif = now_local - received_at_utc_local
                days, hours, minutes = days_hours_minutes(dif)
                if days < int(Config.APP_SETTINGS_PERIOD_TO_HIDE_RIG):
                    if dict_res.get("pool_info"):
                        pool_info_str = dict_res.get("pool_info")
                        if dict_of_rigs_with_unique_pool_info.get(
                                pool_info_str) is None:
                            dict_of_rigs_with_unique_pool_info[
                                pool_info_str] = []
                            dict_of_rigs_with_unique_pool_info[
                                pool_info_str].append(host)
                        else:
                            dict_of_rigs_with_unique_pool_info[
                                pool_info_str].append(host)
                        if pool_info_str not in unique_pool_info_fields:
                            unique_pool_info_fields.append(pool_info_str)
                        # pool_info_str_split = pool_info_str.strip().split('\n')

    try:
        if unique_pool_info_fields:
            for pool_info_string in unique_pool_info_fields:
                pool_info_str_split = pool_info_string.strip().split('\n')
                res_dict = {}
                if dict_of_rigs_with_unique_pool_info.get(pool_info_string):
                    res_dict["hosts"] = dict_of_rigs_with_unique_pool_info[
                        pool_info_string]
                    res_dict["amount"] = len(
                        dict_of_rigs_with_unique_pool_info[pool_info_string])
                for _str in pool_info_str_split:
                    two_str = _str.strip().split(' ')
                    res_dict[two_str[0]] = two_str[1]
                ret_list.append(res_dict)
    except Exception as e:
        print(e)
        print("Exception get_list_of_dict_pool_info")
        return []
    return ret_list
コード例 #14
0
def get_dict_of_drive_names(panel_name=None):
    dict_of_drives = {}
    if panel_name is None:
        all_coll_names = mongo.db.collection_names()
    else:
        all_coll_names = [str(panel_name)]
    for collection_name in all_coll_names:
        collection = mongo.db[collection_name]
        # find_one returns dict, find  returns cursor
        unique_hostnames = collection.find({}).distinct(
            'hostname')  # Uniquie Hostnames = Rigs
        for host in unique_hostnames:
            cursor = collection.find({'hostname': str(host)}, {'received_at': 1, 'drive_name': 1}) \
                .sort('received_at', flask_pymongo.DESCENDING) \
                .limit(1)
            if cursor.count() > 0:
                res = list(cursor)
                dict_res = res[0]
                received_at_utc = dict_res['received_at']
                received_at_utc_local = curr_time_non_naive(received_at_utc)
                now_local = curr_time_naive(datetime.datetime.utcnow())
                dif = now_local - received_at_utc_local
                days, hours, minutes = days_hours_minutes(dif)
                if days < int(Config.APP_SETTINGS_PERIOD_TO_HIDE_RIG):
                    if dict_res.get("drive_name"):
                        mobo_str = dict_res.get("drive_name")
                        if "INTEL" in mobo_str:
                            mobo_list = mobo_str.strip().split(' ')
                            if len(mobo_list) >= 3:
                                mobo_str = "SSD"
                        if "ADATA" in mobo_str:
                            mobo_str = "SSD"
                        if "SAMSUNG" in mobo_str:
                            mobo_str = "SSD"
                        if "SanDisk SDSSDA120G" in mobo_str:
                            mobo_str = "SSD"
                        if "PH4-CE120" in mobo_str:
                            mobo_str = "SSD"
                        # Flash Drives
                        if "Ultra" in mobo_str:
                            mobo_str = "Flash Drive"
                        if "x800m" in mobo_str:
                            mobo_str = "Flash Drive"
                        if "Cruzer" in mobo_str:
                            mobo_str = "Flash Drive"
                        if mobo_str not in dict_of_drives:
                            dict_of_drives[mobo_str] = 1
                        else:
                            dict_of_drives[mobo_str] += 1

    return dict_of_drives
コード例 #15
0
def get_average_gpu_temperature(panel_name=None):
    """Get average temp of GPUs
    if poll_name is not give will count for all polls
    """
    all_temp = 0
    number_of_gpus = 0
    if panel_name is None:
        all_coll_names = mongo.db.collection_names()
    else:
        all_coll_names = [str(panel_name)]
    for collection_name in all_coll_names:
        collection = mongo.db[collection_name]
        # find_one returns dict, find  returns cursor
        unique_hostnames = collection.find({}).distinct('hostname')  # Uniquie Hostnames = Rigs
        for host in unique_hostnames:
            cursor = collection.find({'hostname': str(host)}, {'temp': 1, 'received_at': 1, 'miner_hashes': 1}) \
                .sort('received_at', flask_pymongo.DESCENDING) \
                .limit(1)
            if cursor.count() > 0:
                res = list(cursor)
                dict_res = res[0]
                received_at_utc = dict_res['received_at']
                received_at_utc_local = curr_time_non_naive(received_at_utc)
                now_local = curr_time_naive(datetime.datetime.utcnow())
                dif = now_local - received_at_utc_local
                days, hours, minutes = days_hours_minutes(dif)
                if all_min_from_td(dif) <= int(Config.APP_SETTINGS_PERIOD_TO_LIVE) \
                        and days < int(Config.APP_SETTINGS_PERIOD_TO_HIDE_RIG):
                    if dict_res['temp'] and dict_res['temp'] is not None:
                        temps = dict_res['temp']
                        stripped = temps.strip().split(' ')
                        if len(stripped) == 1:
                            gpu_temp = float(temps)
                            if gpu_temp > 0.0 and gpu_temp < 120.00:
                                all_temp += gpu_temp
                                number_of_gpus += 1
                        elif len(stripped) >= 2:
                            for temp in stripped:
                                if (float(temp)) > 0.0 and (float(temp)) < 120.00:
                                    all_temp += float(temp)
                                    number_of_gpus += 1
    if all_temp == 0 or number_of_gpus == 0:
        return 0
    else:
        av_temp = all_temp / number_of_gpus
        import math
        av_temp = math.ceil(av_temp * 100) / 100
        return av_temp
コード例 #16
0
def get_gpus_temp_info_dict(panel_name=None):
    gpu_temp_info = {}
    gpu_temp_info["COLD"] = 0
    gpu_temp_info["OK"] = 0
    gpu_temp_info["YELLOW"] = 0
    gpu_temp_info["RED"] = 0
    if panel_name is None:
        all_coll_names = mongo.db.collection_names()
    else:
        all_coll_names = [str(panel_name)]
    for collection_name in all_coll_names:
        collection = mongo.db[collection_name]
        # find_one returns dict, find  returns cursor
        unique_hostnames = collection.find({}).distinct('hostname')  # Uniquie Hostnames = Rigs
        for host in unique_hostnames:
            cursor = collection.find({'hostname': str(host)}, {'temp': 1, 'received_at': 1, 'miner_hashes': 1}) \
                .sort('received_at', flask_pymongo.DESCENDING) \
                .limit(1)
            if cursor.count() > 0:
                res = list(cursor)
                dict_res = res[0]
                received_at_utc = dict_res['received_at']
                received_at_utc_local = curr_time_non_naive(received_at_utc)
                now_local = curr_time_naive(datetime.datetime.utcnow())
                dif = now_local - received_at_utc_local
                days, hours, minutes = days_hours_minutes(dif)
                if all_min_from_td(dif) <= int(Config.APP_SETTINGS_PERIOD_TO_LIVE) \
                        and days < int(Config.APP_SETTINGS_PERIOD_TO_HIDE_RIG):
                    if dict_res['temp'] and dict_res['temp'] is not None:
                        temps = dict_res['temp']
                        split = re.findall(r"[-+]?\d*\.\d+|\d+", temps)
                        temps_list = [float(x) for x in split]
                        if temps_list:
                            for temp in temps_list:
                                if temp > 0.00 and temp <= 40.00:
                                    gpu_temp_info["COLD"] += 1
                                if temp > 40.00 and temp < 60.00:
                                    gpu_temp_info["OK"] += 1
                                if temp >= 60.00 and temp < 80.00:
                                    gpu_temp_info["YELLOW"] += 1
                                if temp >= 80.00 and temp < 120.00:
                                    gpu_temp_info["RED"] += 1

    return gpu_temp_info
コード例 #17
0
def execute_commands_on_multiple_rigs(self,
                                      panel_name=None,
                                      hosts=None,
                                      commands=None,
                                      username=None,
                                      password=None,
                                      miner_name=None,
                                      new_password=None,
                                      custom_command=None):
    all_coll_names = mongo.db.collection_names()
    ips_to_execute = {}
    if panel_name in all_coll_names:
        collection = mongo.db[panel_name]
        unique_hostnames = collection.find({}).distinct('hostname')
        for host in hosts:
            if host in unique_hostnames:
                cursor = collection.find({'hostname': str(host)}, {'ip': 1, 'received_at': 1}) \
                    .sort('received_at', flask_pymongo.DESCENDING) \
                    .limit(1)
                if cursor.count() > 0:
                    res = list(cursor)
                    dict_res = res[0]
                    ip = dict_res.get("ip")
                    received_at_utc = dict_res['received_at']
                    received_at_utc_local = curr_time_non_naive(
                        received_at_utc)
                    now_local = curr_time_naive(datetime.datetime.utcnow())
                    dif = now_local - received_at_utc_local
                    days, hours, minutes = days_hours_minutes(dif)
                    if days == 0 and hours == 0 and minutes <= 2:
                        ips_to_execute[host] = ip
        if ips_to_execute:
            executing_tasks = {}
            ips = 0
            for host in ips_to_execute:
                # REBOOT
                if commands.get("clear_thermals"):
                    task = execute_rig_clear_thermals_and_reboot.apply_async(
                        args=[ips_to_execute[host], username, password],
                        expire=240,
                        queue="ssh_tasks")
                    # reboot = execute_rig_reboot.apply_async(countdown=5,
                    #                                         args=[ips_to_execute[host], username, password],
                    #                                         expire=60)
                    # executing_tasks[host] = task
                elif commands.get("put_conf"):
                    task = execute_rig_putconf_and_reboot.apply_async(
                        args=[ips_to_execute[host], username, password],
                        expire=240,
                        queue="ssh_tasks")
                    # reboot = execute_rig_reboot.apply_async(countdown=5,
                    #                                         args=[ips_to_execute[host], username, password],
                    #                                         expire=60)
                elif commands["reboot"]:
                    reboot = execute_rig_reboot.apply_async(
                        countdown=2,
                        args=[ips_to_execute[host], username, password],
                        expire=240,
                        queue="ssh_tasks")
                elif commands["update_miners"]:
                    update_miners = execute_rig_update_miners.apply_async(
                        countdown=2,
                        args=[ips_to_execute[host], username, password],
                        expire=240,
                        queue="ssh_tasks")
                elif commands["allow_command"]:
                    allow_command = execute_rig_allow_command.apply_async(
                        countdown=2,
                        args=[ips_to_execute[host], username, password],
                        expire=240,
                        queue="ssh_tasks")
                elif commands["update_miner_with_name"]:
                    update_miner_with_name = execute_rig_update_miner_with_name.apply_async(
                        countdown=2,
                        args=[
                            ips_to_execute[host], username, password,
                            miner_name
                        ],
                        expire=240,
                        queue="ssh_tasks")
                elif commands["change_password"]:
                    change_pass = execute_change_password.apply_async(
                        countdown=2,
                        args=[
                            ips_to_execute[host], username, password,
                            new_password
                        ],
                        expire=300,
                        queue="ssh_tasks")
                elif commands["execute_custom_command"]:
                    execute_custom = execute_custom_command.apply_async(
                        countdown=2,
                        args=[
                            ips_to_execute[host], username, password,
                            custom_command
                        ],
                        expire=300,
                        queue="ssh_tasks")