From bba55cf240736ee8c659b219cae803e0749c5a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=ADtalo=20Silva?= Date: Thu, 21 Jan 2021 12:41:57 -0300 Subject: [PATCH] Added total RAM to counters --- middleware/monitor/index.go | 29 +++++++++++++++++++++++++++-- middleware/monitor/index.html | 29 +++++++++++++++++++++++++++-- middleware/monitor/monitor.go | 16 ++++++++++------ 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/middleware/monitor/index.go b/middleware/monitor/index.go index bdb6cccc85..92341dddb1 100644 --- a/middleware/monitor/index.go +++ b/middleware/monitor/index.go @@ -65,6 +65,14 @@ var index = []byte(` color: #777; } + h2 span.ram_os { + color: rgba(255, 150, 0, .8); + } + + h2 span.ram_total { + color: rgba(0, 200, 0, .8); + } + canvas { width: 200px; height: 180px; @@ -92,7 +100,7 @@ var index = []byte(`
Memory Usage
-

0.00 MB

+

0.00 MB

@@ -200,6 +208,21 @@ var index = []byte(` }); } + ramChart.data.datasets.push({ + data: [], + lineTension: 0.2, + pointRadius: 0, + backgroundColor: 'rgba(255, 200, 0, .6)', + borderColor: 'rgba(255, 150, 0, .8)', + }) + ramChart.data.datasets.push({ + data: [], + lineTension: 0.2, + pointRadius: 0, + backgroundColor: 'rgba(0, 255, 0, .4)', + borderColor: 'rgba(0, 200, 0, .8)', + }) + // function init() { // charts.forEach(chart => { // chart.data.datasets[0].data = JSON.parse(localStorage.getItem(chart.canvas.id)) || [] @@ -212,11 +235,13 @@ var index = []byte(` cpuOS = json.os.cpu.toFixed(1); cpuMetric.innerHTML = cpu + '% ' + cpuOS + '%'; - ramMetric.innerHTML = formatBytes(json.pid.ram) + ' ' + formatBytes(json.os.ram) + ''; + ramMetric.innerHTML = formatBytes(json.pid.ram) + ' / ' + formatBytes(json.os.ram) + ' / ' + formatBytes(json.os.total_ram) + ''; rtimeMetric.innerHTML = rtime + 'ms client'; connsMetric.innerHTML = json.pid.conns + ' ' + json.os.conns + ''; cpuChart.data.datasets[0].data.push(cpu); + ramChart.data.datasets[2].data.push((json.os.total_ram / 1e6).toFixed(2)); + ramChart.data.datasets[1].data.push((json.os.ram / 1e6).toFixed(2)); ramChart.data.datasets[0].data.push((json.pid.ram / 1e6).toFixed(2)); rtimeChart.data.datasets[0].data.push(rtime); connsChart.data.datasets[0].data.push(json.pid.conns); diff --git a/middleware/monitor/index.html b/middleware/monitor/index.html index 2bbe7cb2c5..57d9f4cba2 100644 --- a/middleware/monitor/index.html +++ b/middleware/monitor/index.html @@ -63,6 +63,14 @@ color: #777; } + h2 span.ram_os { + color: rgba(255, 150, 0, .8); + } + + h2 span.ram_total { + color: rgba(0, 200, 0, .8); + } + canvas { width: 200px; height: 180px; @@ -90,7 +98,7 @@

0.00%

Memory Usage
-

0.00 MB

+

0.00 MB

@@ -198,6 +206,21 @@

0

}); } + ramChart.data.datasets.push({ + data: [], + lineTension: 0.2, + pointRadius: 0, + backgroundColor: 'rgba(255, 200, 0, .6)', + borderColor: 'rgba(255, 150, 0, .8)', + }) + ramChart.data.datasets.push({ + data: [], + lineTension: 0.2, + pointRadius: 0, + backgroundColor: 'rgba(0, 255, 0, .4)', + borderColor: 'rgba(0, 200, 0, .8)', + }) + // function init() { // charts.forEach(chart => { // chart.data.datasets[0].data = JSON.parse(localStorage.getItem(chart.canvas.id)) || [] @@ -210,11 +233,13 @@

0

cpuOS = json.os.cpu.toFixed(1); cpuMetric.innerHTML = cpu + '% ' + cpuOS + '%'; - ramMetric.innerHTML = formatBytes(json.pid.ram) + ' ' + formatBytes(json.os.ram) + ''; + ramMetric.innerHTML = formatBytes(json.pid.ram) + ' / ' + formatBytes(json.os.ram) + ' / ' + formatBytes(json.os.total_ram) + ''; rtimeMetric.innerHTML = rtime + 'ms client'; connsMetric.innerHTML = json.pid.conns + ' ' + json.os.conns + ''; cpuChart.data.datasets[0].data.push(cpu); + ramChart.data.datasets[2].data.push((json.os.total_ram / 1e6).toFixed(2)); + ramChart.data.datasets[1].data.push((json.os.ram / 1e6).toFixed(2)); ramChart.data.datasets[0].data.push((json.pid.ram / 1e6).toFixed(2)); rtimeChart.data.datasets[0].data.push(rtime); connsChart.data.datasets[0].data.push(json.pid.conns); diff --git a/middleware/monitor/monitor.go b/middleware/monitor/monitor.go index a637014c2a..892fb3f0ac 100644 --- a/middleware/monitor/monitor.go +++ b/middleware/monitor/monitor.go @@ -25,9 +25,10 @@ type statsPID struct { Conns int `json:"conns"` } type statsOS struct { - CPU float64 `json:"cpu"` - RAM uint64 `json:"ram"` - Conns int `json:"conns"` + CPU float64 `json:"cpu"` + RAM uint64 `json:"ram"` + TotalRAM uint64 `json:"total_ram"` + Conns int `json:"conns"` } var ( @@ -35,9 +36,10 @@ var ( monitPidRam atomic.Value monitPidConns atomic.Value - monitOsCpu atomic.Value - monitOsRam atomic.Value - monitOsConns atomic.Value + monitOsCpu atomic.Value + monitOsRam atomic.Value + monitOsTotalRam atomic.Value + monitOsConns atomic.Value ) var ( @@ -78,6 +80,7 @@ func New() fiber.Handler { data.OS.CPU = monitOsCpu.Load().(float64) data.OS.RAM = monitOsRam.Load().(uint64) + data.OS.TotalRAM = monitOsTotalRam.Load().(uint64) data.OS.Conns = monitOsConns.Load().(int) mutex.Unlock() return c.Status(fiber.StatusOK).JSON(data) @@ -101,6 +104,7 @@ func updateStatistics(p *process.Process) { if osMem, _ := mem.VirtualMemory(); osMem != nil { monitOsRam.Store(osMem.Used) + monitOsTotalRam.Store(osMem.Total) } pidConns, _ := net.ConnectionsPid("tcp", p.Pid)