Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F73009673
leds.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jul 18, 01:28
Size
1 KB
Mime Type
text/x-python
Expires
Sat, Jul 20, 01:28 (2 d)
Engine
blob
Format
Raw Data
Handle
19128932
Attached To
rSCMINICLUSTER SCITAS Mini Cluster
leds.py
View Options
#!/usr/bin/env python2
import
collectd
import
serial
import
subprocess
from
math
import
floor
DEBUG
=
1
PORT
=
'/dev/ttyS0'
SPEED
=
9600
CORES
=
int
(
subprocess
.
check_output
(
'nproc'
))
LEDS_NUMBER
=
8
# number of leds in a column
LEDS_MAX
=
100
LEDS_COLOR
=
'
%d
0 0 '
LEDS_NOCOL
=
'0 0 0 '
hosts
=
set
()
def
debug
(
msg
):
if
DEBUG
:
f
=
open
(
'/tmp/debug'
,
'a+'
)
f
.
write
(
str
(
msg
)
+
"
\n
"
)
f
.
close
()
def
write
(
vl
,
data
=
None
):
global
hosts
line
=
''
hosts
.
add
(
vl
.
host
)
index
=
list
(
hosts
)
.
index
(
vl
.
host
)
if
vl
.
type
==
'if_octets'
:
pass
if
vl
.
type
==
'load'
:
debug
(
vl
.
values
)
load1
=
vl
.
values
[
0
]
load1
=
load1
if
load1
<=
CORES
else
CORES
LEDS_ON
=
LEDS_NUMBER
/
CORES
*
load1
LEDS_TR
=
0
if
LEDS_ON
==
0
else
LEDS_ON
-
int
(
LEDS_ON
)
LEDS_OFF
=
LEDS_NUMBER
-
LEDS_ON
line
=
"L
%d
%s
"
%
\
(
index
,
LEDS_COLOR
%
(
LEDS_MAX
)
*
int
(
floor
(
LEDS_ON
))
\
+
LEDS_COLOR
%
(
LEDS_MAX
*
LEDS_TR
)
\
+
LEDS_NOCOL
*
int
(
floor
(
LEDS_OFF
)))
debug
(
line
.
strip
())
if
line
!=
''
:
ser
=
serial
.
Serial
(
PORT
,
SPEED
)
ser
.
write
(
line
.
strip
()
+
"
\n
"
)
ser
.
close
()
collectd
.
register_write
(
write
);
Event Timeline
Log In to Comment