[release] v0.12.0-unstable19
This commit is contained in:
parent
4556bca285
commit
15d8fdd404
|
@ -9,6 +9,16 @@ function get() {
|
|||
}))
|
||||
}
|
||||
|
||||
function reset() {
|
||||
return wrap(fetch('/cosmos/api/reset-metrics', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
export {
|
||||
get,
|
||||
reset,
|
||||
};
|
|
@ -9,7 +9,7 @@ import DialogTitle from '@mui/material/DialogTitle';
|
|||
import * as React from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
const ConfirmModal = ({ callback, label, content }) => {
|
||||
const ConfirmModal = ({ callback, label, content, startIcon }) => {
|
||||
const [openModal, setOpenModal] = useState(false);
|
||||
|
||||
return <>
|
||||
|
@ -36,6 +36,7 @@ const ConfirmModal = ({ callback, label, content }) => {
|
|||
disableElevation
|
||||
variant="outlined"
|
||||
color="warning"
|
||||
startIcon={startIcon}
|
||||
onClick={() => {
|
||||
setOpenModal(true);
|
||||
}}
|
||||
|
|
|
@ -19,7 +19,7 @@ import {
|
|||
Skeleton,
|
||||
} from '@mui/material';
|
||||
import RestartModal from './restart';
|
||||
import { SyncOutlined } from '@ant-design/icons';
|
||||
import { DeleteOutlined, SyncOutlined } from '@ant-design/icons';
|
||||
import { CosmosCheckbox, CosmosFormDivider, CosmosInputPassword, CosmosInputText, CosmosSelect } from './formShortcuts';
|
||||
import CountrySelect from '../../../components/countrySelect';
|
||||
import { DnsChallengeComp } from '../../../utils/dns-challenge-comp';
|
||||
|
@ -32,6 +32,7 @@ import { TwitterPicker
|
|||
// TODO: Remove circular deps
|
||||
import {SetPrimaryColor, SetSecondaryColor} from '../../../App';
|
||||
import { useClientInfos } from '../../../utils/hooks';
|
||||
import ConfirmModal from '../../../components/confirmModal';
|
||||
|
||||
const ConfigManagement = () => {
|
||||
const [config, setConfig] = React.useState(null);
|
||||
|
@ -68,12 +69,21 @@ const ConfigManagement = () => {
|
|||
{isAdmin && <Button variant="outlined" color="primary" startIcon={<SyncOutlined />} onClick={() => {
|
||||
setOpenRestartModal(true);
|
||||
}}>Restart Server</Button>}
|
||||
|
||||
<ConfirmModal variant="outlined" color="warning" startIcon={<DeleteOutlined />} callback={() => {
|
||||
API.metrics.reset().then((res) => {
|
||||
refresh();
|
||||
});
|
||||
}}
|
||||
label={'Purge Metrics Dashboard'}
|
||||
content={'Are you sure you want to purge all the metrics data from the dashboards?'} />
|
||||
</Stack>
|
||||
|
||||
{config && <>
|
||||
<RestartModal openModal={openModal} setOpenModal={setOpenModal} config={config} />
|
||||
<RestartModal openModal={openResartModal} setOpenModal={setOpenRestartModal} />
|
||||
|
||||
|
||||
<Formik
|
||||
initialValues={{
|
||||
MongoDB: config.MongoDB,
|
||||
|
|
|
@ -17,7 +17,8 @@ import {
|
|||
TextField,
|
||||
Typography,
|
||||
Alert,
|
||||
LinearProgress
|
||||
LinearProgress,
|
||||
CircularProgress
|
||||
} from '@mui/material';
|
||||
|
||||
// project import
|
||||
|
@ -102,10 +103,12 @@ const DashboardDefault = () => {
|
|||
const refreshMetrics = () => {
|
||||
API.metrics.get().then((res) => {
|
||||
let finalMetrics = {};
|
||||
res.data.forEach((metric) => {
|
||||
finalMetrics[metric.Key] = metric;
|
||||
});
|
||||
setMetrics(finalMetrics);
|
||||
if(res.data) {
|
||||
res.data.forEach((metric) => {
|
||||
finalMetrics[metric.Key] = metric;
|
||||
});
|
||||
setMetrics(finalMetrics);
|
||||
}
|
||||
setTimeout(refreshMetrics, 10000);
|
||||
});
|
||||
};
|
||||
|
@ -149,6 +152,19 @@ const DashboardDefault = () => {
|
|||
{/* <HomeBackground status={coStatus} />
|
||||
<TransparentHeader /> */}
|
||||
<IsLoggedIn />
|
||||
{!metrics && <Box style={{
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
zIndex: 1000,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
marginTop: '150px',
|
||||
}}>
|
||||
<CircularProgress
|
||||
size={100}
|
||||
/>
|
||||
</Box>}
|
||||
{metrics && <div style={{zIndex:2, position: 'relative'}}>
|
||||
<Grid container rowSpacing={4.5} columnSpacing={2.75} >
|
||||
<Grid item xs={12} sx={{ mb: -2.25 }}>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "cosmos-server",
|
||||
"version": "0.12.0-unstable18",
|
||||
"version": "0.12.0-unstable19",
|
||||
"description": "",
|
||||
"main": "test-server.js",
|
||||
"bugs": {
|
||||
|
|
|
@ -341,6 +341,7 @@ func InitServer() *mux.Router {
|
|||
srapi.HandleFunc("/api/constellation/block", constellation.DeviceBlock)
|
||||
|
||||
srapi.HandleFunc("/api/metrics", metrics.API_GetMetrics)
|
||||
srapi.HandleFunc("/api/reset-metrics", metrics.API_ResetMetrics)
|
||||
|
||||
if(!config.HTTPConfig.AcceptAllInsecureHostname) {
|
||||
srapi.Use(utils.EnsureHostname)
|
||||
|
|
|
@ -158,6 +158,9 @@ func AggloMetrics() []DataDefDB {
|
|||
}
|
||||
|
||||
func CommitAggl(metrics []DataDefDB) {
|
||||
lock <- true
|
||||
defer func() { <-lock }()
|
||||
|
||||
utils.Log("Metrics: Agglomeration done. Saving to DB")
|
||||
|
||||
c, errCo := utils.GetCollection(utils.GetRootAppId(), "metrics")
|
||||
|
|
|
@ -17,6 +17,37 @@ func API_GetMetrics(w http.ResponseWriter, req *http.Request) {
|
|||
"status": "OK",
|
||||
"data": AggloMetrics(),
|
||||
})
|
||||
} else {
|
||||
utils.Error("MetricsGet: Method not allowed" + req.Method, nil)
|
||||
utils.HTTPError(w, "Method not allowed", http.StatusMethodNotAllowed, "HTTP001")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func API_ResetMetrics(w http.ResponseWriter, req *http.Request) {
|
||||
if utils.AdminOnly(w, req) != nil {
|
||||
return
|
||||
}
|
||||
|
||||
c, errCo := utils.GetCollection(utils.GetRootAppId(), "metrics")
|
||||
if errCo != nil {
|
||||
utils.Error("MetricsReset: Database error" , errCo)
|
||||
utils.HTTPError(w, "Database error ", http.StatusMethodNotAllowed, "HTTP001")
|
||||
return
|
||||
}
|
||||
|
||||
// delete all metrics from database
|
||||
_, err := c.DeleteMany(nil, map[string]interface{}{})
|
||||
if err != nil {
|
||||
utils.Error("MetricsReset: Database error ", err)
|
||||
utils.HTTPError(w, "Database error ", http.StatusMethodNotAllowed, "HTTP001")
|
||||
return
|
||||
}
|
||||
|
||||
if(req.Method == "GET") {
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"status": "OK",
|
||||
})
|
||||
} else {
|
||||
utils.Error("SettingGet: Method not allowed" + req.Method, nil)
|
||||
utils.HTTPError(w, "Method not allowed", http.StatusMethodNotAllowed, "HTTP001")
|
||||
|
|
|
@ -185,6 +185,7 @@ func Run() {
|
|||
|
||||
func Init() {
|
||||
InitAggl()
|
||||
//GetSystemMetrics()
|
||||
Run()
|
||||
|
||||
go GetSystemMetrics()
|
||||
}
|
Loading…
Reference in a new issue