Merge pull request #151 from Ytemiloluwa/master
This commit is contained in:
@@ -29,6 +29,7 @@ from .device import DeviceInfo
|
|||||||
from .error_codes import BraiinsOSError, InnosiliconError, WhatsminerError, X19Error
|
from .error_codes import BraiinsOSError, InnosiliconError, WhatsminerError, X19Error
|
||||||
from .fans import Fan
|
from .fans import Fan
|
||||||
from .hashrate import AlgoHashRate, HashUnit
|
from .hashrate import AlgoHashRate, HashUnit
|
||||||
|
from pyasic.data.pools import PoolMetrics
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -71,6 +72,7 @@ class MinerData:
|
|||||||
fault_light: Whether the fault light is on as a boolean.
|
fault_light: Whether the fault light is on as a boolean.
|
||||||
efficiency: Efficiency of the miner in J/TH (Watts per TH/s). Calculated automatically.
|
efficiency: Efficiency of the miner in J/TH (Watts per TH/s). Calculated automatically.
|
||||||
is_mining: Whether the miner is mining.
|
is_mining: Whether the miner is mining.
|
||||||
|
pools: A list of PoolMetrics instances, each representing metrics for a pool.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# general
|
# general
|
||||||
@@ -143,6 +145,9 @@ class MinerData:
|
|||||||
uptime: int = None
|
uptime: int = None
|
||||||
efficiency: int = field(init=False)
|
efficiency: int = field(init=False)
|
||||||
|
|
||||||
|
# pools
|
||||||
|
pools: list[PoolMetrics] = field(default_factory=list)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fields(cls):
|
def fields(cls):
|
||||||
return [f.name for f in fields(cls) if not f.name.startswith("_")]
|
return [f.name for f in fields(cls) if not f.name.startswith("_")]
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ from typing import List, Optional, Union
|
|||||||
from pyasic.config import MinerConfig, MiningModeConfig
|
from pyasic.config import MinerConfig, MiningModeConfig
|
||||||
from pyasic.data import AlgoHashRate, Fan, HashBoard, HashUnit
|
from pyasic.data import AlgoHashRate, Fan, HashBoard, HashUnit
|
||||||
from pyasic.data.error_codes import MinerErrorData, X19Error
|
from pyasic.data.error_codes import MinerErrorData, X19Error
|
||||||
from pyasic.errors import APIError
|
|
||||||
from pyasic.miners.backends.bmminer import BMMiner
|
from pyasic.miners.backends.bmminer import BMMiner
|
||||||
from pyasic.miners.backends.cgminer import CGMiner
|
from pyasic.miners.backends.cgminer import CGMiner
|
||||||
from pyasic.miners.data import (
|
from pyasic.miners.data import (
|
||||||
@@ -32,6 +31,8 @@ from pyasic.miners.data import (
|
|||||||
from pyasic.rpc.antminer import AntminerRPCAPI
|
from pyasic.rpc.antminer import AntminerRPCAPI
|
||||||
from pyasic.ssh.antminer import AntminerModernSSH
|
from pyasic.ssh.antminer import AntminerModernSSH
|
||||||
from pyasic.web.antminer import AntminerModernWebAPI, AntminerOldWebAPI
|
from pyasic.web.antminer import AntminerModernWebAPI, AntminerOldWebAPI
|
||||||
|
from pyasic.data.pools import PoolMetrics
|
||||||
|
from pyasic.errors import APIError
|
||||||
|
|
||||||
ANTMINER_MODERN_DATA_LOC = DataLocations(
|
ANTMINER_MODERN_DATA_LOC = DataLocations(
|
||||||
**{
|
**{
|
||||||
@@ -79,6 +80,10 @@ ANTMINER_MODERN_DATA_LOC = DataLocations(
|
|||||||
"_get_uptime",
|
"_get_uptime",
|
||||||
[RPCAPICommand("rpc_stats", "stats")],
|
[RPCAPICommand("rpc_stats", "stats")],
|
||||||
),
|
),
|
||||||
|
str(DataOptions.POOLS): DataFunction(
|
||||||
|
"_get_pools",
|
||||||
|
[RPCAPICommand("rpc_pools", "pools")],
|
||||||
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -351,6 +356,35 @@ class AntminerModern(BMMiner):
|
|||||||
except LookupError:
|
except LookupError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
async def _get_pools(self, rpc_pools: dict = None) -> List[PoolMetrics]:
|
||||||
|
if rpc_pools is None:
|
||||||
|
try:
|
||||||
|
rpc_pools = await self.rpc.pools()
|
||||||
|
except APIError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
pools_data = []
|
||||||
|
if rpc_pools is not None:
|
||||||
|
try:
|
||||||
|
pools = rpc_pools.get("POOLS", [])
|
||||||
|
for pool_info in pools:
|
||||||
|
pool_data = PoolMetrics(
|
||||||
|
accepted=pool_info.get("Accepted"),
|
||||||
|
rejected=pool_info.get("Rejected"),
|
||||||
|
get_failures=pool_info.get("Get Failures"),
|
||||||
|
remote_failures=pool_info.get("Remote Failures"),
|
||||||
|
active=pool_info.get("Stratum Active"),
|
||||||
|
alive=pool_info.get("Status") == "Alive",
|
||||||
|
url=pool_info.get("URL"),
|
||||||
|
user=pool_info.get("User"),
|
||||||
|
index=pool_info.get("POOL")
|
||||||
|
|
||||||
|
)
|
||||||
|
pools_data.append(pool_data)
|
||||||
|
except LookupError:
|
||||||
|
pass
|
||||||
|
return pools_data
|
||||||
|
|
||||||
|
|
||||||
ANTMINER_OLD_DATA_LOC = DataLocations(
|
ANTMINER_OLD_DATA_LOC = DataLocations(
|
||||||
**{
|
**{
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ from pyasic.device.makes import MinerMake
|
|||||||
from pyasic.errors import APIError
|
from pyasic.errors import APIError
|
||||||
from pyasic.logger import logger
|
from pyasic.logger import logger
|
||||||
from pyasic.miners.data import DataLocations, DataOptions, RPCAPICommand, WebAPICommand
|
from pyasic.miners.data import DataLocations, DataOptions, RPCAPICommand, WebAPICommand
|
||||||
|
from pyasic.data.pools import PoolMetrics
|
||||||
|
|
||||||
|
|
||||||
class MinerProtocol(Protocol):
|
class MinerProtocol(Protocol):
|
||||||
@@ -341,6 +342,14 @@ class MinerProtocol(Protocol):
|
|||||||
"""
|
"""
|
||||||
return await self._get_uptime()
|
return await self._get_uptime()
|
||||||
|
|
||||||
|
async def get_pools(self) -> List[PoolMetrics]:
|
||||||
|
""" Get the pools information from Miner.
|
||||||
|
|
||||||
|
Return:
|
||||||
|
The pool information of the miner.
|
||||||
|
"""
|
||||||
|
return await self._get_pools()
|
||||||
|
|
||||||
async def _get_mac(self) -> Optional[str]:
|
async def _get_mac(self) -> Optional[str]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -392,6 +401,9 @@ class MinerProtocol(Protocol):
|
|||||||
async def _get_uptime(self) -> Optional[int]:
|
async def _get_uptime(self) -> Optional[int]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
async def _get_pools(self) -> List[PoolMetrics]:
|
||||||
|
pass
|
||||||
|
|
||||||
async def _get_data(
|
async def _get_data(
|
||||||
self,
|
self,
|
||||||
allow_warning: bool,
|
allow_warning: bool,
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class DataOptions(Enum):
|
|||||||
UPTIME = "uptime"
|
UPTIME = "uptime"
|
||||||
CONFIG = "config"
|
CONFIG = "config"
|
||||||
VOLTAGE = "voltage"
|
VOLTAGE = "voltage"
|
||||||
|
POOLS = "pools"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.value
|
return self.value
|
||||||
|
|||||||
Reference in New Issue
Block a user