2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

Add autoconf and enhance graphs

This commit is contained in:
Mehdi Abaakouk 2012-05-03 16:48:19 +02:00
parent 4a18b06213
commit 33cff547e9
6 changed files with 144 additions and 56 deletions

View File

@ -8,14 +8,21 @@
# #
# Magic markers # Magic markers
#%# capabilities=autoconf #%# capabilities=autoconf
#%# family=keystone #%# family=auto
import sys import sys
import traceback
try:
from keystone.common import utils
from keystone import config
from keystone import exception
from keystone import identity
except ImportError:
succesful_import = False
else:
succesful_import = True
from keystone.common import utils
from keystone import config
from keystone import exception
from keystone import identity
CONF = config.CONF CONF = config.CONF
@ -78,14 +85,26 @@ def print_values():
for (field, value) in stats[state].iteritems(): for (field, value) in stats[state].iteritems():
print "%s_%s.value %s" % (field, state, value) print "%s_%s.value %s" % (field, state, value)
def load_conf():
CONF(config_files=[utils.find_config('keystone.conf')])
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) > 1: if len(sys.argv) > 1:
if sys.argv[1] == "config": if sys.argv[1] == "config":
print_config() print_config()
elif sys.argv[1] == "autoconf": elif sys.argv[1] == "autoconf":
print "yes" if not succesful_import:
else: print 'no (failed import keystone module)'
CONF(config_files=[utils.find_config('keystone.conf')]) sys.exit(0)
try:
load_conf()
identity.Manager()
except:
print 'no (failed to connect keystone backend: %s'%traceback.format_exc()
sys.exit(0)
print 'yes'
elif succesful_import:
load_conf()
print_values() print_values()

View File

@ -12,21 +12,28 @@
# #
# Magic markers # Magic markers
#%# capabilities=autoconf #%# capabilities=autoconf
#%# family=nova #%# family=auto
from nova import context
from nova import db
from nova import flags
from nova import utils
import sys import sys
states = ['total', 'allocated', 'associated'] try:
from nova import context
from nova import db
from nova import flags
from nova import utils
except ImportError:
succesful_import = False
else:
succesful_import = True
states = ['total', 'allocated', 'associated']
def print_config(): def print_config():
global states global states
print 'graph_title Nova Floating IPs' print 'graph_title Nova Floating IPs'
print 'graph_vlabel %' print 'graph_vlabel IPs'
print 'graph_args --base 1000 --lower-limit 0' print 'graph_args --base 1000 --lower-limit 0'
print 'graph_category nova' print 'graph_category nova'
print 'graph_scale no' print 'graph_scale no'
@ -65,8 +72,12 @@ if __name__ == '__main__':
if sys.argv[1] == "config": if sys.argv[1] == "config":
print_config() print_config()
elif sys.argv[1] == "autoconf": elif sys.argv[1] == "autoconf":
print "yes" if not succesful_import:
print 'no (failed import nova module)'
sys.exit(0)
else: else:
print 'yes'
elif succesful_import:
utils.default_flagfile() utils.default_flagfile()
flags.FLAGS(sys.argv) flags.FLAGS(sys.argv)
print_values() print_values()

View File

@ -11,15 +11,22 @@
# user nova # user nova
# #
# Magic markers # Magic markers
#%# capabilities=autoconf #%# capabilities=autoconf suggest
#%# family=nova #%# family=auto
from nova import context
from nova import db
from nova import flags
from nova import utils
import sys import sys
try:
from nova import context
from nova import db
from nova import flags
from nova import utils
from nova.compute import power_state
except ImportError:
succesful_import = False
else:
succesful_import = True
class InstanceState(object): class InstanceState(object):
instance_counts = None instance_counts = None
@ -33,12 +40,9 @@ class InstanceState(object):
instances = db.instance_get_all(ctxt) instances = db.instance_get_all(ctxt)
cls.instance_counts = {} cls.instance_counts = {}
instance_types = {} instance_types = {}
for it in db.instance_type_get_all(ctxt, True).values(): for it in db.instance_type_get_all(ctxt, True):
instance_types[it['id']] = it['name'] instance_types[it['id']] = it['name']
if metric == 'state':
metric = 'state_description'
for instance in instances: for instance in instances:
i = dict(instance) i = dict(instance)
i['instance_type'] = i['type'] = instance_types.get( i['instance_type'] = i['type'] = instance_types.get(
@ -58,17 +62,24 @@ class InstanceState(object):
InstanceState.init(metric) InstanceState.init(metric)
return cls.instance_counts return cls.instance_counts
def get_name(metric, code):
if metric == "power_state":
return power_state.name(code)
elif metric in ["root_gb", "ephemeral_gb"]:
return "%d_gb", code
else:
return code
def print_config(metric): def print_config(metric):
states = InstanceState.get_states(metric) states = InstanceState.get_states(metric)
print 'graph_title Nova Instance States' print 'graph_title Nova Instance %s' % metric
print 'graph_vlabel instances' print 'graph_vlabel instances'
print 'graph_args --base 1000 --lower-limit 0' print 'graph_args --base 1000 --lower-limit 0'
print 'graph_category nova' print 'graph_category nova'
print 'graph_scale no' print 'graph_scale no'
print 'graph_info This graph shows the number of instances by state' print 'graph_info This graph shows the number of instances by %s' % metric
for state in states: for state in states:
print '%s.label %s' % (state, state) print '%s.label %s' % (state, get_name(state))
print '%s.draw LINE2' % state print '%s.draw LINE2' % state
print '%s.info %s IPs' % (state, state) print '%s.info %s IPs' % (state, state)
@ -78,17 +89,35 @@ def print_values(metric):
for (state, value) in status.iteritems(): for (state, value) in status.iteritems():
print '%s.value %s' % (state, value) print '%s.value %s' % (state, value)
def print_suggest():
suggest = [ "vm_state",
"vcpus",
"task_state",
"root_gb",
"ephemeral_gb",
"power_state",
"memory_mb",
"instance_type_id",
]
print "\n".join(suggest)
if __name__ == '__main__': if __name__ == '__main__':
argv = sys.argv[:] argv = sys.argv[:]
utils.default_flagfile() utils.default_flagfile()
flags.FLAGS(sys.argv) flags.FLAGS(sys.argv)
metric = argv[0].split('nova_instance_').pop() or 'state' metric = argv[0].split('nova_instance_').pop() or 'vm_state'
if len(argv) > 1: if len(argv) > 1:
if argv[1] == 'config': if argv[1] == 'config':
print_config(metric) print_config(metric)
elif argv[1] == 'suggest':
print_suggest()
elif argv[1] == 'autoconf': elif argv[1] == 'autoconf':
print 'yes' if not succesful_import:
print 'no (failed import nova module)'
sys.exit(0)
else: else:
print 'yes'
elif succesful_import:
print_values(metric) print_values(metric)

View File

@ -12,15 +12,21 @@
# #
# Magic markers # Magic markers
#%# capabilities=autoconf #%# capabilities=autoconf
#%# family=nova #%# family=auto
from nova import context
from nova import db
from nova import flags
from nova import utils
from nova.db.sqlalchemy.session import get_session
import sys import sys
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:
succesful_import = False
else:
succesful_import = True
def print_config(): def print_config():
global states global states
print 'graph_title Nova Instances Launched' print 'graph_title Nova Instances Launched'
@ -46,8 +52,12 @@ if __name__ == '__main__':
if sys.argv[1] == "config": if sys.argv[1] == "config":
print_config() print_config()
elif sys.argv[1]=="autoconf" : elif sys.argv[1]=="autoconf" :
print "yes" if not succesful_import:
print 'no (failed import nova module)'
sys.exit(0)
else: else:
print 'yes'
elif succesful_import:
utils.default_flagfile() utils.default_flagfile()
flags.FLAGS(sys.argv) flags.FLAGS(sys.argv)
print_values() print_values()

View File

@ -12,15 +12,21 @@
# #
# Magic markers # Magic markers
#%# capabilities=autoconf #%# capabilities=autoconf
#%# family=nova #%# family=auto
from nova import context
from nova import db
from nova import flags
from nova import utils
from nova.db.sqlalchemy.session import get_session
import sys import sys
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:
succesful_import = False
else:
succesful_import = True
def print_config(): def print_config():
global states global states
@ -58,8 +64,12 @@ if __name__ == '__main__':
if sys.argv[1] == "config": if sys.argv[1] == "config":
print_config() print_config()
elif sys.argv[1] == "autoconf": elif sys.argv[1] == "autoconf":
print "yes" if not succesful_import:
print 'no (failed import nova module)'
sys.exit(0)
else: else:
print 'yes'
elif succesful_import:
utils.default_flagfile() utils.default_flagfile()
flags.FLAGS(sys.argv) flags.FLAGS(sys.argv)
print_values() print_values()

View File

@ -8,14 +8,20 @@
# #
# Magic markers # Magic markers
#%# capabilities=autoconf #%# capabilities=autoconf
#%# family=nova #%# family=auto
from nova import context
from nova import db
from nova import flags
from nova import utils
import sys import sys
try:
from nova import context
from nova import db
from nova import flags
from nova import utils
except ImportError:
succesful_import = False
else:
succesful_import = True
services = ['nova-compute', 'nova-volume', 'nova-scheduler', 'nova-vncproxy', 'nova-network', 'nova-cert', 'nova-console', 'nova-consoleauth'] services = ['nova-compute', 'nova-volume', 'nova-scheduler', 'nova-vncproxy', 'nova-network', 'nova-cert', 'nova-console', 'nova-consoleauth']
@ -70,8 +76,11 @@ if __name__ == '__main__':
if sys.argv[1] == "config": if sys.argv[1] == "config":
print_config() print_config()
elif sys.argv[1] == "autoconf": elif sys.argv[1] == "autoconf":
print "yes" if not succesful_import:
print 'no (failed import nova module]'
else: else:
print 'yes'
elif succesful_import:
utils.default_flagfile() utils.default_flagfile()
flags.FLAGS(sys.argv) flags.FLAGS(sys.argv)
print_values() print_values()