Fix issues with sysinfo rpc/API code, add SysInfo api_schema

This commit is contained in:
froggleston 2021-10-05 00:10:39 +01:00
parent 097da448e2
commit 0db5c07314
3 changed files with 10 additions and 5 deletions

View File

@ -347,3 +347,7 @@ class BacktestResponse(BaseModel):
trade_count: Optional[float] trade_count: Optional[float]
# TODO: Properly type backtestresult... # TODO: Properly type backtestresult...
backtest_result: Optional[Dict[str, Any]] backtest_result: Optional[Dict[str, Any]]
class SysInfo(BaseModel):
cpu_pct: float
ram_pct: float

View File

@ -18,7 +18,7 @@ from freqtrade.rpc.api_server.api_schemas import (AvailablePairs, Balances, Blac
OpenTradeSchema, PairHistory, PerformanceEntry, OpenTradeSchema, PairHistory, PerformanceEntry,
Ping, PlotConfig, Profit, ResultMsg, ShowConfig, Ping, PlotConfig, Profit, ResultMsg, ShowConfig,
Stats, StatusMsg, StrategyListResponse, Stats, StatusMsg, StrategyListResponse,
StrategyResponse, Version, WhitelistResponse) StrategyResponse, SysInfo, Version, WhitelistResponse)
from freqtrade.rpc.api_server.deps import get_config, get_rpc, get_rpc_optional from freqtrade.rpc.api_server.deps import get_config, get_rpc, get_rpc_optional
from freqtrade.rpc.rpc import RPCException from freqtrade.rpc.rpc import RPCException
@ -260,6 +260,6 @@ def list_available_pairs(timeframe: Optional[str] = None, stake_currency: Option
} }
return result return result
@router.get('/sysinfo', tags=['info']) @router.get('/sysinfo', response_model=SysInfo, tags=['info'])
def sysinfo(rpc: RPC = Depends(get_rpc)): def sysinfo():
return rpc._rpc_sysinfo() return RPC._rpc_sysinfo()

View File

@ -871,5 +871,6 @@ class RPC:
self._freqtrade.strategy.plot_config['subplots'] = {} self._freqtrade.strategy.plot_config['subplots'] = {}
return self._freqtrade.strategy.plot_config return self._freqtrade.strategy.plot_config
def _rpc_sysinfo(self) -> Dict[str, Any]: @staticmethod
def _rpc_sysinfo() -> Dict[str, Any]:
return {"cpu_pct": psutil.cpu_percent(interval=1, percpu=True), "ram_pct": psutil.virtual_memory().percent} return {"cpu_pct": psutil.cpu_percent(interval=1, percpu=True), "ram_pct": psutil.virtual_memory().percent}