Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Jabis Sev贸n
/
esm
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
5837765c
authored
2016-08-06 18:58:24 +0200
by
Rafal Wilinski
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Layout and statistics improvements
1 parent
5c4f897e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
17 deletions
index.html
index.js
index.html
View file @
5837765
...
...
@@ -25,17 +25,13 @@
}
.stats-column
{
display
:
flex
;
flex-direction
:
column
;
justify-content
:
center
;
align-content
:
center
;
margin-right
:
3em
;
flex
:
0
0
200px
;
}
.container
{
display
:
flex
;
flex-direction
:
row
;
margin
:
auto
;
margin
-top
:
20px
;
}
.footer
{
...
...
@@ -65,6 +61,20 @@
</div>
<canvas
id=
"memChart"
width=
"400"
height=
"100"
></canvas>
</div>
<div
class=
"container"
>
<div
class=
"stats-column"
>
<h5>
Requests per second
</h5>
<h1
id=
"rpsStat"
>
1.45
</h1>
</div>
<canvas
id=
"rpsChart"
width=
"400"
height=
"100"
></canvas>
</div>
<div
class=
"Status Codes"
>
<div
class=
"stats-column"
>
<h5>
Response status codes
</h5>
<h1
id=
"codeStat"
>
OK
</h1>
</div>
<canvas
id=
"codeChart"
width=
"400"
height=
"100"
></canvas>
</div>
<div
class=
"footer"
>
<p>
Powered by Socket.io
</p>
</div>
...
...
@@ -135,12 +145,13 @@
});
socket
.
on
(
'stats'
,
function
(
data
)
{
console
.
log
(
data
);
cpuStat
.
textContent
=
data
.
osStats
[
data
.
osStats
.
length
-
1
].
cpu
.
toFixed
(
1
)
+
'%'
;
cpuChart
.
data
.
datasets
[
0
].
data
=
data
.
osStats
.
map
((
point
)
=>
point
.
cpu
);
cpuChart
.
data
.
labels
=
data
.
osStats
.
map
((
point
)
=>
point
.
timestamp
);
cpuChart
.
update
();
memStat
.
textContent
=
(
data
.
osStats
[
data
.
osStats
.
length
-
1
].
memory
/
1024
/
1024
)
.
toFixed
(
1
)
+
'MB'
;
memStat
.
textContent
=
data
.
osStats
[
data
.
osStats
.
length
-
1
].
memory
.
toFixed
(
1
)
+
'MB'
;
memChart
.
data
.
datasets
[
0
].
data
=
data
.
osStats
.
map
((
point
)
=>
point
.
memory
);
memChart
.
data
.
labels
=
data
.
osStats
.
map
((
point
)
=>
point
.
timestamp
);
memChart
.
update
();
...
...
index.js
View file @
5837765
...
...
@@ -14,19 +14,22 @@
retention
:
100
,
};
const
gatherOsMetrics
=
(
io
)
=>
{
const
gatherOsMetrics
=
(
io
,
config
)
=>
{
pidusage
.
stat
(
process
.
pid
,
(
err
,
stat
)
=>
{
stat
.
timestamp
=
Date
.
now
();
// Convert from B to MB
stat
.
memory
=
stat
.
memory
/
1024
/
1024
;
osStats
.
push
(
stat
);
if
(
osStats
.
length
>=
config
.
retention
)
osStats
.
shift
();
sendMetrics
(
io
);
});
};
const
sendMetrics
=
(
io
)
=>
{
osStats
.
slice
(
Math
.
max
(
osStats
.
length
-
defaultConfig
.
retention
,
1
));
io
.
emit
(
'stats'
,
{
osStats
:
osStats
.
slice
(
Math
.
max
(
osStats
.
length
-
defaultConfig
.
retention
,
1
))
,
osStats
,
responseTimes
});
};
...
...
@@ -50,11 +53,7 @@
const
io
=
require
(
'socket.io'
)(
config
.
socketPort
);
setInterval
(()
=>
gatherOsMetrics
(
io
),
config
.
interval
*
1000
);
io
.
on
(
'connection'
,
(
socket
)
=>
{
});
setInterval
(()
=>
gatherOsMetrics
(
io
,
config
),
config
.
interval
*
1000
);
return
(
req
,
res
,
next
)
=>
{
const
startTime
=
process
.
hrtime
();
...
...
@@ -70,7 +69,6 @@
responseTime
,
timestamp
:
Date
.
now
()
});
});
next
();
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment