root / plugins / nova / nova_instance_launched @ 17f78427
Historique | Voir | Annoter | Télécharger (1,69 ko)
| 1 |
#!/usr/bin/env python |
|---|---|
| 2 |
# |
| 3 |
# Plugin to monitor instances launched from beginning of time |
| 4 |
# |
| 5 |
# To monitor a floating ips, link floating_ips to this file. |
| 6 |
# E.g. |
| 7 |
# ln -s /usr/share/munin/plugins/nova_instance_launched /etc/munin/plugins/ |
| 8 |
# |
| 9 |
# Needs following minimal configuration in plugin-conf.d/nova: |
| 10 |
# [nova_*] |
| 11 |
# user nova |
| 12 |
# |
| 13 |
# Magic markers |
| 14 |
#%# capabilities=autoconf |
| 15 |
#%# family=auto |
| 16 |
|
| 17 |
import sys |
| 18 |
|
| 19 |
try: |
| 20 |
from nova import context |
| 21 |
from nova import db |
| 22 |
from nova import flags |
| 23 |
from nova import utils |
| 24 |
from nova.db.sqlalchemy.session import get_session |
| 25 |
except ImportError: |
| 26 |
successful_import = False |
| 27 |
else: |
| 28 |
successful_import = True |
| 29 |
|
| 30 |
def print_config(): |
| 31 |
global states |
| 32 |
print 'graph_title Nova Instances Launched' |
| 33 |
print 'graph_vlabel qty' |
| 34 |
print 'graph_args --base 1000 --lower-limit 0' |
| 35 |
print 'graph_category cloud' |
| 36 |
print 'graph_scale no' |
| 37 |
print 'graph_info This graph shows the number of instances launched since the beginning of time' |
| 38 |
print 'instances.label instances' |
| 39 |
print 'instances.draw LINE2' |
| 40 |
|
| 41 |
def get_status(): |
| 42 |
connection = get_session().connection() |
| 43 |
row = connection.execute("select count(*) from instances").fetchall()[0]
|
| 44 |
return row[0] |
| 45 |
|
| 46 |
def print_values(): |
| 47 |
qty = get_status() |
| 48 |
print "instances.value %s" % qty |
| 49 |
|
| 50 |
if __name__ == '__main__': |
| 51 |
if len(sys.argv) > 1: |
| 52 |
if sys.argv[1] == "config": |
| 53 |
print_config() |
| 54 |
elif sys.argv[1]=="autoconf" : |
| 55 |
if not successful_import: |
| 56 |
print 'no (failed import nova module)' |
| 57 |
sys.exit(0) |
| 58 |
else: |
| 59 |
print 'yes' |
| 60 |
elif successful_import: |
| 61 |
utils.default_flagfile() |
| 62 |
flags.FLAGS(sys.argv) |
| 63 |
print_values() |
