Merge pull request #5623 from froggleston/rest_sysinfo
Add CPU,RAM sysinfo support to the REST API to help with bot system m…
This commit is contained in:
commit
cae8ff5949
@ -347,3 +347,8 @@ 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: List[float]
|
||||||
|
ram_pct: float
|
||||||
|
@ -18,7 +18,8 @@ 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
|
||||||
|
|
||||||
@ -259,3 +260,8 @@ def list_available_pairs(timeframe: Optional[str] = None, stake_currency: Option
|
|||||||
'pair_interval': pair_interval,
|
'pair_interval': pair_interval,
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@router.get('/sysinfo', response_model=SysInfo, tags=['info'])
|
||||||
|
def sysinfo():
|
||||||
|
return RPC._rpc_sysinfo()
|
||||||
|
@ -8,6 +8,7 @@ from math import isnan
|
|||||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
|
import psutil
|
||||||
from numpy import NAN, inf, int64, mean
|
from numpy import NAN, inf, int64, mean
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
|
|
||||||
@ -870,3 +871,10 @@ class RPC:
|
|||||||
'subplots' not in self._freqtrade.strategy.plot_config):
|
'subplots' not in self._freqtrade.strategy.plot_config):
|
||||||
self._freqtrade.strategy.plot_config['subplots'] = {}
|
self._freqtrade.strategy.plot_config['subplots'] = {}
|
||||||
return self._freqtrade.strategy.plot_config
|
return self._freqtrade.strategy.plot_config
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _rpc_sysinfo() -> Dict[str, Any]:
|
||||||
|
return {
|
||||||
|
"cpu_pct": psutil.cpu_percent(interval=1, percpu=True),
|
||||||
|
"ram_pct": psutil.virtual_memory().percent
|
||||||
|
}
|
||||||
|
@ -36,6 +36,7 @@ fastapi==0.68.1
|
|||||||
uvicorn==0.15.0
|
uvicorn==0.15.0
|
||||||
pyjwt==2.1.0
|
pyjwt==2.1.0
|
||||||
aiofiles==0.7.0
|
aiofiles==0.7.0
|
||||||
|
psutil==5.8.0
|
||||||
|
|
||||||
# Support for colorized terminal output
|
# Support for colorized terminal output
|
||||||
colorama==0.4.4
|
colorama==0.4.4
|
||||||
|
@ -334,6 +334,13 @@ class FtRestClient():
|
|||||||
"timerange": timerange if timerange else '',
|
"timerange": timerange if timerange else '',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def sysinfo(self):
|
||||||
|
"""Provides system information (CPU, RAM usage)
|
||||||
|
|
||||||
|
:return: json object
|
||||||
|
"""
|
||||||
|
return self._get("sysinfo")
|
||||||
|
|
||||||
|
|
||||||
def add_arguments():
|
def add_arguments():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
@ -1271,6 +1271,16 @@ def test_list_available_pairs(botclient):
|
|||||||
assert len(rc.json()['pair_interval']) == 1
|
assert len(rc.json()['pair_interval']) == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_sysinfo(botclient):
|
||||||
|
ftbot, client = botclient
|
||||||
|
|
||||||
|
rc = client_get(client, f"{BASE_URI}/sysinfo")
|
||||||
|
assert_response(rc)
|
||||||
|
result = rc.json()
|
||||||
|
assert 'cpu_pct' in result
|
||||||
|
assert 'ram_pct' in result
|
||||||
|
|
||||||
|
|
||||||
def test_api_backtesting(botclient, mocker, fee, caplog):
|
def test_api_backtesting(botclient, mocker, fee, caplog):
|
||||||
ftbot, client = botclient
|
ftbot, client = botclient
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
|
||||||
|
Loading…
Reference in New Issue
Block a user