Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wspy-monitor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
wspy-monitor
Commits
cb369df7
Commit
cb369df7
authored
Aug 31, 2013
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Now using psutil for sys info (cross-platform)
parent
b2feaa96
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
43 deletions
+32
-43
index.html
index.html
+1
-1
monitor.coffee
monitor.coffee
+10
-12
server.py
server.py
+21
-30
No files found.
index.html
View file @
cb369df7
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
<body>
<body>
<div
class=
"header"
>
<div
class=
"header"
>
<div
class=
"center"
>
<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>
<span
id=
"status"
class=
"right"
></span>
</div>
</div>
</div>
</div>
...
...
monitor.coffee
View file @
cb369df7
el
=
(
id
)
->
document
.
getElementById
(
id
)
el
=
(
id
)
->
document
.
getElementById
(
id
)
set
=
(
id
,
value
)
->
el
(
id
).
innerHTML
=
value
set
=
(
id
,
value
)
->
el
(
id
).
innerHTML
=
value
values
=
(
e
for
e
in
el
(
'content'
).
getElementsByTagName
(
'span'
))
\
values
=
(
e
for
e
in
el
(
'content'
).
getElementsByTagName
(
'span'
))
\
.
concat
(
el
(
'
releas
e'
))
.
concat
(
el
(
'
osnam
e'
))
connect
=
->
connect
=
->
val
.
innerHTML
=
'Connecting...'
for
val
in
values
val
.
innerHTML
=
'Connecting...'
for
val
in
values
...
@@ -26,19 +26,17 @@ connect = ->
...
@@ -26,19 +26,17 @@ connect = ->
console
.
log
'msg'
,
msg
.
data
console
.
log
'msg'
,
msg
.
data
data
=
JSON
.
parse
(
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
(
'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
)
\
el
(
'temp'
).
innerHTML
=
(
"
#{
deg
}
℃"
for
deg
in
data
.
temps
)
\
.
join
(
' '
)
.
join
(
' '
)
else
set
(
'cpu-usage'
,
"
#{
data
.
cpu_usage
}
%"
)
if
data
.
cpu_usage
set
(
'temp'
,
'-'
)
set
(
'memory'
,
fmt_kbytes_usage
(
data
.
memory
))
if
data
.
memory
set
(
'disk'
,
fmt_kbytes_usage
(
data
.
disk
))
if
data
.
disk
fmt_time
=
(
total
)
->
fmt_time
=
(
total
)
->
total
=
Math
.
round
total
total
=
Math
.
round
total
...
@@ -58,8 +56,8 @@ fmt_time = (total) ->
...
@@ -58,8 +56,8 @@ fmt_time = (total) ->
str
str
fmt_kbytes_usage
=
([
used
,
total
])
->
fmt_kbytes_usage
=
([
used
,
total
])
->
used
=
Math
.
round
used
/
1
000
used
=
Math
.
round
used
/
1
e6
total
=
Math
.
round
total
/
1
000
total
=
Math
.
round
total
/
1
e6
perc
=
Math
.
round
used
/
total
*
100
perc
=
Math
.
round
used
/
total
*
100
return
"
#{
used
}
MB /
#{
total
}
MB (
#{
perc
}
%)"
return
"
#{
used
}
MB /
#{
total
}
MB (
#{
perc
}
%)"
...
...
server.py
View file @
cb369df7
...
@@ -3,20 +3,27 @@ import time
...
@@ -3,20 +3,27 @@ import time
import
socket
import
socket
import
json
import
json
import
re
import
re
import
psutil
import
platform
from
subprocess
import
check_output
from
subprocess
import
check_output
from
threading
import
Thread
from
threading
import
Thread
from
twspy
import
websocket
,
Frame
,
OPCODE_TEXT
,
WebkitDeflateFrame
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
():
def
stats
():
# Release
# OS identification
dist
,
codename
=
check_output
([
'lsb_release'
,
'-sdc'
]).
rstrip
().
split
(
'
\
n
'
)
yield
'osname'
,
osname
()
yield
'release'
,
'%s (%s)'
%
(
dist
,
codename
)
# Uptime
# Uptime
with
open
(
'/proc/uptime'
,
'r'
)
as
f
:
yield
'uptime'
,
time
.
time
()
-
psutil
.
get_boot_time
()
uptime
,
idletime
=
map
(
float
,
f
.
read
().
split
(
' '
))
yield
'uptime'
,
uptime
# CPU temperature
# CPU temperature
try
:
try
:
...
@@ -28,39 +35,23 @@ def stats():
...
@@ -28,39 +35,23 @@ def stats():
if
m
:
if
m
:
temps
.
append
(
float
(
m
.
group
(
1
)))
temps
.
append
(
float
(
m
.
group
(
1
)))
assert
len
(
temps
)
==
psutil
.
NUM_CPUS
yield
'temps'
,
temps
yield
'temps'
,
temps
except
:
except
:
pass
pass
# CPU usage
# CPU usage
with
open
(
'/proc/stat'
,
'r'
)
as
f
:
cpu
=
psutil
.
cpu_times
()
line
=
f
.
readlines
()[
0
].
rstrip
().
split
()
total
=
sum
(
cpu
)
assert
line
[
0
]
==
'cpu'
yield
'cpu_usage'
,
round
(
float
(
total
-
cpu
.
idle
)
/
total
*
100
,
2
)
numbers
=
map
(
int
,
line
[
1
:])
total
=
sum
(
numbers
)
idle
=
numbers
[
3
]
yield
'cpu_usage'
,
round
(
float
(
total
-
idle
)
/
total
*
100
,
2
)
# Memory usage
# Memory usage
with
open
(
'/proc/meminfo'
,
'r'
)
as
f
:
mem
=
psutil
.
phymem_usage
()
for
line
in
f
:
yield
'memory'
,
(
mem
.
used
,
mem
.
total
)
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
# Disk usage
# Disk usage
for
line
in
check_output
(
'df'
).
split
(
'
\
n
'
):
disk
=
psutil
.
disk_usage
(
'/'
)
parts
=
line
.
split
()
yield
'disk'
,
(
disk
.
used
,
disk
.
total
)
if
parts
[
0
].
startswith
(
'/dev/'
)
and
parts
[
5
]
==
'/'
:
used
,
avail
=
map
(
int
,
parts
[
2
:
4
])
yield
'disk'
,
(
used
,
used
+
avail
)
break
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment