2012-05-02 08:34:55 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Plugin to monitor instances launched from beginning of time
|
|
|
|
#
|
|
|
|
# To monitor a floating ips, link floating_ips to this file.
|
|
|
|
# E.g.
|
|
|
|
# ln -s /usr/share/munin/plugins/nova_instance_launched /etc/munin/plugins/
|
|
|
|
#
|
|
|
|
# Needs following minimal configuration in plugin-conf.d/nova:
|
|
|
|
# [nova_*]
|
|
|
|
# user nova
|
|
|
|
#
|
|
|
|
# Magic markers
|
|
|
|
#%# capabilities=autoconf
|
2012-05-03 16:48:19 +02:00
|
|
|
#%# family=auto
|
2012-05-02 08:34:55 +02:00
|
|
|
|
|
|
|
import sys
|
|
|
|
|
2012-05-03 16:48:19 +02:00
|
|
|
try:
|
|
|
|
from nova import context
|
|
|
|
from nova import db
|
|
|
|
from nova import flags
|
|
|
|
from nova import utils
|
|
|
|
from nova.db.sqlalchemy.session import get_session
|
|
|
|
except ImportError:
|
2014-12-05 00:37:42 +01:00
|
|
|
successful_import = False
|
2012-05-03 16:48:19 +02:00
|
|
|
else:
|
2014-12-05 00:37:42 +01:00
|
|
|
successful_import = True
|
2012-05-03 16:48:19 +02:00
|
|
|
|
2012-05-02 08:34:55 +02:00
|
|
|
def print_config():
|
|
|
|
global states
|
|
|
|
print 'graph_title Nova Instances Launched'
|
|
|
|
print 'graph_vlabel qty'
|
|
|
|
print 'graph_args --base 1000 --lower-limit 0'
|
2017-02-23 00:15:13 +01:00
|
|
|
print 'graph_category cloud'
|
2012-05-02 08:34:55 +02:00
|
|
|
print 'graph_scale no'
|
|
|
|
print 'graph_info This graph shows the number of instances launched since the beginning of time'
|
|
|
|
print 'instances.label instances'
|
|
|
|
print 'instances.draw LINE2'
|
|
|
|
|
|
|
|
def get_status():
|
|
|
|
connection = get_session().connection()
|
|
|
|
row = connection.execute("select count(*) from instances").fetchall()[0]
|
|
|
|
return row[0]
|
|
|
|
|
|
|
|
def print_values():
|
|
|
|
qty = get_status()
|
|
|
|
print "instances.value %s" % qty
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
if sys.argv[1] == "config":
|
|
|
|
print_config()
|
|
|
|
elif sys.argv[1]=="autoconf" :
|
2014-12-05 00:37:42 +01:00
|
|
|
if not successful_import:
|
2012-05-03 16:48:19 +02:00
|
|
|
print 'no (failed import nova module)'
|
|
|
|
sys.exit(0)
|
|
|
|
else:
|
|
|
|
print 'yes'
|
2014-12-05 00:37:42 +01:00
|
|
|
elif successful_import:
|
2012-05-02 08:34:55 +02:00
|
|
|
utils.default_flagfile()
|
|
|
|
flags.FLAGS(sys.argv)
|
|
|
|
print_values()
|