Beispiel #1
0
VimŸUnDoו�8¨��+‘�@פ1�Z=��½g�1‏‎K¹¢ב¦Bl¾Z!                    {"error": e},O\�לB_�68����\�žpץ57WJ                logger.warn("could not form json response e={}".format(e))5_�68����\�žqץ57W8                logger.warn("could not form json respons5_�6D����\�žvץ57WE                logger.warn("could not form json response", {"error"}5_�
6H����\�žwץ57WH                logger.warn("could not form json response", {"error": e}5_�
:$����\�žµץ9;W:                    "{} {} status={} resp_json={}".format(5_�
;K����\�ž¸ץ:<WV                        self.operation, self.full_url, response.status_code, resp_json5_�
<����\�ž÷ץ;=W                    )5_�
<����\�ž¾ץWimport jsonimport requests from utils import CoinmineLogger!logger = CoinmineLogger(__name__)!OK_STATUS_CODES = [200, 201, 204]class RequestFactory:C    def __init__(self, full_url, operation, json=None, token=None):         self.full_url = full_url"        self.operation = operation        self.json = json        self.token = token        if token is None:            self.headers = None
        else:E            self.headers = {"Authorization": "Token %s" % self.token}    def make_request(self):        response = None        request = {!            "TEST_GET": lambda: (R                requests.get(self.full_url, headers=self.headers, timeout=(5, 10))            ),            "GET": lambda: (R                requests.get(self.full_url, headers=self.headers, timeout=(5, 10))            ),            "DELETE": lambda: (U                requests.delete(self.full_url, headers=self.headers, timeout=(5, 10))            ),            "PUT": lambda: (                requests.put(X                    self.full_url, json=self.json, headers=self.headers, timeout=(5, 10)                )            ),            "POST": lambda: (                requests.post(X                    self.full_url, json=self.json, headers=self.headers, timeout=(5, 10)                )            ),	        }        try:I            response = self._sanitize_response(request[self.operation]())            try:+                resp_json = response.json()5            except json.decoder.JSONDecodeError as e:                 resp_json = NoneI                logger.warn("could not form json response", {"error": e})7            if response.status_code in OK_STATUS_CODES:                logger.debug(-                    "{} {} status={}".format(K                        self.operation, self.full_url, response.status_code                     ), resp_json                )            else:                logger.warn(:                    "{} {} status={} resp_json={}".format(V                        self.operation, self.full_url, response.status_code, resp_json                    )                )        except Exception as e:,            if self.operation == "TEST_GET":J                logger.warn("{} {}".format(self.operation, self.full_url))            else:                logger.error(8                    "e={} {} {} request_json={}".format(C                        e, self.operation, self.full_url, self.json                    )                )            raise e        return response
    # helpers/    def _sanitize_response(self, raw_response):.        # clean up xmr-stak invalid charactersS        raw_response.__text = raw_response.text.replace("\n", "").replace("\r", "")        return raw_response5_�
C����\�ž�ץCEXץCDX5_�C����\�ž�ץBDY                    )5_�A$����\�ž�ץ@BY:                    "{} {} status={} resp_json={}".format(5_�BK����\�ž�ץACYV                        self.operation, self.full_url, response.status_code, resp_json5_�M����\�ž�ץLNYC                        e, self.operation, self.full_url, self.json5_�L����\�ž�ץKMY8                    "e={} {} {} request_json={}".format(5_�N����\�žדץMOY                    )5_�N����\�žזץMOY                     ), {"error"}5_�N!����\�žטץYimport jsonimport requests from utils import CoinmineLogger!logger = CoinmineLogger(__name__)!OK_STATUS_CODES = [200, 201, 204]class RequestFactory:C    def __init__(self, full_url, operation, json=None, token=None):         self.full_url = full_url"        self.operation = operation        self.json = json        self.token = token        if token is None:            self.headers = None
        else:E            self.headers = {"Authorization": "Token %s" % self.token}    def make_request(self):        response = None        request = {!            "TEST_GET": lambda: (R                requests.get(self.full_url, headers=self.headers, timeout=(5, 10))            ),            "GET": lambda: (R                requests.get(self.full_url, headers=self.headers, timeout=(5, 10))            ),            "DELETE": lambda: (U                requests.delete(self.full_url, headers=self.headers, timeout=(5, 10))            ),            "PUT": lambda: (                requests.put(X                    self.full_url, json=self.json, headers=self.headers, timeout=(5, 10)                )            ),            "POST": lambda: (                requests.post(X                    self.full_url, json=self.json, headers=self.headers, timeout=(5, 10)                )            ),	        }        try:I            response = self._sanitize_response(request[self.operation]())            try:+                resp_json = response.json()5            except json.decoder.JSONDecodeError as e:                 resp_json = NoneI                logger.warn("could not form json response", {"error": e})7            if response.status_code in OK_STATUS_CODES:                logger.debug(-                    "{} {} status={}".format(K                        self.operation, self.full_url, response.status_code                    ),                    resp_json,                )            else:                logger.warn(-                    "{} {} status={}".format(K                        self.operation, self.full_url, response.status_code                    ),                    resp_json,                )        except Exception as e:,            if self.operation == "TEST_GET":J                logger.warn("{} {}".format(self.operation, self.full_url))            else:                logger.error(3                    "{} {} request_json={}".format(@                        self.operation, self.full_url, self.json#                    ), {"error": e}                )            raise e        return response
    # helpers/    def _sanitize_response(self, raw_response):.        # clean up xmr-stak invalid charactersS        raw_response.__text = raw_response.text.replace("\n", "").replace("\r", "")        return raw_response5_�6E����\�ל:ץ57ZI                logger.warn("could not form json response", {"error": e})ץ67Z5_�6K����\�ל;ץ57ZM                logger.warn("could not form json response", {"error": str(e})5_�O����\�ל@ץNPZ!                    {"error": e},ץOPZ5_�O#����\�לAץNPZ%                    {"error": str(e},5_�A$����\�ž�ץ@BY&                    "{} {} status={}t(5_�
=����\�ž�ץ<>5_�
:$����\�ž×ץ9;W<                    "{} {} status={}"" resp_json={}".format(5_�	:%����\�ž¬ץ9;W;                    "{} {} status={}" resp_json={}".format(5_�	:%����\�ž®ץ9;W<                    "{} {} status={}", resp_json={}".format(5_�:����\�žŒץ9;W;                    "{} {}" status={} resp_json={}".format(5_�68����\�žkץ67Wץ57W[                logger.warn("could not form json response e={}".format(e)) e={}".format(e))5ח×
Beispiel #2
0
Vim�UnDo�f0�C<?�'��Gz��㤓:o<e2Tn~���pMC            logger.warn("could not get memory info e={}".format(e))L^q7_�����^a4~�
<<<<<<< HEAD5�_�����V^a4��

O        info["version"] = re.findall(r"Version: (.*)", output, re.MULTILINE)[0]O        info["voltage"] = re.findall(r"Voltage: (.*)", output, re.MULTILINE)[0]W        info["num_of_cores"] = re.findall(r"Core Count: (.*)", output, re.MULTILINE)[0],        info["num_of_threads"] = re.findall(7            r"Thread Count: (.*)", output, re.MULTILINE        )[0]W        info["max_frequency"] = re.findall(r"Max Speed: (.*)", output, re.MULTILINE)[0]/        info["current_frequency"] = re.findall(8            r"Current Speed: (.*)", output, re.MULTILINE        )[0]5�_�����V^a4��I�I�H5�_�����V^a4��S
O        info["version"] = re.findall(r"Version: (.*)", output, re.MULTILINE)[0]O        info["voltage"] = re.findall(r"Voltage: (.*)", output, re.MULTILINE)[0]W        info["num_of_cores"] = re.findall(r"Core Count: (.*)", output, re.MULTILINE)[0],        info["num_of_threads"] = re.findall(7            r"Thread Count: (.*)", output, re.MULTILINE        )[0]W        info["max_frequency"] = re.findall(r"Max Speed: (.*)", output, re.MULTILINE)[0]/        info["current_frequency"] = re.findall(8            r"Current Speed: (.*)", output, re.MULTILINE        )[0]5�_�����%V^a4��S            info["version"] = re.findall(r"Version: (.*)", output, re.MULTILINE)[0]S            info["voltage"] = re.findall(r"Voltage: (.*)", output, re.MULTILINE)[0].            info["num_of_cores"] = re.findall(9                r"Core Count: (.*)", output, re.MULTILINE            )[0]0            info["num_of_threads"] = re.findall(;                r"Thread Count: (.*)", output, re.MULTILINE            )[0]5�_� ����V^a4�� 0>>>>>>> a12a311df8e785e8097c59ca61a1fae694685f985�_�����V^a4��
=======5�_�	����V^a4��I	import re,from utils import CoinmineLogger, Converters!logger = CoinmineLogger(__name__)class Dmidecode:=    def __init__(self, dmidecode_path="/usr/sbin/dmidecode"):,        self.dmidecode_path = dmidecode_path    def get_cpu_info(self):        info = {}        arg = "processor"9        cmd = "{} -t {}".format(self.dmidecode_path, arg)        try:2            output = Converters.cmd_to_string(cmd)S            info["version"] = re.findall(r"Version: (.*)", output, re.MULTILINE)[0]S            info["voltage"] = re.findall(r"Voltage: (.*)", output, re.MULTILINE)[0][            info["num_of_cores"] = re.findall(r"Core Count: (.*)", output, re.MULTILINE)[0]0            info["num_of_threads"] = re.findall(;                r"Thread Count: (.*)", output, re.MULTILINE            )[0][            info["max_frequency"] = re.findall(r"Max Speed: (.*)", output, re.MULTILINE)[0]3            info["current_frequency"] = re.findall(<                r"Current Speed: (.*)", output, re.MULTILINE            )[0]        except Exception as e:@            logger.warn("could not get cpu info e={}".format(e))        return info#    def get_motherboard_info(self):        info = {}        arg = "system"9        cmd = "{} -t {}".format(self.dmidecode_path, arg)        try:2            output = Converters.cmd_to_string(cmd).            info["manufacturer"] = re.findall(;                r"Manufacturer: (.*)", output, re.MULTILINE            )[0].            info["product_name"] = re.findall(;                r"Product Name: (.*)", output, re.MULTILINE            )[0]        except Exception as e:H            logger.warn("could not get motherboard info e={}".format(e))        return info    def get_memory_info(self):        info = {}        arg = "memory"9        cmd = "{} -t {}".format(self.dmidecode_path, arg)        try:2            output = Converters.cmd_to_string(cmd)D            size = re.findall(r"\tSize: (.*)", output, re.MULTILINE)D            type = re.findall(r"\tType: (.*)", output, re.MULTILINE)F            speed = re.findall(r"\tSpeed: (.*)", output, re.MULTILINE)D            rank = re.findall(r"\tRank: (.*)", output, re.MULTILINE)S            voltage = re.findall(r"Configured Voltage: (.*)", output, re.MULTILINE)$            num_of_banks = len(size)/            for bank in range(0, num_of_banks):0                info["bank_{}".format(bank)] = {'                    "size": size[bank],'                    "type": type[bank],)                    "speed": speed[bank],'                    "rank": rank[bank],-                    "voltage": voltage[bank],                }        except Exception as e:C            logger.warn("could not get memory info e={}".format(e))        return info5�_�
	"����^q7
�!#M@            logger.warn("could not get cpu info e={}".format(e))5�_�	
2����^q7�13MH            logger.warn("could not get motherboard info e={}".format(e))5�_�
L����^q7�KMMC            logger.warn("could not get memory info e={}".format(e))5��
Beispiel #3
0
VimŸUnDoεhγ0βθέϊΕW…w-•‹WŒPy0‡?ΈG{L7ΎQ<            "zcash": nanopool_hashrate("zec", self.address),:LLLL]9ξ�_Π����]/[ύυ        υ5_Π����]/\υ
        {}5_Π����]/\υ        hashrate = {}5_Π����]/\υ        hashrate = {"ethereum"}5_Π����]/\Œυυ5_Π ����]/\«υ/from health_monitor.pool import HashrateGateway5_Π ����]/\«υ from health_monitor.pool import 5_Π	(����]/\±υ(from health_monitor.pool import hashrate5_Π
	 ����]/\Γυ!        hashrate = {"ethereum": }5_Π	
7����]/\Μυ9        hashrate = {"ethereum": nanopool_hashrate('eth')}5_Π

D����]/\�υ,from health_monitor import BaseHealthChecker from utils import CoinmineLogger=from health_monitor.pool import hashrate as nanopool_hashrate!logger = CoinmineLogger(__name__)+class PoolHealthChecker(BaseHealthChecker):&    def __init__(self, coin, address):        self.coin = coin        self.address = address    def _is_healthy(self):'        hashrate = self._get_hashrate()        if hashrate:            return True
        else:            return False    def _get_hashrate(self):G        hashrate = {"ethereum": nanopool_hashrate('eth', self.address)}        pass5_Π
F����]/\ΪυG        hashrate = {"ethereum": nanopool_hashrate("eth", self.address)}5_Π
����]/\άυυυ5_Π����22V2]/\έυ3"ethereum": nanopool_hashrate("eth", self.address)}5_Π����22V2]/\έυ7    "ethereum": nanopool_hashrate("eth", self.address)}5_Π����22V2]/\έυ;        "ethereum": nanopool_hashrate("eth", self.address)}5_Π����22V2]/\ήυ?            "ethereum": nanopool_hashrate("eth", self.address)}5_Π����22V2]/\ήυC                "ethereum": nanopool_hashrate("eth", self.address)}5_Π����22V2]/\ΰυG                    "ethereum": nanopool_hashrate("eth", self.address)}5_Π4����22V2]/\δυE                    "monero": nanopool_hashrate("eth", self.address)}5_Π3����22V2]/\ηυυ5_Π����22V2]/\ιυE                    "monero": nanopool_hashrate("xmr", self.address)}5_Π����22V2]/\μυυ5_Π����22V2]/\νυE                    "monero": nanopool_hashrate("xmr", self.address)}5_Π3����22V2]/\ρυD                    "zcash": nanopool_hashrate("xmr", self.address)}5_Π2����22V2]/\χυC                    "grin": nanopool_hashrate("xmr", self.address)}5_ΠD����22V2]/\ύυD                    "zcash": nanopool_hashrate("zec", self.address)}5_ΠE����22V2]/]υE                    "monero": nanopool_hashrate("xmr", self.address)}5_ΠD����22V2]/]υD                    "grin": nanopool_hashrate("grin", self.address)}5_Π C����22V2]/]υC                    "grin": nanopool_hashrate("grin", self.address)5_Π! C����22V2]/]υ,from health_monitor import BaseHealthChecker from utils import CoinmineLogger=from health_monitor.pool import hashrate as nanopool_hashrate!logger = CoinmineLogger(__name__)+class PoolHealthChecker(BaseHealthChecker):&    def __init__(self, coin, address):        self.coin = coin        self.address = address    def _is_healthy(self):'        hashrate = self._get_hashrate()        if hashrate:            return True
        else:            return False    def _get_hashrate(self):G        hashrate = {"ethereum": nanopool_hashrate("eth", self.address),E                    "monero": nanopool_hashrate("xmr", self.address),D                    "zcash": nanopool_hashrate("zec", self.address),D                    "grin": nanopool_hashrate("grin", self.address),                    }        pass5_Π "!����22V2]/]υ        υ5_Π!#"����22V2]/]
υ        hashrate[]5_Π"$#����22V2]/]υ        pass5_Π#%$����22V2]/]υ        return hashrate[]5_Π$&% ����22V2]/]~υ=from health_monitor.pool import hashrate as nanopool_hashrate5_Π%'& ����22V2]/]~υ5from health_monitor.pool import  as nanopool_hashrate5_Π&(' ����22V2]/]	υ,from health_monitor import BaseHealthChecker from utils import CoinmineLogger2from health_monitor.pool import  nanopool_hashrate!logger = CoinmineLogger(__name__)+class PoolHealthChecker(BaseHealthChecker):&    def __init__(self, coin, address):        self.coin = coin        self.address = address    def _is_healthy(self):'        hashrate = self._get_hashrate()        if hashrate:            return True
        else:            return False    def _get_hashrate(self):        hashrate = {?            "ethereum": nanopool_hashrate("eth", self.address),=            "monero": nanopool_hashrate("xmr", self.address),<            "zcash": nanopool_hashrate("zec", self.address),<            "grin": nanopool_hashrate("grin", self.address),	        }"        return hashrate[self.coin]5_Π')(����22V2]/]ηυ            υ5_Π(*)/����22V2]/]ϋυ0            logger.info("Pool side hashrate={}")5_Π)+*����22V2]/^υυ5_Π*,+����22V2]/^υA            logger.info("Pool side hashrate={}".format(hashrate))5_Π+-,����22V2]/^
υA            logger.warn("Pool side hashrate={}".format(hashrate))5_Π,.-����22V2]/^bυA            logger.warn("Pool side hashrate={}".format(hashrate))5_Π-/.!����22V2]/_ϋ
υ        υ5_Π.0/"����22V2]/`Zυ"        return hashrate[self.coin]5_Π/10����22V2]/`zυ        print(hashrate)5_Π021#����22V2]/aΩυ.        return hashrate[self.coin]["hashrate"]5_Π132(����22V2]/aΫυ3        return hashrate[self.coin].get()"hashrate"]5_Π2432����22V2]/aάυ2        return hashrate[self.coin].get("hashrate"]5_Π354����22V2]/erυυ5_Π465����22V2]/evυ1from health_monitor.pool import nanopool_hashrate5_Π5761����22V2]/evυ1from health_monitor.pool import nanopool_hashrate5_Π687����22V2]/e|υ<            "grin": nanopool_hashrate("grin", self.address),5_Π798����]/l
υ        υ5_Π8:9
$����]/lυ	&    def __init__(self, coin, address):5_Π9;:����]/{υJ            logger.warn("Warning! Pool side hashrate={}".format(hashrate))5_Π:<;!����]/{υK            logger.error("Warning! Pool side hashrate={}".format(hashrate))5_Π;><!����]/{υJ            logger.error("Warnin! Pool side hashrate={}".format(hashrate))5_Π<?=>����]/{2υ         υ5_Π>@?����]/{:υ            return False5_Π?A@����]/{;υ            return True5_Π@BA.����]/•Eυ<            "grin": grinmint_hashrate("grin", self.address),5_ΠACB2����]/•Iυ4            "grin": grinmint_hashrate(self.address),5_ΠBDC����]/•Nυ        υ5_ΠCED
����]/•Pυ        self.uuid5_ΠDFE

����]/•Tυ        self.uuid = uuid5_ΠEGF
����]/•Wυ        self.short_uuid = uuid5_ΠFHG
%����]/•Zυ	6    def __init__(self, coin, address, remedy_command):5_ΠGIH
0����]/•]υ	A    def __init__(self, coin, address, short_uuid remedy_command):5_ΠHJI9����]/•ύυ?            "grin": grinmint_hashrate(self.address, self.uuid),5_ΠIKJ=����]9ξ€υ?            "ethereum": nanopool_hashrate("eth", self.address),5_ΠJLK;����]9ξ¬υ=            "monero": nanopool_hashrate("xmr", self.address),5_ΠKL:����]9ξ­υ<            "zcash": nanopool_hashrate("zec", self.address),5_Π<>=����]/{*υ5_Π
����]/\Ωυ        hashrate = {5ηͺ
Vim�UnDo�b�ΩAx'�P@�r.���.���e"��M5<��hJ                logger.warn("{} {}".format(self.operation, self.full_url))X....^q8o_�P����]�B�WR                requests.get(self.full_url, headers=self.headers, timeout=(5, 10))5�_�P����]�G�WR                requests.get(self.full_url, headers=self.headers, timeout=(5, 10))5�_�!S����]�J� "WU                requests.delete(self.full_url, headers=self.headers, timeout=(5, 10))5�_�%W����]�M�$&WX                    self.full_url, json=self.json, headers=self.headers, timeout=(5, 10)5�_�*W����]�O�)+WX                    self.full_url, json=self.json, headers=self.headers, timeout=(5, 10)5�_�	
����]���
X�
W5�_�
		5����]���
X5REQUEST_TIMEOUT = os.environ[REQUEST_TIMEOUT_CONNECT]5�_�	
	6����]���
X6REQUEST_TIMEOUT = os.environ[REQUEST_TIMEOUT_CONNECT])5�_�
	Z����]���
XZREQUEST_TIMEOUT = os.environ[REQUEST_TIMEOUT_CONNECT]), os,environ["REQUEST_TIMEOUT_READ"]5�_�
	8����]���
X\REQUEST_TIMEOUT = os.environ[REQUEST_TIMEOUT_CONNECT]), os,environ["REQUEST_TIMEOUT_READ"]))5�_�
	����]���
X`REQUEST_TIMEOUT = os.environ[REQUEST_TIMEOUT_CONNECT]), int(os,environ["REQUEST_TIMEOUT_READ"]))5�_�
	����]���Ximport jsonimport requests from utils import CoinmineLogger!logger = CoinmineLogger(__name__)!OK_STATUS_CODES = [200, 201, 204]eREQUEST_TIMEOUT = (int(os.environ[REQUEST_TIMEOUT_CONNECT]), int(os,environ["REQUEST_TIMEOUT_READ"]))class RequestFactory:C    def __init__(self, full_url, operation, json=None, token=None):         self.full_url = full_url"        self.operation = operation        self.json = json        self.token = token        if token is None:            self.headers = None
        else:E            self.headers = {"Authorization": "Token %s" % self.token}    def make_request(self):        response = None        request = {!            "TEST_GET": lambda: (R                requests.get(self.full_url, headers=self.headers, timeout=(5, 25))            ),            "GET": lambda: (R                requests.get(self.full_url, headers=self.headers, timeout=(5, 25))            ),            "DELETE": lambda: (U                requests.delete(self.full_url, headers=self.headers, timeout=(5, 25))            ),            "PUT": lambda: (                requests.put(X                    self.full_url, json=self.json, headers=self.headers, timeout=(5, 25)                )            ),            "POST": lambda: (                requests.post(X                    self.full_url, json=self.json, headers=self.headers, timeout=(5, 25)                )            ),	        }        try:I            response = self._sanitize_response(request[self.operation]())            try:+                resp_json = response.json()5            except json.decoder.JSONDecodeError as e:                 resp_json = NoneJ                logger.warn("could not form json response e={}".format(e))7            if response.status_code in OK_STATUS_CODES:                logger.debug(:                    "{} {} status={} resp_json={}".format(V                        self.operation, self.full_url, response.status_code, resp_json                    )                )            else:                logger.warn(:                    "{} {} status={} resp_json={}".format(V                        self.operation, self.full_url, response.status_code, resp_json                    )                )        except Exception as e:,            if self.operation == "TEST_GET":J                logger.warn("{} {}".format(self.operation, self.full_url))            else:                logger.error(8                    "e={} {} {} request_json={}".format(C                        e, self.operation, self.full_url, self.json                    )                )            raise e        return response
    # helpers/    def _sanitize_response(self, raw_response):.        # clean up xmr-stak invalid charactersS        raw_response.__text = raw_response.text.replace("\n", "").replace("\r", "")        return raw_response5�_�����]���
[-    int(os, environ["REQUEST_TIMEOUT_READ"]),5�_�
����]���\�[5�_�����]���
\-    int(os.environ[REQUEST_TIMEOUT_CONNECT]),5�_�+����]���
\.    int(os.environ["REQUEST_TIMEOUT_CONNECT]),5�_� Q����]� 
�!\R                requests.get(self.full_url, headers=self.headers, timeout=(5, 25))5�_�#Q����]� �"$\R                requests.get(self.full_url, headers=self.headers, timeout=(5, 25))5�_�&T����]� �%'\U                requests.delete(self.full_url, headers=self.headers, timeout=(5, 25))5�_�*X����]� �)+\X                    self.full_url, json=self.json, headers=self.headers, timeout=(5, 25)5�_�/X����]� �.0\X                    self.full_url, json=self.json, headers=self.headers, timeout=(5, 25)5�_�\����]� �\	import osimport jsonimport requests from utils import CoinmineLogger!logger = CoinmineLogger(__name__)!OK_STATUS_CODES = [200, 201, 204]REQUEST_TIMEOUT = (/    int(os.environ["REQUEST_TIMEOUT_CONNECT"]),,    int(os.environ["REQUEST_TIMEOUT_READ"]),)class RequestFactory:C    def __init__(self, full_url, operation, json=None, token=None):         self.full_url = full_url"        self.operation = operation        self.json = json        self.token = token        if token is None:            self.headers = None
        else:E            self.headers = {"Authorization": "Token %s" % self.token}    def make_request(self):        response = None        request = {!            "TEST_GET": lambda: (Z                requests.get(self.full_url, headers=self.headers, timeout=REQUEST_TIMEOUT)            ),            "GET": lambda: (Z                requests.get(self.full_url, headers=self.headers, timeout=REQUEST_TIMEOUT)            ),            "DELETE": lambda: (]                requests.delete(self.full_url, headers=self.headers, timeout=REQUEST_TIMEOUT)            ),            "PUT": lambda: (                requests.put(`                    self.full_url, json=self.json, headers=self.headers, timeout=REQUEST_TIMEOUT                )            ),            "POST": lambda: (                requests.post(`                    self.full_url, json=self.json, headers=self.headers, timeout=REQUEST_TIMEOUT                )            ),	        }        try:I            response = self._sanitize_response(request[self.operation]())            try:+                resp_json = response.json()5            except json.decoder.JSONDecodeError as e:                 resp_json = NoneJ                logger.warn("could not form json response e={}".format(e))7            if response.status_code in OK_STATUS_CODES:                logger.debug(:                    "{} {} status={} resp_json={}".format(V                        self.operation, self.full_url, response.status_code, resp_json                    )                )            else:                logger.warn(:                    "{} {} status={} resp_json={}".format(V                        self.operation, self.full_url, response.status_code, resp_json                    )                )        except Exception as e:,            if self.operation == "TEST_GET":J                logger.warn("{} {}".format(self.operation, self.full_url))            else:                logger.error(8                    "e={} {} {} request_json={}".format(C                        e, self.operation, self.full_url, self.json                    )                )            raise e        return response
    # helpers/    def _sanitize_response(self, raw_response):.        # clean up xmr-stak invalid charactersS        raw_response.__text = raw_response.text.replace("\n", "").replace("\r", "")        return raw_response5�_�����V]����
h/    int(os.environ["REQUEST_TIMEOUT_CONNECT"]),5�_�����V]����
h,    int(os.environ["REQUEST_TIMEOUT_READ"]),5�_�,����V]����
h.    int(os.getenv["REQUEST_TIMEOUT_CONNECT"]),5�_�)����V]����
h+    int(os.getenv["REQUEST_TIMEOUT_READ"]),5�_�.����V]����
h/    int(os.getenv["REQUEST_TIMEOUT_READ"], 30),5�_� /����V]����
h1    int(os.getenv["REQUEST_TIMEOUT_CONNECT"], 5),5�_�! 0����V]����
h1    int(os.getenv["REQUEST_TIMEOUT_CONNECT"], 5),5�_� "!)����V]����
Beispiel #5
0
Vim�UnDo�–G�B�v$���{P�&ub&��0#p�D            logger.warn("could not get wifi device info from lspci")QQQQ^q7_�����^b���5�_�����^b����5�_�����^b���5�_�����^b���5�_�����^b���"�5�_�"����")V^b���!"    def get_cpu_info(self):.        cpus = Converters.json_string_to_dict(;            Converters.cmd_to_string(self.detailed_cpu_cmd)        )["cpus"]        for cpu in cpus:.            cpu["max_mhz"] = cpu.pop("maxmhz").            cpu["min_mhz"] = cpu.pop("minmhz")        return cpus5�_�����""V^b���	!        base_cmd = "lscpu"5�_�	����""V^b���!class Lscpu:5�_�
	%����""V^b���"�!5�_�	

����##V^b���"
import re]5�_�

����##V^b���"5�_�
����$$V^b��
;        cpu_columns = "--extended=CPU,SOCKET,MAXMHZ,MINMHZ"5�_�

����##V^b��
"L        self.detailed_cpu_cmd = "{} --json {}".format(base_cmd, cpu_columns)5�_�
����##V^b��
"<        self. = "{} --json {}".format(base_cmd, cpu_columns)5�_�����##V^b��
"?        self.cmd = "{} --json {}".format(base_cmd, cpu_columns)5�_�����##V^b��
"        self.cmd = 5�_�����##V^b��
        self.cmd = bas5�_�

����""V^b��	!        base_cmd = "lsusb"5�_�����""V^b�'�"        �!5�_�
����##V^b�1�
"        Converters.cmd_to_string()5�_�����""V^b�2�"            �!5�_�����##V^b�4�"�"5�_�����V^b�5�#"        Converters.cmd_to_string()5�_�����V^b�6�            5�_�%����V^b�>�"&            Converters.cmd_to_string()5�_�����V^b�B�0            output = self._get_detailed_output()5�_�����V^b�C�!.            Converters.cmd_to_string(self.cmd)5�_�����V^b�;�!5�_�����V^b�<�"�"5�_� ����V^b�=�"
r"Bus (.*)\n"5�_�! ����V^b�=�"    r"Bus (.*)\n"5�_� "!����V^b�=�"        r"Bus (.*)\n"5�_�!#"����V^b�=�"            r"Bus (.*)\n"5�_�"$#����V^b�@�/                r"Class:.*Network controller\n"!                "Vendor:\t(.*)\n"!                "Device:\t(.*)\n""                "SVendor:\t(.*)\n"!                "SDevice:\t(.*)",5�_�#%$����V^b�@�                re.MULTILINE,5�_�$&%����V^b�C�                r"Bus (.*)\n"5�_�%'&����V^b�D	�	import re,from utils import CoinmineLogger, Converters!logger = CoinmineLogger(__name__)class Lsusb:    def __init__(self):        self.cmd = "lsusb"#    def get_wifi_device_info(self):        info = {}        try:7            output = Converters.cmd_to_string(self.cmd)!            matches = re.findall(                r"Bus (.*)\n",                output,
            )            info = {(                "vendor": matches[0][0],(                "device": matches[0][1],,                "sub_vendor": matches[0][2],,                "sub_device": matches[0][3],
            }        except Exception:D            logger.warn("could not get wifi device info from lspci")        return info5�_�&('����V^b�G�            �5�_�')( ����V^b�N�                �5�_�(*)
����V^b�R�
        �
5�_�)+*"����V^b�Y�
#        self.keywords = ["Network"]5�_�*,+#����V^b�r�
%        self.keywords = ["Network", ]5�_�+-,.����V^b�v�
0        self.keywords = ["Network", "Wireless" ]5�_�,.-����V^b�{
�                if 5�_�-/.����V^b�~�                if5�_�.0/
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ח×
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��