Esempio n. 1
0
 def test_miner_can_monitor(self):
     miner = Miner("test", '', '', '', '', '', '', '', '')
     self.assertFalse(miner.can_monitor())
     miner.ipaddress = '123.123.123.123'
     self.assertFalse(miner.can_monitor())
     miner.port = '4028'
     self.assertTrue(miner.can_monitor())
Esempio n. 2
0
def getminerinfo(miner: Miner):
    minerid = 'unknown'
    minertype = 'unknown'
    if not miner.can_monitor():
        raise MinerMonitorException(
            'miner {0} cannot be monitored. ip={1} port={2}'.format(
                miner.name, miner.ipaddress, miner.port))
    api = MinerApi(host=miner.ipaddress, port=int(miner.port), timeout=1)
    jstats = api.stats()
    #if there was an error then the return is STATUS not STATS!
    toplevelstatus = jstats['STATUS'][0]
    if toplevelstatus['STATUS'] == 'error':
        if not miner.is_disabled():
            raise MinerMonitorException(toplevelstatus['description'])
    else:
        status = jstats['STATS'][0]
        details = jstats['STATS'][1]
        if 'Type' in status:
            minertype = status['Type']
        else:
            if toplevelstatus['Description'].startswith('cgminer'):
                minertype = toplevelstatus['Description']
        if minertype == 'Antminer S9':
            minerid = details['miner_id']
    minerinfo = MinerInfo(minertype, minerid)
    return minerinfo
Esempio n. 3
0
def stats(miner: Miner):
    '''returns MinerStatistics, MinerInfo, and MinerApiCall'''
    if not miner.can_monitor():
        raise MinerMonitorException(
            'miner {0} cannot be monitored. ip={1} port={2}'.format(
                miner.name, miner.ipaddress, miner.port))

    try:
        thecall = MinerApiCall(miner)
        entity = domain.minerstatistics.MinerStatistics(
            miner, when=datetime.datetime.utcnow())
        api = MinerApi(host=miner.ipaddress, port=int(miner.port))

        thecall.start()
        #jstats = api.stats()
        stats_and_pools = api.command('stats+pools')
        thecall.stop()
        if 'stats' in stats_and_pools:
            jstats = stats_and_pools['stats'][0]
        else:
            #if call failed then only one result is returned, so parse it
            jstats = stats_and_pools
        entity.rawstats = jstats
        jstatus = jstats['STATUS']
        if jstatus[0]['STATUS'] == 'error':
            if not miner.is_disabled():
                raise MinerMonitorException(jstatus[0]['description'])
        else:
            miner_software = parse_miner_software(jstats)
            if miner_software.startswith('sgminer'):
                jstats = stats_and_pools['STATS']
                jsonstats = jstats
                status = jstats[0]
                jstatus = stats_and_pools['STATUS']
                minerinfo = helpers.antminerhelper.parse_statistics_inno(
                    entity, jsonstats, status)

            else:
                status = jstats['STATS'][0]
                jsonstats = jstats['STATS'][1]

                minerinfo = parse_minerinfo(status)

                #build MinerStatistics from stats
                parse_statistics(entity, jsonstats, status)
                minerpool = parse_minerpool(miner, stats_and_pools['pools'][0])

            return entity, minerinfo, thecall, minerpool
    except BaseException as ex:
        print('Failed to call miner stats api: ' + str(ex))
        raise MinerMonitorException(ex)
    return None, None, None, None