Add Sysinfo endpoint

This commit is contained in:
Matthias 2021-10-09 15:17:53 +02:00
parent a24a93411e
commit 67cb1af105
3 changed files with 26 additions and 0 deletions

View File

@ -30,6 +30,7 @@ import {
PairHistory, PairHistory,
LogLine, LogLine,
BacktestSteps, BacktestSteps,
SysInfoResponse,
} from '@/types'; } from '@/types';
import { import {
@ -70,6 +71,7 @@ export enum BotStoreGetters {
stakeCurrencyDecimals = 'stakeCurrencyDecimals', stakeCurrencyDecimals = 'stakeCurrencyDecimals',
strategyPlotConfig = 'strategyPlotConfig', strategyPlotConfig = 'strategyPlotConfig',
version = 'version', version = 'version',
sysinfo = 'sysinfo',
profit = 'profit', profit = 'profit',
botState = 'botState', botState = 'botState',
whitelist = 'whitelist', whitelist = 'whitelist',
@ -136,6 +138,7 @@ export enum BotStoreActions {
pollBacktest = 'pollBacktest', pollBacktest = 'pollBacktest',
removeBacktest = 'removeBacktest', removeBacktest = 'removeBacktest',
stopBacktest = 'stopBacktest', stopBacktest = 'stopBacktest',
sysInfo = 'sysInfo',
logout = 'logout', logout = 'logout',
} }
@ -244,6 +247,9 @@ export function createBotSubStore(botId: string, botName: string) {
[BotStoreGetters.version](state: FtbotStateType): string { [BotStoreGetters.version](state: FtbotStateType): string {
return state.version; return state.version;
}, },
[BotStoreGetters.version](state: FtbotStateType): SysInfoResponse | {} {
return state.sysinfo;
},
[BotStoreGetters.profit](state: FtbotStateType): ProfitInterface | {} { [BotStoreGetters.profit](state: FtbotStateType): ProfitInterface | {} {
return state.profit; return state.profit;
}, },
@ -423,6 +429,9 @@ export function createBotSubStore(botId: string, botName: string) {
setBacktestResultKey(state: FtbotStateType, key: string) { setBacktestResultKey(state: FtbotStateType, key: string) {
state.selectedBacktestResultKey = key; state.selectedBacktestResultKey = key;
}, },
updateSysInfo(state, sysinfo: SysInfoResponse) {
state.sysinfo = sysinfo;
},
}, },
actions: { actions: {
[BotStoreActions.botAdded]({ commit }) { [BotStoreActions.botAdded]({ commit }) {
@ -942,6 +951,15 @@ export function createBotSubStore(botId: string, botName: string) {
return Promise.reject(err); return Promise.reject(err);
} }
}, },
async [BotStoreActions.sysInfo]({ commit }) {
try {
const result = await api.get('/sysinfo');
commit('updateSysInfo', result.data);
return Promise.resolve(result.data);
} catch (err) {
return Promise.reject(err);
}
},
}, },
}; };
} }

View File

@ -14,6 +14,7 @@ import {
StrategyBacktestResult, StrategyBacktestResult,
BacktestSteps, BacktestSteps,
LogLine, LogLine,
SysInfoResponse,
} from '@/types'; } from '@/types';
export interface FtbotStateType { export interface FtbotStateType {
@ -56,6 +57,7 @@ export interface FtbotStateType {
backtestResult?: BacktestResult; backtestResult?: BacktestResult;
selectedBacktestResultKey: string; selectedBacktestResultKey: string;
backtestHistory: Record<string, StrategyBacktestResult>; backtestHistory: Record<string, StrategyBacktestResult>;
sysinfo: SysInfoResponse | {};
} }
const state = (): FtbotStateType => { const state = (): FtbotStateType => {
@ -98,6 +100,7 @@ const state = (): FtbotStateType => {
backtestResult: undefined, backtestResult: undefined,
selectedBacktestResultKey: '', selectedBacktestResultKey: '',
backtestHistory: {}, backtestHistory: {},
sysinfo: {},
}; };
}; };
export default state; export default state;

View File

@ -134,3 +134,8 @@ export interface PairHistory {
/** Data end date in as millisecond timestamp */ /** Data end date in as millisecond timestamp */
data_stop_ts: number; data_stop_ts: number;
} }
export interface SysInfoResponse {
cpu_pct: number[];
ram_pct: number;
}