Skip to content

Commit

Permalink
Merge pull request #27 from echo-dave/dataRateBug
Browse files Browse the repository at this point in the history
fix timeslice button implementation bug + client duplicate data potential
  • Loading branch information
echo-dave authored Nov 21, 2023
2 parents 8290f81 + 4f5cf00 commit aa58f1a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions api/getWebData.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const getWebData = (hostname, io) => {
console.warn(err)
}
if (response[0] === 'ok') {
console.log('webData Response', response)
dataLoop()
if (monitoringState[hostname] !== response.length) {
monitoringState[hostname] = response.length
}
// if (monitoringState[hostname] !== response.length) {
// monitoringState[hostname] = response.length
// }
}
if (response[0] !== 'ok') monitoringState[hostname] = 0
})
}
dataLoop()
Expand Down
4 changes: 2 additions & 2 deletions clientWeb/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
const updateDataPoints = async (count) => {
try {
if (count > metrics.length + 1) {
let res = await fetch(`/api/tsClientData/count/${count}`)
let res = await fetch(`/api/tsClientData/${hostname}/${count}`)
if (!res.ok) {
throw new Error({ error: res, msg: 'Failed to get client data' })
}
Expand All @@ -95,7 +95,7 @@
<meta name="description" content="Nodesysmon a simple system monitor" />
</svelte:head>
<div id="wrap" class="no-border">
<Header bind:metrics {subscribe} {unsubscribe} />
<Header bind:metrics bind:hostname {subscribe} {unsubscribe} {minutes} />

<div id="chartTimeScaleButtons" class="no-border">
<div class="left no-border">
Expand Down
5 changes: 4 additions & 1 deletion clientWeb/src/routes/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
export let metrics
export let subscribe
export let unsubscribe
export let minutes
export let hostname
let hostmenutoggle = false
let currentHost
//storing a pending promise because svelt needs to await data from the onMount
Expand All @@ -31,13 +33,14 @@
unsubscribe(currentHost)
console.log('unsub: ', currentHost)
subscribe(name)
let resp = await fetch(`/api/serverchange/${name}`)
let resp = await fetch(`/api/serverchange/${name}/${minutes * 30}`)
if (!resp.ok) throw new Error(resp.status)
resp = await resp.json()
resp.map((el) => {
el.time = new Date(el.time)
})
currentHost = name
hostname = currentHost
metrics = resp.reverse()
// metrics = resp
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodesysmon",
"version": "0.7.1",
"version": "0.7.2",
"description": "Node simple system monitoring",
"main": "nodesysmon.js",
"engines": {
Expand Down
8 changes: 4 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ export default async (thresholds) => {
}
})

app.get('/api/tsClientData/count/:count', async (req, res) => {
const data = await getHistory(req.params.count, serverName)
app.get('/api/tsClientData/:server/:count', async (req, res) => {
const data = await getHistory(req.params.count, req.params.server)
res.status(200).json(data)
})

app.get('/api/serverchange/:host', async (req, res) => {
const data = await getHistory(300, req.params.host)
app.get('/api/serverchange/:host/:count', async (req, res) => {
const data = await getHistory(req.params.count, req.params.host)
if (monitoringState[req.params.host]) {
monitoringState[req.params.host] += 1
console.log('change: ', monitoringState)
Expand Down

0 comments on commit aa58f1a

Please sign in to comment.