| 1 |
# This module allows you to collect available entropy on your system. Why is |
| 2 |
# entropy important. |
| 3 |
# [http://www.chrissearle.org/node/326] |
| 4 |
# There are two random number sources on linux - /dev/random and /dev/urandom. |
| 5 |
# /dev/random will block if there is nothing left in the entropy bit bucket. |
| 6 |
# /dev/urandom uses the same bucket - but will not block |
| 7 |
# (it can reuse the pool of bits). |
| 8 |
# Therefore if you are running SSL on the box you want to know this. |
| 9 |
|
| 10 |
import sys |
| 11 |
|
| 12 |
|
| 13 |
entropy_file = "/proc/sys/kernel/random/entropy_avail" |
| 14 |
|
| 15 |
|
| 16 |
def metrics_handler(name): |
| 17 |
try: |
| 18 |
f = open(entropy_file, 'r') |
| 19 |
|
| 20 |
except IOError: |
| 21 |
return 0 |
| 22 |
|
| 23 |
for l in f: |
| 24 |
line = l |
| 25 |
|
| 26 |
return int(line) |
| 27 |
|
| 28 |
|
| 29 |
def metric_init(params): |
| 30 |
global descriptors, node_id |
| 31 |
|
| 32 |
dict = {'name': 'entropy_avail', |
| 33 |
'call_back': metrics_handler, |
| 34 |
'time_max': 90, |
| 35 |
'value_type': 'uint', |
| 36 |
'units': 'bits', |
| 37 |
'slope': 'both', |
| 38 |
'format': '%u', |
| 39 |
'description': 'Entropy Available', |
| 40 |
'groups': 'ssl'} |
| 41 |
|
| 42 |
descriptors = [dict] |
| 43 |
|
| 44 |
return descriptors |
| 45 |
|
| 46 |
|
| 47 |
def metric_cleanup(): |
| 48 |
'''Clean up the metric module.''' |
| 49 |
pass |
| 50 |
|
| 51 |
#This code is for debugging and unit testing |
| 52 |
if __name__ == '__main__': |
| 53 |
metric_init({}) |
| 54 |
for d in descriptors: |
| 55 |
v = d['call_back'](d['name']) |
| 56 |
print 'value for %s is %u' % (d['name'], v) |