[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 {
|
export {
|
||||||
get,
|
get,
|
||||||
|
reset,
|
||||||
};
|
};
|
|
@ -9,7 +9,7 @@ import DialogTitle from '@mui/material/DialogTitle';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
const ConfirmModal = ({ callback, label, content }) => {
|
const ConfirmModal = ({ callback, label, content, startIcon }) => {
|
||||||
const [openModal, setOpenModal] = useState(false);
|
const [openModal, setOpenModal] = useState(false);
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
|
@ -36,6 +36,7 @@ const ConfirmModal = ({ callback, label, content }) => {
|
||||||
disableElevation
|
disableElevation
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
color="warning"
|
color="warning"
|
||||||
|
startIcon={startIcon}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setOpenModal(true);
|
setOpenModal(true);
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import {
|
||||||
Skeleton,
|
Skeleton,
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import RestartModal from './restart';
|
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 { CosmosCheckbox, CosmosFormDivider, CosmosInputPassword, CosmosInputText, CosmosSelect } from './formShortcuts';
|
||||||
import CountrySelect from '../../../components/countrySelect';
|
import CountrySelect from '../../../components/countrySelect';
|
||||||
import { DnsChallengeComp } from '../../../utils/dns-challenge-comp';
|
import { DnsChallengeComp } from '../../../utils/dns-challenge-comp';
|
||||||
|
@ -32,6 +32,7 @@ import { TwitterPicker
|
||||||
// TODO: Remove circular deps
|
// TODO: Remove circular deps
|
||||||
import {SetPrimaryColor, SetSecondaryColor} from '../../../App';
|
import {SetPrimaryColor, SetSecondaryColor} from '../../../App';
|
||||||
import { useClientInfos } from '../../../utils/hooks';
|
import { useClientInfos } from '../../../utils/hooks';
|
||||||
|
import ConfirmModal from '../../../components/confirmModal';
|
||||||
|
|
||||||
const ConfigManagement = () => {
|
const ConfigManagement = () => {
|
||||||
const [config, setConfig] = React.useState(null);
|
const [config, setConfig] = React.useState(null);
|
||||||
|
@ -68,12 +69,21 @@ const ConfigManagement = () => {
|
||||||
{isAdmin && <Button variant="outlined" color="primary" startIcon={<SyncOutlined />} onClick={() => {
|
{isAdmin && <Button variant="outlined" color="primary" startIcon={<SyncOutlined />} onClick={() => {
|
||||||
setOpenRestartModal(true);
|
setOpenRestartModal(true);
|
||||||
}}>Restart Server</Button>}
|
}}>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>
|
</Stack>
|
||||||
|
|
||||||
{config && <>
|
{config && <>
|
||||||
<RestartModal openModal={openModal} setOpenModal={setOpenModal} config={config} />
|
<RestartModal openModal={openModal} setOpenModal={setOpenModal} config={config} />
|
||||||
<RestartModal openModal={openResartModal} setOpenModal={setOpenRestartModal} />
|
<RestartModal openModal={openResartModal} setOpenModal={setOpenRestartModal} />
|
||||||
|
|
||||||
|
|
||||||
<Formik
|
<Formik
|
||||||
initialValues={{
|
initialValues={{
|
||||||
MongoDB: config.MongoDB,
|
MongoDB: config.MongoDB,
|
||||||
|
|
|
@ -17,7 +17,8 @@ import {
|
||||||
TextField,
|
TextField,
|
||||||
Typography,
|
Typography,
|
||||||
Alert,
|
Alert,
|
||||||
LinearProgress
|
LinearProgress,
|
||||||
|
CircularProgress
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
|
|
||||||
// project import
|
// project import
|
||||||
|
@ -102,10 +103,12 @@ const DashboardDefault = () => {
|
||||||
const refreshMetrics = () => {
|
const refreshMetrics = () => {
|
||||||
API.metrics.get().then((res) => {
|
API.metrics.get().then((res) => {
|
||||||
let finalMetrics = {};
|
let finalMetrics = {};
|
||||||
res.data.forEach((metric) => {
|
if(res.data) {
|
||||||
finalMetrics[metric.Key] = metric;
|
res.data.forEach((metric) => {
|
||||||
});
|
finalMetrics[metric.Key] = metric;
|
||||||
setMetrics(finalMetrics);
|
});
|
||||||
|
setMetrics(finalMetrics);
|
||||||
|
}
|
||||||
setTimeout(refreshMetrics, 10000);
|
setTimeout(refreshMetrics, 10000);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -149,6 +152,19 @@ const DashboardDefault = () => {
|
||||||
{/* <HomeBackground status={coStatus} />
|
{/* <HomeBackground status={coStatus} />
|
||||||
<TransparentHeader /> */}
|
<TransparentHeader /> */}
|
||||||
<IsLoggedIn />
|
<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'}}>
|
{metrics && <div style={{zIndex:2, position: 'relative'}}>
|
||||||
<Grid container rowSpacing={4.5} columnSpacing={2.75} >
|
<Grid container rowSpacing={4.5} columnSpacing={2.75} >
|
||||||
<Grid item xs={12} sx={{ mb: -2.25 }}>
|
<Grid item xs={12} sx={{ mb: -2.25 }}>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "cosmos-server",
|
"name": "cosmos-server",
|
||||||
"version": "0.12.0-unstable18",
|
"version": "0.12.0-unstable19",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "test-server.js",
|
"main": "test-server.js",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
|
|
|
@ -341,6 +341,7 @@ func InitServer() *mux.Router {
|
||||||
srapi.HandleFunc("/api/constellation/block", constellation.DeviceBlock)
|
srapi.HandleFunc("/api/constellation/block", constellation.DeviceBlock)
|
||||||
|
|
||||||
srapi.HandleFunc("/api/metrics", metrics.API_GetMetrics)
|
srapi.HandleFunc("/api/metrics", metrics.API_GetMetrics)
|
||||||
|
srapi.HandleFunc("/api/reset-metrics", metrics.API_ResetMetrics)
|
||||||
|
|
||||||
if(!config.HTTPConfig.AcceptAllInsecureHostname) {
|
if(!config.HTTPConfig.AcceptAllInsecureHostname) {
|
||||||
srapi.Use(utils.EnsureHostname)
|
srapi.Use(utils.EnsureHostname)
|
||||||
|
|
|
@ -158,8 +158,11 @@ func AggloMetrics() []DataDefDB {
|
||||||
}
|
}
|
||||||
|
|
||||||
func CommitAggl(metrics []DataDefDB) {
|
func CommitAggl(metrics []DataDefDB) {
|
||||||
utils.Log("Metrics: Agglomeration done. Saving to DB")
|
lock <- true
|
||||||
|
defer func() { <-lock }()
|
||||||
|
|
||||||
|
utils.Log("Metrics: Agglomeration done. Saving to DB")
|
||||||
|
|
||||||
c, errCo := utils.GetCollection(utils.GetRootAppId(), "metrics")
|
c, errCo := utils.GetCollection(utils.GetRootAppId(), "metrics")
|
||||||
if errCo != nil {
|
if errCo != nil {
|
||||||
utils.Error("Metrics - Database Connect", errCo)
|
utils.Error("Metrics - Database Connect", errCo)
|
||||||
|
|
|
@ -17,6 +17,37 @@ func API_GetMetrics(w http.ResponseWriter, req *http.Request) {
|
||||||
"status": "OK",
|
"status": "OK",
|
||||||
"data": AggloMetrics(),
|
"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 {
|
} else {
|
||||||
utils.Error("SettingGet: Method not allowed" + req.Method, nil)
|
utils.Error("SettingGet: Method not allowed" + req.Method, nil)
|
||||||
utils.HTTPError(w, "Method not allowed", http.StatusMethodNotAllowed, "HTTP001")
|
utils.HTTPError(w, "Method not allowed", http.StatusMethodNotAllowed, "HTTP001")
|
||||||
|
|
|
@ -185,6 +185,7 @@ func Run() {
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
InitAggl()
|
InitAggl()
|
||||||
//GetSystemMetrics()
|
|
||||||
Run()
|
Run()
|
||||||
|
|
||||||
|
go GetSystemMetrics()
|
||||||
}
|
}
|
Loading…
Reference in a new issue