Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
wspy-monitor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
wspy-monitor
Commits
cb369df7
Commit
cb369df7
authored
11 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Now using psutil for sys info (cross-platform)
parent
b2feaa96
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
index.html
+1
-1
1 addition, 1 deletion
index.html
monitor.coffee
+10
-12
10 additions, 12 deletions
monitor.coffee
server.py
+21
-30
21 additions, 30 deletions
server.py
with
32 additions
and
43 deletions
index.html
+
1
−
1
View file @
cb369df7
...
...
@@ -8,7 +8,7 @@
<body>
<div
class=
"header"
>
<div
class=
"center"
>
<i
class=
"icon-gear"
></i><span
id=
"
releas
e"
>
-
</span>
<i
class=
"icon-gear"
></i><span
id=
"
osnam
e"
>
-
</span>
<span
id=
"status"
class=
"right"
></span>
</div>
</div>
...
...
This diff is collapsed.
Click to expand it.
monitor.coffee
+
10
−
12
View file @
cb369df7
el
=
(
id
)
->
document
.
getElementById
(
id
)
set
=
(
id
,
value
)
->
el
(
id
).
innerHTML
=
value
values
=
(
e
for
e
in
el
(
'content'
).
getElementsByTagName
(
'span'
))
\
.
concat
(
el
(
'
releas
e'
))
.
concat
(
el
(
'
osnam
e'
))
connect
=
->
val
.
innerHTML
=
'Connecting...'
for
val
in
values
...
...
@@ -26,19 +26,17 @@ connect = ->
console
.
log
'msg'
,
msg
.
data
data
=
JSON
.
parse
(
msg
.
data
)
set
(
'release'
,
data
.
release
)
if
data
.
release
set
(
'osname'
,
data
.
osname
)
if
data
.
osname
set
(
'uptime'
,
fmt_time
(
data
.
uptime
))
if
data
.
uptime
set
(
'cpu-usage'
,
"
#{
data
.
cpu_usage
}
%"
)
set
(
'memory'
,
fmt_kbytes_usage
(
data
.
memory
))
set
(
'disk'
,
fmt_kbytes_usage
(
data
.
disk
))
if
data
.
temps
.
length
if
data
.
temps
el
(
'temp'
).
innerHTML
=
(
"
#{
deg
}
℃"
for
deg
in
data
.
temps
)
\
.
join
(
' '
)
set
(
'cpu-usage'
,
"
#{
data
.
cpu_usage
}
%"
)
if
data
.
cpu_usage
set
(
'memory'
,
fmt_kbytes_usage
(
data
.
memory
))
if
data
.
memory
set
(
'disk'
,
fmt_kbytes_usage
(
data
.
disk
))
if
data
.
disk
else
set
(
'temp'
,
'-'
)
fmt_time
=
(
total
)
->
total
=
Math
.
round
total
...
...
@@ -58,8 +56,8 @@ fmt_time = (total) ->
str
fmt_kbytes_usage
=
([
used
,
total
])
->
used
=
Math
.
round
used
/
1
000
total
=
Math
.
round
total
/
1
000
used
=
Math
.
round
used
/
1
e6
total
=
Math
.
round
total
/
1
e6
perc
=
Math
.
round
used
/
total
*
100
return
"
#{
used
}
MB /
#{
total
}
MB (
#{
perc
}
%)"
...
...
This diff is collapsed.
Click to expand it.
server.py
+
21
−
30
View file @
cb369df7
...
...
@@ -3,20 +3,27 @@ import time
import
socket
import
json
import
re
import
psutil
import
platform
from
subprocess
import
check_output
from
threading
import
Thread
from
twspy
import
websocket
,
Frame
,
OPCODE_TEXT
,
WebkitDeflateFrame
def
osname
():
if
platform
.
system
()
==
'
Linux
'
:
return
'
Linux %s %s (%s)
'
%
platform
.
dist
()
#return '%s %s' % (platform.system(), platform.release())
return
platform
.
platform
()
def
stats
():
# Release
dist
,
codename
=
check_output
([
'
lsb_release
'
,
'
-sdc
'
]).
rstrip
().
split
(
'
\n
'
)
yield
'
release
'
,
'
%s (%s)
'
%
(
dist
,
codename
)
# OS identification
yield
'
osname
'
,
osname
()
# Uptime
with
open
(
'
/proc/uptime
'
,
'
r
'
)
as
f
:
uptime
,
idletime
=
map
(
float
,
f
.
read
().
split
(
'
'
))
yield
'
uptime
'
,
uptime
yield
'
uptime
'
,
time
.
time
()
-
psutil
.
get_boot_time
()
# CPU temperature
try
:
...
...
@@ -28,39 +35,23 @@ def stats():
if
m
:
temps
.
append
(
float
(
m
.
group
(
1
)))
assert
len
(
temps
)
==
psutil
.
NUM_CPUS
yield
'
temps
'
,
temps
except
:
pass
# CPU usage
with
open
(
'
/proc/stat
'
,
'
r
'
)
as
f
:
line
=
f
.
readlines
()[
0
].
rstrip
().
split
()
assert
line
[
0
]
==
'
cpu
'
numbers
=
map
(
int
,
line
[
1
:])
total
=
sum
(
numbers
)
idle
=
numbers
[
3
]
yield
'
cpu_usage
'
,
round
(
float
(
total
-
idle
)
/
total
*
100
,
2
)
cpu
=
psutil
.
cpu_times
()
total
=
sum
(
cpu
)
yield
'
cpu_usage
'
,
round
(
float
(
total
-
cpu
.
idle
)
/
total
*
100
,
2
)
# Memory usage
with
open
(
'
/proc/meminfo
'
,
'
r
'
)
as
f
:
for
line
in
f
:
if
line
.
startswith
(
'
MemTotal
'
):
assert
line
.
endswith
(
'
kB
\n
'
)
total
=
int
(
line
.
split
()[
1
])
elif
line
.
startswith
(
'
MemFree
'
):
assert
line
.
endswith
(
'
kB
\n
'
)
used
=
total
-
int
(
line
.
split
()[
1
])
yield
'
memory
'
,
(
used
,
total
)
break
mem
=
psutil
.
phymem_usage
()
yield
'
memory
'
,
(
mem
.
used
,
mem
.
total
)
# Disk usage
for
line
in
check_output
(
'
df
'
).
split
(
'
\n
'
):
parts
=
line
.
split
()
if
parts
[
0
].
startswith
(
'
/dev/
'
)
and
parts
[
5
]
==
'
/
'
:
used
,
avail
=
map
(
int
,
parts
[
2
:
4
])
yield
'
disk
'
,
(
used
,
used
+
avail
)
break
disk
=
psutil
.
disk_usage
(
'
/
'
)
yield
'
disk
'
,
(
disk
.
used
,
disk
.
total
)
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment