Vim�UnDoε�ΰ—ΖΨΨΛPΙ1Ύ/½1’‘�KR¦ΛΖ–6ΑρMΞ|Rξ�E            return sorted(SystemHelpers.dict_to_string(miner_status))[[[[\]¦_Π����\8#υl:from coinmine_utils import CoinmineRequests, CoinmineUtils5�_Π����\8$υl,from  import CoinmineRequests, CoinmineUtils5�_Π#����\9Άυ
l+        return CoinmineRequests.get_config(5�_Π#����\9¤υ
l#        return CoinmineRequests.get5�_Π%����\9¥υ
l%        return CoinmineRequests.get()5�_Π	
����\9©υ	l    def get_config():5�_Π
	/����\9΄υ
l/            os.environ['MINARY_API_SERVER_URL']5�_Π	
����	V=\9Ύυ
    @staticmethod    def get_miner_stats():0        return CoinmineRequests.get_miner_stats(/            os.environ['MINARY_API_SERVER_URL']	        )5�_Π

����	V=\9Δυ	f    def get_status():5�_Π
'����	V=\9Υυf3        return CoinmineCli.get_config().get('coin')5�_Π
%����	V=\9Ϋυf6        return CoinmineCli.get_config().get('address')5�_Π
%����	V=\9αυf6        return CoinmineCli.get_config().get('api_url')5�_Π%����	V=\9γυf4        return CoinmineCli.get_config().get('token')5�_Π!*����	V=\9νυ "f<        return CoinmineCli.get_miner_stats().get('hashrate')5�_Π0����	V=\:υ/0A                    'timestamp': str(datetime.datetime.utcnow()),5�_Π%����%,V\:υ$%4        distro_info = CoinmineUtils.get_distro_info(*            os.environ['DISTRO_INFO_PATH']	        )&        uuid = CoinmineUtils.get_uuid()            os.environ['MACHINE_ID_PATH']	        )3        miner_stats = CoinmineCli.get_miner_stats())        config = CoinmineCli.get_config()5�_Π$����%%V\:υ$&^        υ$&]5�_Π%����&&V\:υ$&^        miner_status5�_Π%����&&V\:υ$&^        miner_status = Coinmin]5�_Π'����'.
v\:)υ&(^            return (5�_Π(����(.
V\:+υ'(                {!                    'uuid': uuid,"                    **distro_info,"                    **miner_stats,                    **config                }
            )5�_Π'����((
V\:/υ&(W            return 5�_Π'����((
V\:7υ&(W             return  miner_status5�_Π'����((
V\:8υ&(W!            return   miner_status5�_Π)7����((
V\:@υ(*WC            distro_info = CoinmineUtils.dict_to_string(distro_info)5�_Π)7����((
V\:Bυ(*W8            distro_info = CoinmineUtils.dict_to_string()5�_Π *����*B+9VB\:Jυ)*C            miner_stats = CoinmineUtils.dict_to_string(miner_stats)9            config = CoinmineUtils.dict_to_string(config)5�_Π! )����*B*9VB\:Lυ(*UD            distro_info = CoinmineUtils.dict_to_string(miner_status)5�_Π "!)����*B*9VB\:Lυ(*U9             = CoinmineUtils.dict_to_string(miner_status)5�_Π!#"+����+4
V\:Vυ*+
                'uuid: {}\n'                '{}\n'                '{}\n'                '{}'.format(!                            uuid,(                            distro_info,(                            miner_stats,"                            config                            )
            )5�_Π"$#*����++
V\:Wυ)+K            return (5�_Π#%$)����++
V\:\υ(*KE            miner_status = CoinmineUtils.dict_to_string(miner_status)5�_Π$&%*����++
V\:_υ)*            return 5�_Π%'&*����*JV\:wυ)*!    @staticmethod$    def get_human_readible_config():)        config = CoinmineCli.get_config()        return (3            'Current coin being mined:        {}\n'9            'Current address being mined to:  {}'.format(C                                                config.get('coin'),E                                                config.get('address')1                                                )	        )    @staticmethod)    def get_human_readible_miner_stats():-        stats = CoinmineCli.get_miner_stats()        return (+            'uptime:          {} minutes\n'&            'hashrate:        {} {}\n'#            'accepted shares: {}\n'#            'rejected shares: {}\n'$            'fan speed:       {}%\n'-            'temp:            {}Β° Celsius\n')            'pool:            {}'.format(8                                    stats.get('uptime'),:                                    stats.get('hashrate'),*                                    'H/s',A                                    stats.get('accepted_shares'),A                                    stats.get('rejected_shares'),;                                    stats.get('fan_speed'),6                                    stats.get('temp'),5                                    stats.get('pool')#                                  )	        )5�_Π&('����**V\:}υ
)$        return CoinmineRequests.get(?            os.environ['MINARY_API_SERVER_URL'], 'miner_status'5�_Π')(%����))V\:~υ
(X        return CoinmineRequests.get( os.environ['MINARY_API_SERVER_URL'], 'miner_status'5�_Π(*)����))V\:†υimport datetime5�_Π)+*����((V\:�υ(υ'5�_Π*,+!����))V\:‘	υ(!from utils import CoinmineRequest5�_Π+-,"����))V\:•υ(/from cli import CoinmineRequests, CoinmineUtils5�_Π,.-����))V\:™
υfrom cli import CoinmineUtils5�_Π-/.+����((V\:©υ'7        return CoinmineCli.get_miner_status.get('coin')5�_Π.0/!����((V\:Όυ(υ'5�_Π/10����))V\:ϊυfrom 5�_Π021"����((V\:ϋυ'"from utils import CoinmineRequests5�_Π132' ����((V\;υ&=            return CoinmineUtils.dict_to_string(miner_status)5�_Π243
Vim�UnDoε’ω=U‡¦3΅�q�3#'yϋ…Iχ	,Μ
�]γτίΙ        CCCC\Σ;μ_Π,����\Σ#�υ	S    access_key = CoinmineRequests.get("miner", MINARY_AWS_S3_CM_INSTALL_ACCESS_KEY)5�_Π����/	V/\Σ8υT    access_key = CoinmineRequests.get("config", MINARY_AWS_S3_CM_INSTALL_ACCESS_KEY)    awscli = AWS_Cli()    pass5�_Π����/V/\Σ8	υ    υ5�_Π����/V/\Σ9ƒυ    υ5�_Π%����/V/\Σ9 υ2    s3_config = CoinmineRequests.get(s3_config, 1)5�_Π/����/V/\Σ9Άυ3    s3_config = CoinmineRequests.get('s3_config, 1)5�_Π/����/V/\Σ9£υfrom aws_cli import AWS_Cli+from utils.requests import CoinmineRequestsif __name__ == "__main__":4    s3_config = CoinmineRequests.get('s3_config', 1)    pass5�_Π	(����/V/\Σ9®υ    υ5�_Π
	����/V/\Σ9Όυ
    AWS_Cli()5�_Π	
����/V/\Σ9Ζυ    aws = AWS_Cli()5�_Π
����/V/\Σ9Πυ    aws = AWS_Cli(s3_config)5�_Π
'����/V/\Σ:υ*    aws = AWS_Cli(s3_config['access_key'])5�_Π
����/V/\Σ:!υ
υυ    aws = AWS_Cli(s3_config['])5�_Π
����/V/\Σ:&υ
    aws = AWS_Cli(s3_config[])5�_Π����/V/\Σ:'υ
    aws = AWS_Cli()5�_Π#����/V/\Σ:+υ

#            "cm_install_host_path",5�_Π#����/V/\Σ:,υ
from aws_cli import AWS_Cli+from utils.requests import CoinmineRequestsif __name__ == "__main__":4    s3_config = CoinmineRequests.get("s3_config", 1)    aws = AWS_Cli($            "cm_install_access_key",$            "cm_install_secret_key",             "cm_install_bucket",            "cm_install_path",$            "cm_install_host_path",)    pass5�_Π����/V/\Σ:2υ	         "cm_install_access_key",5�_Π����/V/\Σ:5υ	+        s3_config[]"cm_install_access_key",5�_Π	����/V/\Σ:9υ
         "cm_install_secret_key",υ	
5�_Π
����/V/\Σ:;υ	        "cm_install_bucket",υ
5�_Π����/V/\Σ:=υ
        "cm_install_path",υ5�_Π����/V/\Σ:?υ
        "cm_install_host_path",υ
5�_Π����/V/\Σ:?υ
*        s3_config[]"cm_install_host_path",5�_Π����/V/\Σ:Aυ
%        s3_config[]"cm_install_path",5�_Π
����/V/\Σ:Aυ	'        s3_config[]"cm_install_bucket",5�_Π	����/V/\Σ:Aυ
+        s3_config[]"cm_install_secret_key",5�_Π(����/V/\Σ:Dυ	*        s3_config["cm_install_access_key",υ	5�_Π	(����/V/\Σ:Eυ
*        s3_config["cm_install_secret_key",υ	
5�_Π 
$����/V/\Σ:Fυ	&        s3_config["cm_install_bucket",υ
5�_Π! "����/V/\Σ:Gυ
$        s3_config["cm_install_path",υ5�_Π "!'����/V/\Σ:Hυ
예제 #3
0
Vim�UnDo�!�U��a�+~��`x;D���-Wr}n��[���(;                self.bucket + "/" + self.s3_path, self.path7++++\�D�_�����\�����5�_�����\���5�_�����'V\���import boto3class AWS_Cli:K    def __init__(self, access_key, secret_key, bucket, s3_path, host_path):$        self.access_key = access_key$        self.secret_key = secret_key    def configure(self):%        self.session = boto3.Session(T            aws_access_key_id=self.access_key, aws_secret_access_key=self.secret_key	        )    def get_cm_install(self):T        self.session.Object(self.bucket, self.s3_path).download_file(self.host_path)    @staticmethod    def get_credentials(self):        pass5�_�����V\���R        s3_session.Object(self.bucket, self.s3_path).download_file(self.host_path)5�_�����V\���0        s3_session = self.session.resource("s3")G        Object(self.bucket, self.s3_path).download_file(self.host_path)5�_�1����V\���p        s3_session = self.session.resource("s3") Object(self.bucket, self.s3_path).download_file(self.host_path)5�_�	����V\���p        s3_session = self.session.resource("s3").Object(self.bucket, self.s3_path).download_file(self.host_path)5�_�
	����V\���import boto3class AWS_Cli:K    def __init__(self, access_key, secret_key, bucket, s3_path, host_path):$        self.access_key = access_key$        self.secret_key = secret_key    def configure(self):%        self.session = boto3.Session(T            aws_access_key_id=self.access_key, aws_secret_access_key=self.secret_key	        )    def get_cm_install(self):c        self.session.resource("s3").Object(self.bucket, self.s3_path).download_file(self.host_path)    @staticmethod    def get_credentials(self):        pass5�_�	
����V\���	        �	5�_�
����V\���
        �
5�_�
	����V\���
        self.s3_path5�_�
	����V\���	        �	5�_�
����V\���    �5�_�����V\���    def _make_executable()5�_�����V\���    def _make_executable():5�_�����V\�����5�_�����&&V&\���'s.chmod("/home/satoshi/testing", 0o775)5�_�����&&V&\���+    s.chmod("/home/satoshi/testing", 0o775)5�_�����&&V&\���/        s.chmod("/home/satoshi/testing", 0o775)5�_�����&&V&\����5�_�(����&&V&\���0        os.chmod("/home/satoshi/testing", 0o775)5�_�����&&V&\���        �5�_�����&&V&\�	��5�_�����&&V&\�r�        �5�_�����&&V&\��
�    def get_credentials(self):5�_�����&&V&\���         �5�_� ���� & &V&\��� 	import osimport boto3class AWS_Cli:K    def __init__(self, access_key, secret_key, bucket, s3_path, host_path):$        self.access_key = access_key$        self.secret_key = secret_key        self.bucket = bucket        self.s3_path = s3_path"        self.host_path = host_path    def configure(self):%        self.session = boto3.Session(T            aws_access_key_id=self.access_key, aws_secret_access_key=self.secret_key	        )    def get_cm_install(self):T        self.session.resource("s3").Object(self.bucket, self.s3_path).download_file(            self.host_path	        )-        self._make_executable(self.host_path)    @staticmethod"    def get_cm_install_info(self):%        CoinmineRequests.get('miner')        pass    @staticmethod    def _make_executable(path):        os.chmod(path, 0o775)5�_�! ����&&V&\���5�_� "!����&&V&\���        pass5�_�!#"����&&V&\����5�_�"$#����&&V&\�;�� � 5�_�#%$����&&V&\�;��$        �#5�_�$&%>����&&V&\�<'�$D        logger.info('successfully downloaded cm_install bucket={} ')5�_�%'&?����&&V&\�<,�$B        logger.info('successfully downloaded cm_install path={} ')5�_�&('J����&&V&\�</�$L        logger.info('successfully downloaded cm_install path={} host_path ')5�_�')(M����&&V&\�<0�$N        logger.info('successfully downloaded cm_install path={} host_path={}')5�_�(*)d����&&V&\�<C�$f        logger.info('successfully downloaded cm_install path={} host_path={}'.format(self.bucket+'/'))5�_�)+*{����&&V&\�<N�$	import osimport boto3+from utils.requests import CoinmineRequests from utils import CoinmineLogger!logger = CoinmineLogger(__name__)class AWS_Cli:K    def __init__(self, access_key, secret_key, bucket, s3_path, host_path):$        self.access_key = access_key$        self.secret_key = secret_key        self.bucket = bucket        self.s3_path = s3_path"        self.host_path = host_path    def configure(self):%        self.session = boto3.Session(T            aws_access_key_id=self.access_key, aws_secret_access_key=self.secret_key	        )    def get_cm_install(self):T        self.session.resource("s3").Object(self.bucket, self.s3_path).download_file(            self.host_path	        )-        self._make_executable(self.host_path)~        logger.info('successfully downloaded cm_install path={} host_path={}'.format(self.bucket+'/'+self.s3_path, self.path))    @staticmethod"    def get_cm_install_info(self):%        CoinmineRequests.get("miner")    @staticmethod    def _make_executable(path):        os.chmod(path, 0o775)5�_�*+7����\�D��(;                self.bucket + "/" + self.s3_path, self.path5�_� ����&&V&\���5�_�����&&V&\�<�"    def download_cm_install(self):5�_�
����V\���        �5�_�����V\���+        s3_se = self.session.resource("s3")5��
VimŸUnDoεƒ^ητ`Άir?ΞNͺA½ΜΗ?9Ή„ί'Ι	Μ‰?        ambiance = AmbianceController(teensy_interface, {}, "")
>



]B(	_Π
����
V]BΓυ
,        teensy_interface.serial_port.close()+        teensy_interface.serial_port.open()5_Π����	)v+]B&υ        υ5_Π1����	)v+]B&*υ3        print("counld not finish animation, e={}}")5_Π1����	)v+]B&,υ2        print("counld not finish animation, e={}")5_Π����	)v+]B&0υ    except Exception:5_Π����	)v+]B&2υ+from utils.requests import CoinmineRequests@from thunder_and_lightning.controllers import AmbianceController<from thunder_and_lightning.interfaces import TeensyInterface5from thunder_and_lightning.helpers import SerialUtilsif __name__ == "__main__":-    config_path = "/home/satoshi/config.yaml"!    uuid_path = "/etc/machine-id"    try:3        teensy_path = SerialUtils.get_teensy_port();        teensy_interface = TeensyInterface(teensy_path, "")*        teensy_interface.set_serial_port()?        ambiance = AmbianceController(teensy_interface, {}, ""))        ambiance.run_poweroff_animation()    except Exception as e:<        print("counld not finish animation, e={}",format(e))        passR    CoinmineRequests.send_powered_down_status_to_admin_api(config_path, uuid_path)5_Π	3����)v+]B&8υ=        print("counld not finish animation, e={}", format(e))5_Π
	����)v+]B&<υ        pass5_Π	

>����)v+]B(
	υ?        ambiance = AmbianceController(teensy_interface, {}, "")5_Π
����
+
+V.]BŠυ5ηͺ
VimЯUnDoеb3длуе,=ЦХ–#¤#УUH[ы%кWоЖHhЃШƒP                s.sendall(b'{"id":0,"jsonrpc":"2.0","method":"miner_getstat1"}')9L
	_†Џx	_–(W¤¤¤¤^Вb-х')X        miner_status["mining"] = MinerRequests._is_hashing(miner_status.get("hashrate"))5Б_–([¤¤¤¤^Вb/х
import socketimport json from utils import CoinmineLogger+from utils.requests import CoinmineRequests!logger = CoinmineLogger(__name__)class MinerRequests:    @staticmethod%    def get_miner_status(coin, urls):        # we assume not mining        miner_status = {            "uptime": 0,            "hashrate": 0,!            "hashrate_list": [0],            "pool": "",            "errors": [],	        }        try:            miners = {W                "ethereum": lambda: MinerRequests.get_claymore_stats(urls["claymore"]),T                "zcash": lambda: MinerRequests.get_claymore_stats(urls["claymore"]),O                "monero": lambda: MinerRequests.get_xmrig_stats(urls["xmrig"]),S                "grin": lambda: MinerRequests.get_lolminer_stats(urls["lolminer"]),G                "hashcat": lambda: MinerRequests.get_hashtopolis_stats('                    urls["hashtopolis"]                ),X                "handshake": lambda: MinerRequests.get_sixminer_stats(urls["sixminer"]),K                None: lambda: {"errors": "missing coin value from config"},
            }=            miner_status = {**miner_status, **miners[coin]()}I            logger.debug("received miner status {}".format(miner_status))        except Exception as e:G            logger.warning("failed to get miner status e={}".format(e))]        miner_status["mining"] = MinerRequests._is_hashing(miner_status.get("hashrate") or 0)        return miner_status    @staticmethod,    def get_claymore_stats(claymore_socket):        try:H            with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:                logger.debug(>                    "attempting to connect to claymore rpc on"1                    " {}".format(claymore_socket)                )*                s.connect(claymore_socket)9                logger.debug("connected to claymore rpc")                 s.settimeout(60)P                s.sendall(b'{"id":0,"jsonrpc":"2.0","method":"miner_getstat1"}')C                logger.debug("sent json for stats to claymore rpc")#                data = s.recv(1024)?                logger.debug("received data from claymore rpc")'            string_data = data.decode()/            json_data = json.loads(string_data)-            result_list = json_data["result"]*            uptime_in_min = result_list[1]:            accepted_shares = result_list[2].split(";")[1]:            rejected_shares = result_list[2].split(";")[2]%            hashrate = result_list[3]            # multigpu            if ";" in hashrate:E                hashrate_list = list(map(float, hashrate.split(";")))-                hashrate = sum(hashrate_list)            else:1                hashrate_list = [float(hashrate)]4            fan_speed = result_list[6].split(";")[1]/            temp = result_list[6].split(";")[0]!            pool = result_list[7]            stats = {4                "uptime": int(float(uptime_in_min)),*                "hashrate": int(hashrate),/                "hashrate_list": hashrate_list,8                "accepted_shares": int(accepted_shares),8                "rejected_shares": int(rejected_shares),,                "fan_speed": int(fan_speed),"                "temp": int(temp),                "pool": pool,
            }C            logger.debug("claymore socket stats: {}".format(stats))            return stats        except Exception as e:            logger.warning(T                "could not handle sending or receiving from socket:" " {}".format(e)
            )B            return {"errors": "claymore http service unavailable"}    @staticmethod)    def get_xmr_stak_stats(xmr_stak_url):        try:B            stats = CoinmineRequests.get(xmr_stak_url, "api.json").            pool = stats["connection"]["pool"]9            uptime_in_sec = stats["connection"]["uptime"]4            # will report 0 if a single thread fails4            hashrate = stats["hashrate"]["total"][0]             if hashrate is None:                hashrate = 0=            accepted_shares = stats["results"]["shares_good"]P            rejected_shares = stats["results"]["shares_total"] - accepted_shares8            # None values come from failed gpus/threads,7            # we want to accurately report the hashrate$            # even if a thread fails8            hashrate_list = stats["hashrate"]["threads"]            # convert None to 0P            hashrate_list = [0 if i[0] is None else i[0] for i in hashrate_list]>            total_hashrate_threads = round(sum(hashrate_list))            return {2                "uptime": int(uptime_in_sec / 60),D                "hashrate": int(hashrate) or total_hashrate_threads,/                "hashrate_list": hashrate_list,8                "accepted_shares": int(accepted_shares),8                "rejected_shares": int(rejected_shares),                "pool": pool,
            }        except Exception as e:L            logger.warning("could not return xmr-stak stats e={}".format(e))B            return {"errors": "xmr-stak http service unavailable"}    @staticmethod+    def get_nanominer_stats(nanominer_url):        try:            hashrate = 0            hashrate_list = []            accepted_shares = 0            rejected_shares = 0            uptime = 0@            stats = CoinmineRequests.get(nanominer_url, "stats")&            algs = stats["Algorithms"]            adapter = 0            for alg in algs:S                values = next(iter(alg.values()))  # gets the first value from dict/                algorithm = list(alg.keys())[0]>                hashrate += float(values["Total"]["Hashrate"])C                accepted_shares += int(values["Total"]["Accepted"])A                rejected_shares += int(values["Total"]["Denied"])0                pool = values.pop("CurrentPool")/                del values["ReconnectionCount"]#                del values["Total"]1                for key, value in values.items():7                    if key == "GPU {}".format(adapter):$                        adapter += 12                        if algorithm == "RandomX":>                            # pass on gpu hashrates on randomx$                            continueB                    hashrate_list.append(float(value["Hashrate"]))&            uptime = stats["WorkTime"]            return {%                "hashrate": hashrate,/                "hashrate_list": hashrate_list,!                "uptime": uptime,3                "accepted_shares": accepted_shares,3                "rejected_shares": rejected_shares,                "pool": pool,
            }        except Exception as e:M            logger.warning("could not return nanominer stats e={}".format(e))C            return {"errors": "nanominer http service unavailable"}    @staticmethodF    def get_teamredminer_stats(teamredminer_socket=("0.0.0.0", 4028)):        stats = {}        try:A            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)            logger.debug(>                "attempting to connect to teamredminer rpc on"1                " {}".format(teamredminer_socket)
            )*            s.connect(teamredminer_socket)9            logger.debug("connected to teamredminer rpc")            s.settimeout(60)!            s.sendall(b"summary")C            logger.debug("sent json for stats to teamredminer rpc")            data = s.recv(1024)?            logger.debug("received data from teamredminer rpc")'            string_data = data.decode().            list_data = string_data.split(",")=            stats["uptime"] = int(list_data[5].split("=")[1])I            hashrate = round(float(list_data[6].split("=")[1]) * 10e5, 3)(            stats["hashrate"] = hashrate/            stats["hashrate_list"] = [hashrate]G            stats["hardware_errors"] = int(list_data[14].split("=")[1])G            stats["accepted_shares"] = int(list_data[12].split("=")[1])G            stats["rejected_shares"] = int(list_data[13].split("=")[1])        except Exception as e:            logger.warning(Q                "could not handle sending or receiving from socket: {}".format(e)
            )        return stats    @staticmethod/    def get_hashtopolis_stats(hashtopolis_url):>        stats = CoinmineRequests.get(hashtopolis_url, "stats").        stats["hashrate"] = stats.pop("speed")4        stats["hashrate_list"] = [stats["hashrate"]]8        stats["accepted_shares"] = stats.pop("accepted")8        stats["uptime"] = stats.pop("uptime_in_seconds")        return stats    @staticmethod)    def get_lolminer_stats(lolminer_url):        stats = {}        try:@            data = CoinmineRequests.get(lolminer_url, "summary")            stats = {4                "uptime": data["Session"]["Uptime"],C                "hashrate": data["Session"]["Performance_Summary"],N                "hashrate_list": [gpu["Performance"] for gpu in data["GPUs"]],?                "accepted_shares": data["Session"]["Accepted"],?                "rejected_shares": data["Session"]["Submitted"].                - data["Session"]["Accepted"],8                "pool": data["Stratum"]["Current_Pool"],
            }        except Exception as e:H            logger.warning("could not get lolminer stats: {}".format(e))        return stats    @staticmethod*    def get_sixminer_stats(handshake_url):;        return MinerRequests.get_local_stats(handshake_url)    @staticmethod#    def get_xmrig_stats(xmrig_url):        stats = {}        try:?            data = CoinmineRequests.get(xmrig_url, "1/summary")            stats = {)                "uptime": data["uptime"],9                "hashrate": data["hashrate"]["total"][0],W                "hashrate_list": [thread[0] for thread in data["hashrate"]["threads"]],B                "accepted_shares": data["results"]["shares_good"],B                "rejected_shares": data["results"]["shares_total"]1                - data["results"]["shares_good"],3                "pool": data["connection"]["pool"],
            }        except Exception as e:E            logger.warning("could not get xmrig stats: {}".format(e))        return stats    @staticmethod    def get_local_stats(url):        stats = {}        try:5            data = CoinmineRequests.get(url, "stats")W            stats = {"hashrate": data["hashrate"], "hashrate_list": [data["hashrate"]]}        except Exception as e:E            logger.warning("could not get local stats: {}".format(e))        return stats    @staticmethod    def _is_hashing(hashrate):$        return bool(float(hashrate))5Б_–yC¤¤¤¤^Вd)хxz
D                "hashrate": int(hashrate) or total_hashrate_threads,5Б_–ц8¤¤¤¤^Вdѓххч
9                "hashrate": data["hashrate"]["total"][0],5Б_–ч+¤¤¤¤^Вiохцш
W                "hashrate_list": [thread[0] for thread in data["hashrate"]["threads"]],5Б_–	ч/¤¤¤¤^Вiрх

import socketimport json from utils import CoinmineLogger+from utils.requests import CoinmineRequests!logger = CoinmineLogger(__name__)class MinerRequests:    @staticmethod%    def get_miner_status(coin, urls):        # we assume not mining        miner_status = {            "uptime": 0,            "hashrate": 0,!            "hashrate_list": [0],            "pool": "",            "errors": [],	        }        try:            miners = {W                "ethereum": lambda: MinerRequests.get_claymore_stats(urls["claymore"]),T                "zcash": lambda: MinerRequests.get_claymore_stats(urls["claymore"]),O                "monero": lambda: MinerRequests.get_xmrig_stats(urls["xmrig"]),S                "grin": lambda: MinerRequests.get_lolminer_stats(urls["lolminer"]),G                "hashcat": lambda: MinerRequests.get_hashtopolis_stats('                    urls["hashtopolis"]                ),X                "handshake": lambda: MinerRequests.get_sixminer_stats(urls["sixminer"]),K                None: lambda: {"errors": "missing coin value from config"},
            }=            miner_status = {**miner_status, **miners[coin]()}I            logger.debug("received miner status {}".format(miner_status))        except Exception as e:G            logger.warning("failed to get miner status e={}".format(e));        miner_status["mining"] = MinerRequests._is_hashing(-            miner_status.get("hashrate") or 0	        )        return miner_status    @staticmethod,    def get_claymore_stats(claymore_socket):        try:H            with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:                logger.debug(>                    "attempting to connect to claymore rpc on"1                    " {}".format(claymore_socket)                )*                s.connect(claymore_socket)9                logger.debug("connected to claymore rpc")                 s.settimeout(60)P                s.sendall(b'{"id":0,"jsonrpc":"2.0","method":"miner_getstat1"}')C                logger.debug("sent json for stats to claymore rpc")#                data = s.recv(1024)?                logger.debug("received data from claymore rpc")'            string_data = data.decode()/            json_data = json.loads(string_data)-            result_list = json_data["result"]*            uptime_in_min = result_list[1]:            accepted_shares = result_list[2].split(";")[1]:            rejected_shares = result_list[2].split(";")[2]%            hashrate = result_list[3]            # multigpu            if ";" in hashrate:E                hashrate_list = list(map(float, hashrate.split(";")))-                hashrate = sum(hashrate_list)            else:1                hashrate_list = [float(hashrate)]4            fan_speed = result_list[6].split(";")[1]/            temp = result_list[6].split(";")[0]!            pool = result_list[7]            stats = {4                "uptime": int(float(uptime_in_min)),*                "hashrate": int(hashrate),/                "hashrate_list": hashrate_list,8                "accepted_shares": int(accepted_shares),8                "rejected_shares": int(rejected_shares),,                "fan_speed": int(fan_speed),"                "temp": int(temp),                "pool": pool,
            }C            logger.debug("claymore socket stats: {}".format(stats))            return stats        except Exception as e:            logger.warning(T                "could not handle sending or receiving from socket:" " {}".format(e)
            )B            return {"errors": "claymore http service unavailable"}    @staticmethod)    def get_xmr_stak_stats(xmr_stak_url):        try:B            stats = CoinmineRequests.get(xmr_stak_url, "api.json").            pool = stats["connection"]["pool"]9            uptime_in_sec = stats["connection"]["uptime"]4            # will report 0 if a single thread fails4            hashrate = stats["hashrate"]["total"][0]             if hashrate is None:                hashrate = 0=            accepted_shares = stats["results"]["shares_good"]P            rejected_shares = stats["results"]["shares_total"] - accepted_shares8            # None values come from failed gpus/threads,7            # we want to accurately report the hashrate$            # even if a thread fails8            hashrate_list = stats["hashrate"]["threads"]            # convert None to 0P            hashrate_list = [0 if i[0] is None else i[0] for i in hashrate_list]>            total_hashrate_threads = round(sum(hashrate_list))            return {2                "uptime": int(uptime_in_sec / 60),I                "hashrate": int(hashrate) or total_hashrate_threads or 0,/                "hashrate_list": hashrate_list,8                "accepted_shares": int(accepted_shares),8                "rejected_shares": int(rejected_shares),                "pool": pool,
            }        except Exception as e:L            logger.warning("could not return xmr-stak stats e={}".format(e))B            return {"errors": "xmr-stak http service unavailable"}    @staticmethod+    def get_nanominer_stats(nanominer_url):        try:            hashrate = 0            hashrate_list = []            accepted_shares = 0            rejected_shares = 0            uptime = 0@            stats = CoinmineRequests.get(nanominer_url, "stats")&            algs = stats["Algorithms"]            adapter = 0            for alg in algs:S                values = next(iter(alg.values()))  # gets the first value from dict/                algorithm = list(alg.keys())[0]>                hashrate += float(values["Total"]["Hashrate"])C                accepted_shares += int(values["Total"]["Accepted"])A                rejected_shares += int(values["Total"]["Denied"])0                pool = values.pop("CurrentPool")/                del values["ReconnectionCount"]#                del values["Total"]1                for key, value in values.items():7                    if key == "GPU {}".format(adapter):$                        adapter += 12                        if algorithm == "RandomX":>                            # pass on gpu hashrates on randomx$                            continueB                    hashrate_list.append(float(value["Hashrate"]))&            uptime = stats["WorkTime"]            return {%                "hashrate": hashrate,/                "hashrate_list": hashrate_list,!                "uptime": uptime,3                "accepted_shares": accepted_shares,3                "rejected_shares": rejected_shares,                "pool": pool,
            }        except Exception as e:M            logger.warning("could not return nanominer stats e={}".format(e))C            return {"errors": "nanominer http service unavailable"}    @staticmethodF    def get_teamredminer_stats(teamredminer_socket=("0.0.0.0", 4028)):        stats = {}        try:A            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)            logger.debug(>                "attempting to connect to teamredminer rpc on"1                " {}".format(teamredminer_socket)
            )*            s.connect(teamredminer_socket)9            logger.debug("connected to teamredminer rpc")            s.settimeout(60)!            s.sendall(b"summary")C            logger.debug("sent json for stats to teamredminer rpc")            data = s.recv(1024)?            logger.debug("received data from teamredminer rpc")'            string_data = data.decode().            list_data = string_data.split(",")=            stats["uptime"] = int(list_data[5].split("=")[1])I            hashrate = round(float(list_data[6].split("=")[1]) * 10e5, 3)(            stats["hashrate"] = hashrate/            stats["hashrate_list"] = [hashrate]G            stats["hardware_errors"] = int(list_data[14].split("=")[1])G            stats["accepted_shares"] = int(list_data[12].split("=")[1])G            stats["rejected_shares"] = int(list_data[13].split("=")[1])        except Exception as e:            logger.warning(Q                "could not handle sending or receiving from socket: {}".format(e)
            )        return stats    @staticmethod/    def get_hashtopolis_stats(hashtopolis_url):>        stats = CoinmineRequests.get(hashtopolis_url, "stats").        stats["hashrate"] = stats.pop("speed")4        stats["hashrate_list"] = [stats["hashrate"]]8        stats["accepted_shares"] = stats.pop("accepted")8        stats["uptime"] = stats.pop("uptime_in_seconds")        return stats    @staticmethod)    def get_lolminer_stats(lolminer_url):        stats = {}        try:@            data = CoinmineRequests.get(lolminer_url, "summary")            stats = {4                "uptime": data["Session"]["Uptime"],C                "hashrate": data["Session"]["Performance_Summary"],N                "hashrate_list": [gpu["Performance"] for gpu in data["GPUs"]],?                "accepted_shares": data["Session"]["Accepted"],?                "rejected_shares": data["Session"]["Submitted"].                - data["Session"]["Accepted"],8                "pool": data["Stratum"]["Current_Pool"],
            }        except Exception as e:H            logger.warning("could not get lolminer stats: {}".format(e))        return stats    @staticmethod*    def get_sixminer_stats(handshake_url):;        return MinerRequests.get_local_stats(handshake_url)    @staticmethod#    def get_xmrig_stats(xmrig_url):        stats = {}        try:?            data = CoinmineRequests.get(xmrig_url, "1/summary")            stats = {)                "uptime": data["uptime"],>                "hashrate": data["hashrate"]["total"][0] or 0,\                "hashrate_list": [thread[0] or 0 for thread in data["hashrate"]["threads"]],B                "accepted_shares": data["results"]["shares_good"],B                "rejected_shares": data["results"]["shares_total"]1                - data["results"]["shares_good"],3                "pool": data["connection"]["pool"],
            }        except Exception as e:E            logger.warning("could not get xmrig stats: {}".format(e))        return stats    @staticmethod    def get_local_stats(url):        stats = {}        try:5            data = CoinmineRequests.get(url, "stats")W            stats = {"hashrate": data["hashrate"], "hashrate_list": [data["hashrate"]]}        except Exception as e:E            logger.warning("could not get local stats: {}".format(e))        return stats    @staticmethod    def _is_hashing(hashrate):$        return bool(float(hashrate))5Б_–
	9L¤¤¤¤_†’w	х8:P                s.sendall(b'{"id":0,"jsonrpc":"2.0","method":"miner_getstat1"}')5Б_–	
1¤¤¤¤>+1v_†Џxх0?D        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:            logger.debug(:                "attempting to connect to claymore rpc on"-                " {}".format(claymore_socket)
            )&            s.connect(claymore_socket)5            logger.debug("connected to claymore rpc")            s.settimeout(60)L            s.sendall(b'{"id":0,"jsonrpc":"2.0","method":"miner_getstat2"}')?            logger.debug("sent json for stats to claymore rpc")            data = s.recv(1024);            logger.debug("received data from claymore rpc")#        string_data = data.decode()+        json_data = json.loads(string_data)5Б_–
1¤¤¤¤>'1v_†Џxх0?@    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:        logger.debug(6            "attempting to connect to claymore rpc on")            " {}".format(claymore_socket)	        )"        s.connect(claymore_socket)1        logger.debug("connected to claymore rpc")        s.settimeout(60)H        s.sendall(b'{"id":0,"jsonrpc":"2.0","method":"miner_getstat2"}');        logger.debug("sent json for stats to claymore rpc")        data = s.recv(1024)7        logger.debug("received data from claymore rpc")    string_data = data.decode()'    json_data = json.loads(string_data)5Б_–1¤¤¤¤1>V_†Џyх0?<with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:    logger.debug(2        "attempting to connect to claymore rpc on"%        " {}".format(claymore_socket)    )    s.connect(claymore_socket)-    logger.debug("connected to claymore rpc")    s.settimeout(60)D    s.sendall(b'{"id":0,"jsonrpc":"2.0","method":"miner_getstat2"}')7    logger.debug("sent json for stats to claymore rpc")    data = s.recv(1024)3    logger.debug("received data from claymore rpc")string_data = data.decode()#json_data = json.loads(string_data)5Б_–с¤¤¤¤^Вh™хрт
        stats = {	        }5Б_–с¤¤¤¤^ВhЂхстхтухту%                "accepted_shares": 0,$                "hashrate": 1041.74,:                "hashrate_list": [578.02, 231.77, 231.93],:                "pool": "xmr-us-east1.nanopool.org:14444",%                "rejected_shares": 0,                "uptime": 205,5Бз™
Vim�UnDo�N?��=��n842f��kx�X�e#w��.J        return [Consumer(queues=self.queues, callbacks=[self.on_message])]G1111]��e_�����]��#�5�_�����]��0��5�_�����V]��2�     class Worker(ConsumerMixin):/        def __init__(self, connection, queues):(            self.connection = connection             self.queues = queues3        def get_consumers(self, Consumer, channel):N            return [Consumer(queues=self.queues, callbacks=[self.on_message])],        def on_message(self, body, message):            if message:/                body = json.loads(message.body)F                logger.info("Got pubsub message body={}".format(body))K                CoinmineRequests.put(minary_api_server_url, "config", body)                message.ack()5�_�����V]��6�        �5�_�����V]��`��5�_�����V]��d��5�_�	����V]��j�	         self.callback = callback5�_�	����V]�͌��5�_�
	����V]�͍�import json&from kombu.mixins import ConsumerMixin+from utils.requests import CoinmineRequestsclass Worker(ConsumerMixin):+    def __init__(self, connection, queues):$        self.connection = connection        self.queues = queues/    def get_consumers(self, Consumer, channel):J        return [Consumer(queues=self.queues, callbacks=[self.on_message])](    def on_message(self, body, message):        if message:+            body = json.loads(message.body)B            logger.info("Got pubsub message body={}".format(body))G            CoinmineRequests.put(minary_api_server_url, "config", body)            message.ack()5�_�	

����V]�͢�
        �
5�_�
)����V]�ͪ�	+    def __init__(self, connection, queues):5�_�2����V]�ͳ�            �5�_�
����V]���class Worker(ConsumerMixin):5�_�����V]�� �            self.callback()5�_�����V]��"�
         self.callback = callback5�_�)����V]��%�	5    def __init__(self, connection, queues, callback):5�_�����V]��`��5�_�����V]��a�%    logger = CoinmineLogger(__name__)5�_�����V]��v��5�_�����V]��{�<from utils import SystemHelpers, CoinmineLogger, sentry_init5�_�!����V]��}�.from utils import  CoinmineLogger, sentry_init5�_� ����V]��}	�import json&from kombu.mixins import ConsumerMixin+from utils.requests import CoinmineRequests!from utils import  CoinmineLogger!logger = CoinmineLogger(__name__)$class ConfigConsumer(ConsumerMixin):+    def __init__(self, connection, queues):$        self.connection = connection        self.queues = queues/    def get_consumers(self, Consumer, channel):J        return [Consumer(queues=self.queues, callbacks=[self.on_message])](    def on_message(self, body, message):        if message:+            body = json.loads(message.body)B            logger.info("Got pubsub message body={}".format(body))G            CoinmineRequests.put(minary_api_server_url, "config", body)            message.ack()5�_�

����V]����
        �
5�_�)����V]����
+    def __init__(self, connection, queues):5�_�����V]��A
�        �5�_�����V]����
        self.fun = fun
        self.5�_�)����V]����
0    def __init__(self, connection, queues, fun):5�_� !����V]���G            CoinmineRequests.put(minary_api_server_url, "config", body)5�_�! 
����V]��#�
��
5�_� "!����V]��$�
self.minary_api_server_url5�_�!#"����V]��%�
    self.minary_api_server_url5�_�"$#"����V]��&�
"        self.minary_api_server_url5�_�#%$)����V]��*�
+    def __init__(self, connection, queues):5�_�$&%?����V]��-�import json&from kombu.mixins import ConsumerMixin+from utils.requests import CoinmineRequests from utils import CoinmineLogger!logger = CoinmineLogger(__name__)$class ConfigConsumer(ConsumerMixin):B    def __init__(self, connection, queues, minary_api_server_url):$        self.connection = connection        self.queues = queues9        self.minary_api_server_url= minary_api_server_url/    def get_consumers(self, Consumer, channel):J        return [Consumer(queues=self.queues, callbacks=[self.on_message])](    def on_message(self, body, message):        if message:+            body = json.loads(message.body)B            logger.info("Got pubsub message body={}".format(body))L            CoinmineRequests.put(self.minary_api_server_url, "config", body)            message.ack()5�_�%'&&����V]��d�+            body = json.loads(message.body)5�_�&('����V]��g�            �5�_�')(����V]���            print5�_�(*)����V]����            print(body)5�_�)+*����V]����            print(body)5�_�*,+����V]����#            body = json.loads(body)5�_�+-,����V]����            body = jsobody)5�_�,.-����V]��%�#            print(body, type(body))5�_�-/.G����]��L�J        return [Consumer(queues=self.queues, callbacks=[self.on_message])]5�_�.0/G����]��`�^        return [Consumer(queues=self.queues, callbacks=[self.on_message, auto_declare=False])]5�_�/10\����]��c�_        return [Consumer(queues=self.queues, callbacks=[self.on_message], auto_declare=False])]5�_�01\����]��d�import json&from kombu.mixins import ConsumerMixin+from utils.requests import CoinmineRequests from utils import CoinmineLogger!logger = CoinmineLogger(__name__)$class ConfigConsumer(ConsumerMixin):B    def __init__(self, connection, queues, minary_api_server_url):$        self.connection = connection        self.queues = queues:        self.minary_api_server_url = minary_api_server_url/    def get_consumers(self, Consumer, channel):^        return [Consumer(queues=self.queues, callbacks=[self.on_message], auto_declare=False)](    def on_message(self, body, message):        if message:B            logger.info("Got pubsub message body={}".format(body))L            CoinmineRequests.put(self.minary_api_server_url, "config", body)            message.ack()5�_� !����V]��!�2            CoinmineRequests.put(, "config", body)5�_�����V]��s��%    logger = CoinmineLogger(__name__)5�_�
����V]����5��
예제 #7
0
VimŸUnDoх–Ж˜š‘vНІвHЏ!ы+няЇеRњДŒ0Х†ш_;        logger.warn("Health Monitor failed e={}".format(e))]^q8L_аџџџџ^_Яѕ>        amdgpu_info_path = os.environ["MINARY_AMDGPU_PM_INFO"]5_аCџџџџ^_еѕBDaF            amdgpu_info_path, num_of_gpus, integrated_graphics_enabled5_аCџџџџ^_жѕa	import os/from utils import CoinmineLogger, SystemHelpers+from utils.requests import CoinmineRequestsXfrom health_monitor.docker import MinaryDocker, MinaryDockerCompose, DockerHealthChecker4from health_monitor.miner import AMDGPUHealthCheckerfrom adapters import AMDGPUInfo5from health_monitor.system import SystemHealthChecker3# from health_monitor.pool import PoolHealthChecker!logger = CoinmineLogger(__name__)if __name__ == "__main__":3    logger.info("Starting Coinmine Health Monitor")    try:!        hardreboot = "hardreboot"C        restart_minary_compose = "systemctl restart minary-compose"G        gpu_mineable_coins = ["ethereum", "zcash", "grin", "handshake"]'        cpu_mineable_coins = ["monero"]        # envsC        minary_api_server_url = os.environ["MINARY_API_SERVER_URL"]@        compose_filename = os.environ["MINARY_COMPOSE_FILENAME"]W        mem_clock_low_threshold = int(os.environ["MINARY_AMDGPU_MEMCLK_LOW_THRESHOLD"])'        mem_clock_high_threshold = int(=            os.environ["MINARY_AMDGPU_MEMCLK_HIGH_THRESHOLD"]	        )X        gpu_load_low_threshold = int(os.environ["MINARY_AMDGPU_GPU_LOAD_LOW_THRESHOLD"])T        gpu_watt_low_threshold = int(os.environ["MINARY_AMDGPU_WATT_LOW_THRESHOLD"])R        mem_percent_threshold = int(os.environ["MINARY_MEMORY_PERCENT_THRESHOLD"])$        # wait for minary_api_server        logger.info(7            "wait for minary_api_server: {}/{}".format(5                minary_api_server_url, "miner_status"
            )	        )*        SystemHelpers.wait_for_connection(V            lambda: (CoinmineRequests.test_get(minary_api_server_url, "miner_status"))	        )R        miner_status = CoinmineRequests.get(minary_api_server_url, "miner_status")'        coin = miner_status.get("coin")8        num_of_gpus = miner_status.get("num_of_gpus", 0)-        address = miner_status.get("address")3        admin_api_url = miner_status.get("api_url")1        short_uuid = miner_status.get("uuid")[:8]U        integrated_graphics_enabled = miner_status.get("integrated_graphics_enabled")        # Docker&        minary_docker = MinaryDocker())        minary_docker.initialize_client()E        minary_docker_compose = MinaryDockerCompose(compose_filename)0        oneshot_services = ["bootup_controller"]4        docker_health_checker = DockerHealthChecker(            minary_docker,"            minary_docker_compose,            oneshot_services,#            restart_minary_compose,	        )        # AMDGPU!        amdgpu_info = AMDGPUInfo(5             num_of_gpus, integrated_graphics_enabled	        )4        amdgpu_health_checker = AMDGPUHealthChecker(            amdgpu_info,            hardreboot,$            mem_clock_low_threshold,%            mem_clock_high_threshold,#            gpu_load_low_threshold,#            gpu_watt_low_threshold,            admin_api_url,            miner_status,	        )        # System4        system_health_checker = SystemHealthChecker(;            miner_status, mem_percent_threshold, hardreboot	        )        # PoolX        # pool_health_checker = PoolHealthChecker(coin, address, short_uuid, hardreboot)        # Checks%        docker_health_checker.check()%        system_health_checker.check()&        if coin in gpu_mineable_coins:)            amdgpu_health_checker.check()%        # pool_health_checker.check()    except Exception as e:;        logger.warn("Health Monitor failed e={}".format(e))3    logger.info("Finished Coinmine Health Monitor")5_а]џџџџ^q8Kѕ\^_;        logger.warn("Health Monitor failed e={}".format(e))5чЊ
예제 #8
0
Vim�UnDo������.���	U�{��~�`|8h��Q2                             {'power-down': True})"%5555\��?_�����\��`�>�>5�_�����\��e�?Nfrom utils import SystemHelpers, CoinmineRequests, CoinmineLogger, sentry_init5�_�?����\�N��?5�_�@����\�N��@�A�@5�_�A����\�O�@A2signal.signal(signal.SIGTERM, signal_term_handler)5�_�����\�O�A�A�@5�_�����V\�O�B2signal.signal(signal.SIGTERM, signal_term_handler)5�_�	����V\�O�6    signal.signal(signal.SIGTERM, signal_term_handler)5�_�
	����V\�O�A�A5�_�	
����V\�O�C�B5�_�
����V\�O �5�_�
B����V\�O8�B�C�B5�_�
D
����V\�O?�CEE    print 'got SIGTERM'5�_�
D����V\�OA�CEE    print ()'got SIGTERM'5�_�D����V\�OE�CD    print ('got SIGTERM')5�_�C����V\�OF�CEE    �CED5�_�D/����V\�OY�CEE0    logger.info('got signal handler, signal={}')5�_�B����V\�O_�BDE5�_�4+����V\�Of�36FL                    **CoinmineRequests.get(minary_api_server_url, 'config'),5�_�6+����V\�Oh�58GQ                    **CoinmineRequests.get(minary_api_server_url, 'system_info'),5�_�8+����V\�Oj	�7:HR                    **CoinmineRequests.get(minary_api_server_url, 'miner_status'),5�_�<����V\�Om
�;<5�_�D����DHV\�Ox�CD'def signal_term_handler(signal, frame):?    logger.info('got signal handler, signal={}'.format(signal))    sys.exit(0)5�_�
����DDV\�O{�D�D�
C5�_�
����JJV\�O|�
5�_�����IIV\�O}�H5�_�����JJV\�QK�I5�_�����KKV\�Q��K    �J5�_�����LLV\�R�K    CoinmineRequests.put()5�_�>����LLV\�R�K?    CoinmineRequests.put(minary_api_server_url, 'miner_status')5�_� M����LLV\�R$
�KO    CoinmineRequests.put(minary_api_server_url, 'miner_status', {'power-down'})5�_�! /����LLV\�R,�KU    CoinmineRequests.put(minary_api_server_url, 'miner_status', {'power-down': True})5�_� "!(����MMV\�R.�L>                         'miner_status', {'power-down': True})5�_�!#"����
V
\�S��'def signal_term_handler(signal, frame):?    logger.info('got signal handler, signal={}'.format(signal))/    CoinmineRequests.put(minary_api_server_url,(                         'miner_status',.                         {'power-down': True})    sys.exit(0)5�_�"$#����
V
\�S��G�G�F5�_�#%$����V\�S��N'def signal_term_handler(signal, frame):?    logger.info('got signal handler, signal={}'.format(signal))/    CoinmineRequests.put(minary_api_server_url,(                         'miner_status',.                         {'power-down': True})    sys.exit(0)5�_�$&%����V\�S��5�_�%'&����V\�S��5�_�&('����V\�S��+    def signal_term_handler(signal, frame):C        logger.info('got signal handler, signal={}'.format(signal))3        CoinmineRequests.put(minary_api_server_url,+                            'miner_status',1                            {'power-down': True})        sys.exit(0)5�_�')(����V\�S��F�F5�_�(*)����V\�S��L+                            'miner_status',5�_�)+*����V\�S��L1                            {'power-down': True})5�_�*,+����
V\�S��5�_�+-,����V\�S��+    def signal_term_handler(signal, frame):C        logger.info('got signal handler, signal={}'.format(signal))3        CoinmineRequests.put(minary_api_server_url,,                             'miner_status',2                             {'power-down': True})        sys.exit(0)6    signal.signal(signal.SIGTERM, signal_term_handler)5�_�,.-����V\�S��%B�B5�_�-/.����V\�S��K�J5�_�.0/#����\�X�#%K�#$K5�_�/10$����$$V\�X�#%L%            ambiance.run(full_status)5�_�021#����04V\�X$�#)L�#$L5�_�132$����$(V\�X%�#)Q    full_status = {@        **CoinmineRequests.get(minary_api_server_url, 'config'),E        **CoinmineRequests.get(minary_api_server_url, 'system_info'),F        **CoinmineRequests.get(minary_api_server_url, 'miner_status'),    }5�_�243#����$(V\�Y
�"#        sys.exit(0)5�_�354(����#'V\�Y�(*P�()P5�_�45"%����\��>�!#Q2                             {'power-down': True})5��
VimŸUnDoוa_ž®�±¢±7�פM²Š�¨F~ך�°כ�+W�¯DIŒJ            logger.warn("could not return grin miner stats", {"error": e})‡F,,,,\�ל5
_�$/����\��ץ#%ŒI            logger.debug("received miner status {}".format(miner_status))5_�$0����\��ץ#%Œ>            logger.debug("received miner status(miner_status))5_�$@����\��ץ#%Œ@            logger.debug("received miner status", miner_status))5_�&4����\��ץ%'ŒE            logger.error("failed to get miner status e={}".format(e))5_�&4����\��ץ%'Œ4            logger.error("failed to get miner status5_�&9����\��ץ%'Œ9            logger.error("failed to get miner status", ""5_�&?����\��ץ%'Œ@            logger.error("failed to get miner status", {"error"}5_�	&C����\��ץ%'ŒC            logger.error("failed to get miner status", {"error": e}5_�
	1:����\�מץ02Œ>                    "attempting to connect to claymore rpc on"5_�	
1:����\�ןץ02Œ:                    "attempting to connect to claymore rpc5_�
1:����\�סץ02Œ;                    "attempting to connect to claymore rpc"1                    " {}".format(claymore_socket)5_�
1;����\�עץ02‹Y                    "attempting to connect to claymore rpc" " {}".format(claymore_socket)5_�
1<����\�ףץ02‹L                    "attempting to connect to claymore rpc"(claymore_socket)5_�
1=����\�רץ02‹N                    "attempting to connect to claymore rpc", "claymore_socket)5_�1?����\�שץ02‹P                    "attempting to connect to claymore rpc", {}"claymore_socket)5_�1N����\��ץ02‹O                    "attempting to connect to claymore rpc", {"claymore_socket)ץ12‹5_�1a����\�žץ02‹b                    "attempting to connect to claymore rpc", {"claymore_socket": claymore_socket))5_�1b����\�žץ02‹b                    "attempting to connect to claymore rpc", {"claymore_socket": claymore_socket})5_�1`����\�žץ‹
import socketimport json from utils import CoinmineLogger+from utils.requests import CoinmineRequests!logger = CoinmineLogger(__name__)class MinerRequests:    @staticmethodN    def get_miner_status(coin, claymore_socket, xmr_stak_url, grin_miner_url):        # we assume not mining        miner_status = {            "uptime": 0,            "hashrate": 0,!            "hashrate_list": [0],!            "accepted_shares": 0,!            "rejected_shares": 0,            "fan_speed": 0,            "temp": 0,            "pool": "",            "errors": [],	        }        try:            miners = {V                "ethereum": lambda: MinerRequests.get_claymore_stats(claymore_socket),S                "zcash": lambda: MinerRequests.get_claymore_stats(claymore_socket),Q                "monero": lambda: MinerRequests.get_xmr_stak_stats(xmr_stak_url),S                "grin": lambda: MinerRequests.get_grin_miner_stats(grin_miner_url),K                None: lambda: {"errors": "missing coin value from config"},
            }=            miner_status = {**miner_status, **miners[coin]()}?            logger.debug("received miner status", miner_status)        except Exception as e:D            logger.error("failed to get miner status", {"error": e})X        miner_status["mining"] = MinerRequests._is_hashing(miner_status.get("hashrate"))        return miner_status    @staticmethod,    def get_claymore_stats(claymore_socket):        try:H            with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:                logger.debug(a                    "attempting to connect to claymore rpc", {"claymore_socket": claymore_socket}                )*                s.connect(claymore_socket)9                logger.debug("connected to claymore rpc")                 s.settimeout(60)P                s.sendall(b'{"id":0,"jsonrpc":"2.0","method":"miner_getstat1"}')C                logger.debug("sent json for stats to claymore rpc")#                data = s.recv(1024)?                logger.debug("received data from claymore rpc")'            string_data = data.decode()/            json_data = json.loads(string_data)-            result_list = json_data["result"]*            uptime_in_min = result_list[1]:            accepted_shares = result_list[2].split(";")[1]:            rejected_shares = result_list[2].split(";")[2]%            hashrate = result_list[3]            # multigpu            if ";" in hashrate:E                hashrate_list = list(map(float, hashrate.split(";")))-                hashrate = sum(hashrate_list)            else:1                hashrate_list = [float(hashrate)]4            fan_speed = result_list[6].split(";")[1]/            temp = result_list[6].split(";")[0]!            pool = result_list[7]            stats = {4                "uptime": int(float(uptime_in_min)),*                "hashrate": int(hashrate),/                "hashrate_list": hashrate_list,8                "accepted_shares": int(accepted_shares),8                "rejected_shares": int(rejected_shares),,                "fan_speed": int(fan_speed),"                "temp": int(temp),                "pool": pool,
            }C            logger.debug("claymore socket stats: {}".format(stats))            return stats        except Exception as e:            logger.warn(T                "could not handle sending or receiving from socket:" " {}".format(e)
            )B            return {"errors": "claymore http service unavailable"}    @staticmethod)    def get_xmr_stak_stats(xmr_stak_url):        try:B            stats = CoinmineRequests.get(xmr_stak_url, "api.json").            pool = stats["connection"]["pool"]9            uptime_in_sec = stats["connection"]["uptime"]4            # will report 0 if a single thread fails4            hashrate = stats["hashrate"]["total"][0]             if hashrate is None:                hashrate = 0=            accepted_shares = stats["results"]["shares_good"]P            rejected_shares = stats["results"]["shares_total"] - accepted_shares8            # None values come from failed gpus/threads,7            # we want to accurately report the hashrate$            # even if a thread fails8            hashrate_list = stats["hashrate"]["threads"]            # convert None to 0P            hashrate_list = [0 if i[0] is None else i[0] for i in hashrate_list]>            total_hashrate_threads = round(sum(hashrate_list))            return {2                "uptime": int(uptime_in_sec / 60),D                "hashrate": int(hashrate) or total_hashrate_threads,/                "hashrate_list": hashrate_list,8                "accepted_shares": int(accepted_shares),8                "rejected_shares": int(rejected_shares),                "pool": pool,
            }        except Exception as e:I            logger.warn("could not return xmr-stak stats e={}".format(e))B            return {"errors": "xmr-stak http service unavailable"}-    def get_grin_miner_stats(grin_miner_url):        try:A            stats = CoinmineRequests.get(grin_miner_url, "stats")5            hashrate = stats["results"]["graph_rate"]F            return {"hashrate": hashrate, "hashrate_list": [hashrate]}        except Exception as e:K            logger.warn("could not return grin miner stats e={}".format(e))D            return {"errors": "grin miner http service unavailable"}    @staticmethod    def _is_hashing(hashrate):)        return bool(int(float(hashrate)))5_�U#����\�žץTVŒC            logger.debug("claymore socket stats: {}".format(stats))5_�U#����\�žץTVŒC            logger.debug("claymore socket stats: {}".format(stats))5_�U����\�žץTVŒC            logger.debug("claymore socket stats: {}".format(stats))5_�U9����\�ž ץTVŒL            logger.debug("recieved claymore socket stats: {}".format(stats))5_�U9����\�ž!ץTVŒL            logger.debug("recieved claymore socket stats" {}".format(stats))5_�U9����\�ž"ץTVŒ9            logger.debug("recieved claymore socket stats"5_�YB����\�ž.ץXZŒT                "could not handle sending or receiving from socket:" " {}".format(e)5_�YB����\�ž0ץXZŒB                "could not handle sending or receiving from socket5_�YM����\�ž4ץXZŒN                "could not handle sending or receiving from socket", {"error"}5_� ~7����\�žEץ}ŒI            logger.warn("could not return xmr-stak stats e={}".format(e))ץ~Œ5_�! ~G����\�žFץ}ŒX            logger.warn("could not return xmr-stak stats", {"error": e} e={}".format(e))5_� #!~G����\�žJץ}ŒG            logger.warn("could not return xmr-stak stats", {"error": e}5_�!$"#‡9����\�žUץ†ˆŒK            logger.warn("could not return grin miner stats e={}".format(e))ץ‡ˆŒ5_�#%$‡J����\�žV	ץ†ˆŒ[            logger.warn("could not return grin miner stats", {"error": e}) e={}".format(e))5_�$&%&@����\�ל'ץ%'ŒD            logger.error("failed to get miner status", {"error": e})ץ&'Œ5_�%'&&F����\�ל(
ץ%'ŒH            logger.error("failed to get miner status", {"error": str(e})5_�&('YN����\�ל+ץXZŒQ                "could not handle sending or receiving from socket", {"error": e}ץYZŒ5_�')(YT����\�ל,ץXZŒU                "could not handle sending or receiving from socket", {"error": str(e}5_�(*)~D����\�ל/ץ}ŒH            logger.warn("could not return xmr-stak stats", {"error": e})ץ~Œ5_�)+*~J����\�ל0ץ}ŒL            logger.warn("could not return xmr-stak stats", {"error": str(e})5_�*,+‡F����\�ל3ץ†ˆŒJ            logger.warn("could not return grin miner stats", {"error": e})ץ‡ˆŒ5_�+,‡L����\�ל4
ץ†ˆŒN            logger.warn("could not return grin miner stats", {"error": str(e})5_�!#"~8����\�žQץ}Œ8            logger.warn("could not return xmr-stak stats5_�YB����\�žAץXZŒB                "could not handle sending or receiving from socket5_�1?����\�תץ02‹?                    "attempting to connect to claymore rpc", {"5ח×
예제 #10
0
VimŸUnDoх4ˆtwг‹lC’_Тi=юеzœ1ХB?QљГ-i]4444\п	и_аџџџџ\о#иѕѕ5_аџџџџ\о#йѕ5_а,џџџџ\о#мѕ.from utils.requests import CoinmineRequests; \5_а-џџџџ\о#нѕ-from utils.requests import CoinmineRequests \5_а+џџџџ\о#оѕ+from utils.requests import CoinmineRequests5_аџџџџ\о#шѕif __name__ == "__main__"5_аџџџџV\о#ыѕb             CoinmineRequests.send_powered_down_status_to_admin_api('$CONFIG_PATH', '$UUID_PATH')"5_а	џџџџV\о#ыѕa            CoinmineRequests.send_powered_down_status_to_admin_api('$CONFIG_PATH', '$UUID_PATH')"5_а
	џџџџV\о#ыѕ]        CoinmineRequests.send_powered_down_status_to_admin_api('$CONFIG_PATH', '$UUID_PATH')"5_а	
џџџџV\о#ёѕ}5_а

YџџџџV\о#ѕѕY    CoinmineRequests.send_powered_down_status_to_admin_api('$CONFIG_PATH', '$UUID_PATH')"5_а
WџџџџV\о#іѕ+from utils.requests import CoinmineRequestsif __name__ == "__main__":X    CoinmineRequests.send_powered_down_status_to_admin_api('$CONFIG_PATH', '$UUID_PATH')5_а
џџџџV\о#џѕѕ5_аџџџџV\о$ѕX    CoinmineRequests.send_powered_down_status_to_admin_api("$CONFIG_PATH", "$UUID_PATH")5_аџџџџV\о$ѕTCoinmineRequests.send_powered_down_status_to_admin_api("$CONFIG_PATH", "$UUID_PATH")5_аџџџџV\о$ѕ  UUID_PATH="/etc/machine-id"5_аџџџџV\о$	ѕ)  CONFIG_PATH="/home/satoshi/config.yaml"5_аџџџџv\о$ѕ+    CONFIG_PATH="/home/satoshi/config.yaml"5_аџџџџv\о$ѕ    UUID_PATH="/etc/machine-id"5_аџџџџv\о$ѕ    uUID_PATH="/etc/machine-id"5_аџџџџv\о$ѕ    uuID_PATH="/etc/machine-id"5_аџџџџv\о$ѕ    uuiD_PATH="/etc/machine-id"5_аџџџџv\о$ѕ    uuid_PATH="/etc/machine-id"5_а	џџџџv\о$ѕ    uuid_PATH="/etc/machine-id"5_а
џџџџv\о$ѕ    uuid_pATH="/etc/machine-id"5_аџџџџv\о$ѕ    uuid_paTH="/etc/machine-id"5_аџџџџv\о$ѕ    uuid_patH="/etc/machine-id"5_аIџџџџv\о$UѕX    CoinmineRequests.send_powered_down_status_to_admin_api("$CONFIG_PATH", "$UUID_PATH")5_аOџџџџv\о$\ѕP    CoinmineRequests.send_powered_down_status_to_admin_api(config, "$UUID_PATH")5_а Aџџџџv\о$bѕM    CoinmineRequests.send_powered_down_status_to_admin_api(config, uuid_path)5_а! Eџџџџv\о$dѕ+from utils.requests import CoinmineRequestsif __name__ == "__main__":+    config_path="/home/satoshi/config.yaml"    uuid_path="/etc/machine-id"R    CoinmineRequests.send_powered_down_status_to_admin_api(config_path, uuid_path)5_а "!*џџџџv\о$rѕѕ5_а!#"џџџџV\о$sѕ	H        from thunder_and_lightning.controllers import AmbianceControllerD        from thunder_and_lightning.interfaces import TeensyInterface=        from thunder_and_lightning.helpers import SerialUtils5_а"$#џџџџV\о$tѕ	D    from thunder_and_lightning.controllers import AmbianceController@    from thunder_and_lightning.interfaces import TeensyInterface9    from thunder_and_lightning.helpers import SerialUtils5_а#%$	џџџџV\о${ѕ	5_а$&%
џџџџV\о${ѕ
ѕ
5_а%)&џџџџV\о$}ѕ
3        teensy_path = SerialUtils.get_teensy_port();        teensy_interface = TeensyInterface(teensy_path, "")*        teensy_interface.set_serial_port(),        teensy_interface.serial_port.close()+        teensy_interface.serial_port.open()?        ambiance = AmbianceController(teensy_interface, {}, ""))        ambiance.run_poweroff_animation()5_а&*()
џџџџ!!V!\озѕ
ѕ
5_а)+*џџџџV\оз
ѕ/    teensy_path = SerialUtils.get_teensy_port()7    teensy_interface = TeensyInterface(teensy_path, "")&    teensy_interface.set_serial_port()(    teensy_interface.serial_port.close()'    teensy_interface.serial_port.open();    ambiance = AmbianceController(teensy_interface, {}, "")%    ambiance.run_poweroff_animation()5_а*,+џџџџV\оз'ѕ        ѕ5_а+-,џџџџV\оз1ѕ        ѕ5_а,.-џџџџV\оз<ѕ        pass5_а-/.џџџџV\озBѕ        print('Could ')5_а.0/џџџџV\озB	ѕ        ѕ5_а/10џџџџV\озGѕ    except Exception as e:5_а021џџџџV\п	дѕ

    try:3        teensy_path = SerialUtils.get_teensy_port();        teensy_interface = TeensyInterface(teensy_path, "")*        teensy_interface.set_serial_port(),        teensy_interface.serial_port.close()+        teensy_interface.serial_port.open()?        ambiance = AmbianceController(teensy_interface, {}, ""))        ambiance.run_poweroff_animation()    except Exception:        pass5_а132џџџџV\п	еѕ
ѕ	
5_а243џџџџV\п	жѕ5_а34џџџџV\п	зѕ5_а&')(џџџџ!!V!\об>ѕ
5_а&('џџџџ\оЯ“ѕ    ѕѕj    os.environ[MINARY_SENTRY_PUBLIC_KEY=e295da6c82fe4b7aa41d56b65649a8af MINARY_SENTRY_PROJECT_ID=1307349]5_а
џџџџ00V\о#ђѕpif __name__ == "__main__": CoinmineRequests.send_powered_down_status_to_admin_api('$CONFIG_PATH', '$UUID_PATH')"5чЊ
예제 #11
0
v[�o��'D        self.logger.info('checking debug flag: {} {}'.format(debug))5�_�!#"B����
v[�o��'D        self.logger.info('checking debug flag: {} {}'.format(debug))5�_�"$#C����
v[�o��'R        self.logger.info('checking debug flag: {} {}'.format(debug, self.enabled))5�_�#%$����
v[�pS�)            �(5�_�$&%����
v[�pZ�*�*5�_�%'&����
v[�p]�+.            self.logger.info('debug disabled')5�_�&('����
v[�p_�+             self.logger.info('')5�_�')(����
v[�pd�5�_�(*)����
v[�r�*�*5�_�)+*����
v[�r�+&        if debug and not self.enabled:5�_�*,+,����
v[�r�+,        print(if debug and not self.enabled:5�_�+-,����
v[�r�+,        print(if debug and not self.enabled)5�_�,.-����
v[�r<�)        print(debug and not self.enabled)5�_�-/.����
v[�rA�
*,        debug = CoinmineRequests.get_config(5�_�.1/0����
v[�rE�*0            self.config_server_url).get('debug')5�_�/201*����
v[�ss�*5�_�132+����
v[�ss�*�+5�_�243*����++V[�sw�*,,5�_�354,����,-V[�sx�+def str2bool(v):/  return v.lower() in ("yes", "true", "t", "1")5�_�465-����,-V[�s{�,1    return v.lower() in ("yes", "true", "t", "1")5�_�576+����+-V[�s��*+    def str2bool(v):5        return v.lower() in ("yes", "true", "t", "1")5�_�687����V[�t�
        else:)            self.logger.info('no change')5�_�798����V[�t�)        �(5�_�8:9����V[�t.�)(        CoinmineRequests.str2bool(debug)5�_�9;:����V[�t3�0        debug = CoinmineRequests.str2bool(debug)5�_�:<;����V[�t5�
(1        debug = bool(CoinmineRequests.get_config(5�_�;A<1����V[�t8�(1            self.config_server_url).get('debug'))5�_�<B?A#����V[�u:�(0            self.config_server_url).get('debug')5�_�ACB"����V[�u;�
(,        debug = CoinmineRequests.get_config(#            self.config_server_url)5�_�BDC-����V[�u<�
'D        debug = CoinmineRequests.get_config( self.config_server_url)5�_�CED+����V[�u=�
'C        debug = CoinmineRequests.get_config(self.config_server_url)5�_�DFE2����V[�uG�'C        self.logger.info('checking debug flag: {} {}'.format(debug,5�_�EGF����V[�uL�'K        self.logger.info('checking debug flag: {} enabled {}'.format(debug,5�_�FHG1����V[�uN�(>            'checking debug flag: {} enabled {}'.format(debug,K                                                             self.enabled))5�_�GIH����V[�u^ �'        self.logger.info(5�_�HJI-����[���'.        CoinmineRequests.post_to_ngrok_tunnel(5�_�IKJ"����[���'"            self.ngrok_server_url,5�_�JLK����[��!�(            'api/tunnels'5�_�KML'/����[���&((M        CoinmineRequests.delete_to_ngrok_tunnel(self.ngrok_server_url, 'ssh')5�_�LNM'8����[��"�&((=        CoinmineRequests.delete(self.ngrok_server_url, 'ssh')5�_�MON
����\<5�	(9        self.logger = SystemHelpers.init_logger(__name__)5�_�NPO
����\<9�	(        self.logger = 5�_�OQP1����\<=�(1from utils import SystemHelpers, CoinmineRequests5�_�PRQ
����\<C#�	(        self.logger = 5�_�QSR
$����\<_�	($        self.logger = CoinmineLogger5�_�RTSD����\<g&�(F    def __init__(self, config_server_url, ngrok_server_url, ssh_port):5�_�SUT����\<�(�(5�_�TVU����\<��5�_�UWV1����\<�)�(Afrom utils import SystemHelpers, CoinmineRequests, CoinmineLogger5�_�VXW ����\<��(1from utils import SystemHelpers, CoinmineRequests5�_�WYX����\<��(#from utils import  CoinmineRequests5�_�XY����\<�*�(!from utils importCoinmineRequests5�_�<@=A?����V[�u-�5�_�?@,����V[�u.�
',        debug = CoinmineRequests.get_debug()5�_�<>?=+����V[�t<�
(Q        debug = CoinmineRequests.get_config( self.config_server_url).get('debug')5�_�=>-����V[�t=�
'P        debug = CoinmineRequests.get_config(self.config_server_url).get('debug')5�_�/10����
v[�s�*        �+!        print(debug, type(debug))5��
예제 #12
0
VimЪUnDoтьEExqЎ┌ь4!Ц"_
├К╗иц:JdЃhо├7ф■\С?[_л    \С9yшш5Ђ_л    \С9zш5Ђ_л    \С9Ђш        ш5Ђ_л
    \С9Ѕш)        ambiance.run_poweroff_animation()5Ђ_л
9    V\С?ш        ш5Ђ_л
    V\С?9ш        ambiance.state = 5Ђ_л
"    V\С?Iшш5Ђ_л
    V\С?Kш5from thunder_and_lightning.helpers import SerialUtils5Ђ_л
    V\С?Lш.from thunder_and_lightning. import SerialUtils5Ђ_л8    V\С?Oш8from thunder_and_lightning.animations import SerialUtils5Ђ_л    V\С?Yш6from thunder_and_lightning.animations import PowerDown5Ђ_л    V\С?Zшш5Ђ_л
9    V\С>aшK        ambiance = AmbianceController(teensy_interface, {'power_down'}, "")5Ђ_л	E    V\С>eшQ        ambiance = AmbianceController(teensy_interface, {'power_down': True}, "")5Ђ_л	J    V\С>gш+from utils.requests import CoinmineRequests@from thunder_and_lightning.controllers import AmbianceController<from thunder_and_lightning.interfaces import TeensyInterface5from thunder_and_lightning.helpers import SerialUtilsif __name__ == "__main__":-    config_path = "/home/satoshi/config.yaml"!    uuid_path = "/etc/machine-id"    try:3        teensy_path = SerialUtils.get_teensy_port();        teensy_interface = TeensyInterface(teensy_path, "")*        teensy_interface.set_serial_port(),        teensy_interface.serial_port.close()+        teensy_interface.serial_port.open()Q        ambiance = AmbianceController(teensy_interface, {"power_down": True}, "")"        ambiance.turn_lights_off()    except Exception:        passR    CoinmineRequests.send_powered_down_status_to_admin_api(config_path, uuid_path)5Ђ_л    V\С9їш5Ђ_л    \С9Єш5Ђуф
Vim�UnDo��8�o�
ϖ�(����6��_v�8���,�(+9        logger.warn("No teensy device detected! Exiting")^q8�_�����^q8��+9        logger.warn("No teensy device detected! Exiting")5�_�
=����++v]���+@    minary_ambiance_server_url = os.environ["MINARY_SERVER_URL"]5�_�
4����++v]���+D    minary_ambiance_server_url = os.environ["MINARY_API_SERVER_URL"]5�_�
����++v]���+?    minary_api_server_url = os.environ["MINARY_API_SERVER_URL"]5�_�>����++v]���+N        "waiting for connection: {}/{}".format(minary_api_server_url, "state")5�_�9����++v]���+I        lambda: CoinmineRequests.test_get(minary_api_server_url, "state")5�_�0����++v]��� +@    state = CoinmineRequests.get(minary_api_server_url, "state")5�_�	"0����++v]���!#+G        teensy_interface, state, minary_api_server_url, animation_queue5�_�
	"*����v]� �,)	import os
import sysDfrom thunder_and_lightning.utils import SerialUtils, TeensyInterfacePfrom thunder_and_lightning.controllers import AmbianceController, AnimationQueue<from utils import SystemHelpers, CoinmineLogger, sentry_init+from utils.requests import CoinmineRequests
sentry_init()if __name__ == "__main__":%    logger = CoinmineLogger(__name__)?    minary_api_server_url = os.environ["MINARY_API_SERVER_URL"]5    script_path = os.environ["MINARY_TL_SCRIPT_PATH"]2    logger.info("Starting Light and Sound Worker")/    teensy_path = SerialUtils.get_teensy_port()    if not teensy_path:9        logger.warn("No teensy device detected! Exiting")        sys.exit(1)@    teensy_interface = TeensyInterface(teensy_path, script_path)&    teensy_interface.set_serial_port()W    logger.info("waiting for connection: {}/{}".format(minary_api_server_url, "state"))&    SystemHelpers.wait_for_connection(I        lambda: CoinmineRequests.test_get(minary_api_server_url, "state")    )@    state = CoinmineRequests.get(minary_api_server_url, "state")&    animation_queue = AnimationQueue()"    ambiance = AmbianceController(G        teensy_interface, state, minary_api_server_url, animation_queue    )    try:        while True:)            ambiance.run_animation_step()    except Exception as e:L        logger.error("Could not run light and sound service e={}".format(e))        sys.exit(1)5�_�	
>����v]�"��)G    state = CoinmineRequests.get(minary_api_server_url, "miner_status")5�_�
G����v]�"��)P        lambda: CoinmineRequests.test_get(minary_api_server_url, "miner_status")5��