mirror of
https://github.com/gofiber/fiber.git
synced 2025-05-31 11:52:41 +00:00
commit
d3e53e90f0
@ -6,8 +6,11 @@ var index = []byte(`<!DOCTYPE html>
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;900&display=swap" rel="stylesheet">
|
<link
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0/dist/Chart.bundle.min.js"></script>
|
href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;900&display=swap"
|
||||||
|
rel="stylesheet">
|
||||||
|
<script
|
||||||
|
src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0/dist/Chart.bundle.min.js"></script>
|
||||||
<title>Fiber Monitor</title>
|
<title>Fiber Monitor</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
@ -72,7 +75,7 @@ var index = []byte(`<!DOCTYPE html>
|
|||||||
<body>
|
<body>
|
||||||
<section class="wrapper">
|
<section class="wrapper">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<h1>Fiber Status Monitor</h1>
|
<h1>Fiber Monitor</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<section class="charts">
|
<section class="charts">
|
||||||
@ -204,18 +207,18 @@ var index = []byte(`<!DOCTYPE html>
|
|||||||
// })
|
// })
|
||||||
// }
|
// }
|
||||||
|
|
||||||
function update(json) {
|
function update(json, rtime) {
|
||||||
cpu = json.pid.cpu.toFixed(1);
|
cpu = json.pid.cpu.toFixed(1);
|
||||||
cpuOS = json.os.cpu.toFixed(1);
|
cpuOS = json.os.cpu.toFixed(1);
|
||||||
|
|
||||||
cpuMetric.innerHTML = cpu + '% <span>' + cpuOS + '%</span>';
|
cpuMetric.innerHTML = cpu + '% <span>' + cpuOS + '%</span>';
|
||||||
ramMetric.innerHTML = formatBytes(json.pid.ram) + ' <span>' + formatBytes(json.os.ram) + '</span>';
|
ramMetric.innerHTML = formatBytes(json.pid.ram) + ' <span>' + formatBytes(json.os.ram) + '</span>';
|
||||||
rtimeMetric.innerHTML = json.rtime + 'ms';
|
rtimeMetric.innerHTML = rtime + 'ms';
|
||||||
connsMetric.innerHTML = json.conns;
|
connsMetric.innerHTML = json.conns;
|
||||||
|
|
||||||
cpuChart.data.datasets[0].data.push(cpu);
|
cpuChart.data.datasets[0].data.push(cpu);
|
||||||
ramChart.data.datasets[0].data.push((json.pid.ram / 1e6).toFixed(2));
|
ramChart.data.datasets[0].data.push((json.pid.ram / 1e6).toFixed(2));
|
||||||
rtimeChart.data.datasets[0].data.push(json.rtime);
|
rtimeChart.data.datasets[0].data.push(rtime);
|
||||||
connsChart.data.datasets[0].data.push(json.conns);
|
connsChart.data.datasets[0].data.push(json.conns);
|
||||||
|
|
||||||
const timestamp = new Date().getTime();
|
const timestamp = new Date().getTime();
|
||||||
@ -235,14 +238,21 @@ var index = []byte(`<!DOCTYPE html>
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fetchJSON() {
|
function fetchJSON() {
|
||||||
|
var t1 = ''
|
||||||
|
var t0 = performance.now()
|
||||||
fetch(window.location.href, {
|
fetch(window.location.href, {
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json'
|
||||||
},
|
},
|
||||||
credentials: 'same-origin'
|
credentials: 'same-origin'
|
||||||
})
|
})
|
||||||
.then(res => res.json())
|
.then(res => {
|
||||||
.then(update)
|
t1 = performance.now()
|
||||||
|
return res.json()
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
update(res, Math.round(performance.now() - t0))
|
||||||
|
})
|
||||||
.catch(console.error);
|
.catch(console.error);
|
||||||
setTimeout(fetchJSON, 750)
|
setTimeout(fetchJSON, 750)
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,11 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;900&display=swap" rel="stylesheet">
|
<link
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0/dist/Chart.bundle.min.js"></script>
|
href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;900&display=swap"
|
||||||
|
rel="stylesheet">
|
||||||
|
<script
|
||||||
|
src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0/dist/Chart.bundle.min.js"></script>
|
||||||
<title>Fiber Monitor</title>
|
<title>Fiber Monitor</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
@ -70,7 +73,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<section class="wrapper">
|
<section class="wrapper">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<h1>Fiber Status Monitor</h1>
|
<h1>Fiber Monitor</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<section class="charts">
|
<section class="charts">
|
||||||
@ -202,18 +205,18 @@
|
|||||||
// })
|
// })
|
||||||
// }
|
// }
|
||||||
|
|
||||||
function update(json) {
|
function update(json, rtime) {
|
||||||
cpu = json.pid.cpu.toFixed(1);
|
cpu = json.pid.cpu.toFixed(1);
|
||||||
cpuOS = json.os.cpu.toFixed(1);
|
cpuOS = json.os.cpu.toFixed(1);
|
||||||
|
|
||||||
cpuMetric.innerHTML = cpu + '% <span>' + cpuOS + '%</span>';
|
cpuMetric.innerHTML = cpu + '% <span>' + cpuOS + '%</span>';
|
||||||
ramMetric.innerHTML = formatBytes(json.pid.ram) + ' <span>' + formatBytes(json.os.ram) + '</span>';
|
ramMetric.innerHTML = formatBytes(json.pid.ram) + ' <span>' + formatBytes(json.os.ram) + '</span>';
|
||||||
rtimeMetric.innerHTML = json.rtime + 'ms';
|
rtimeMetric.innerHTML = rtime + 'ms';
|
||||||
connsMetric.innerHTML = json.conns;
|
connsMetric.innerHTML = json.conns;
|
||||||
|
|
||||||
cpuChart.data.datasets[0].data.push(cpu);
|
cpuChart.data.datasets[0].data.push(cpu);
|
||||||
ramChart.data.datasets[0].data.push((json.pid.ram / 1e6).toFixed(2));
|
ramChart.data.datasets[0].data.push((json.pid.ram / 1e6).toFixed(2));
|
||||||
rtimeChart.data.datasets[0].data.push(json.rtime);
|
rtimeChart.data.datasets[0].data.push(rtime);
|
||||||
connsChart.data.datasets[0].data.push(json.conns);
|
connsChart.data.datasets[0].data.push(json.conns);
|
||||||
|
|
||||||
const timestamp = new Date().getTime();
|
const timestamp = new Date().getTime();
|
||||||
@ -233,14 +236,21 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fetchJSON() {
|
function fetchJSON() {
|
||||||
|
var t1 = ''
|
||||||
|
var t0 = performance.now()
|
||||||
fetch(window.location.href, {
|
fetch(window.location.href, {
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json'
|
||||||
},
|
},
|
||||||
credentials: 'same-origin'
|
credentials: 'same-origin'
|
||||||
})
|
})
|
||||||
.then(res => res.json())
|
.then(res => {
|
||||||
.then(update)
|
t1 = performance.now()
|
||||||
|
return res.json()
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
update(res, Match.Round(performance.now() - t0))
|
||||||
|
})
|
||||||
.catch(console.error);
|
.catch(console.error);
|
||||||
setTimeout(fetchJSON, 750)
|
setTimeout(fetchJSON, 750)
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import (
|
|||||||
type stats struct {
|
type stats struct {
|
||||||
PID statsPID `json:"pid"`
|
PID statsPID `json:"pid"`
|
||||||
OS statsOS `json:"os"`
|
OS statsOS `json:"os"`
|
||||||
Rtime int64 `json:"rtime"`
|
|
||||||
Conns uint32 `json:"conns"`
|
Conns uint32 `json:"conns"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +75,6 @@ func New() fiber.Handler {
|
|||||||
data.PID.RAM = monitPidRam
|
data.PID.RAM = monitPidRam
|
||||||
data.OS.CPU = monitOsCpu
|
data.OS.CPU = monitOsCpu
|
||||||
data.OS.RAM = monitOsRam
|
data.OS.RAM = monitOsRam
|
||||||
data.Rtime = (time.Now().UnixNano() - c.Context().Time().UnixNano()) / 1000000
|
|
||||||
data.Conns = c.App().Server().GetCurrentConcurrency()
|
data.Conns = c.App().Server().GetCurrentConcurrency()
|
||||||
mutex.Unlock()
|
mutex.Unlock()
|
||||||
return c.Status(fiber.StatusOK).JSON(data)
|
return c.Status(fiber.StatusOK).JSON(data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user