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
#%# capabilities=autoconf
#%# family=keystone
#%# family=auto
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
CONF = config.CONF
@ -78,14 +85,26 @@ def print_values():
for (field, value) in stats[state].iteritems():
print "%s_%s.value %s" % (field, state, value)
def load_conf():
CONF(config_files=[utils.find_config('keystone.conf')])
if __name__ == '__main__':
if len(sys.argv) > 1:
if sys.argv[1] == "config":
print_config()
elif sys.argv[1] == "autoconf":
print "yes"
else:
CONF(config_files=[utils.find_config('keystone.conf')])
if not succesful_import:
print 'no (failed import keystone module)'
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()

View File

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

View File

@ -11,14 +11,21 @@
# user nova
#
# Magic markers
#%# capabilities=autoconf
#%# family=nova
#%# capabilities=autoconf suggest
#%# family=auto
import sys
try:
from nova import context
from nova import db
from nova import flags
from nova import utils
import sys
from nova.compute import power_state
except ImportError:
succesful_import = False
else:
succesful_import = True
class InstanceState(object):
@ -33,12 +40,9 @@ class InstanceState(object):
instances = db.instance_get_all(ctxt)
cls.instance_counts = {}
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']
if metric == 'state':
metric = 'state_description'
for instance in instances:
i = dict(instance)
i['instance_type'] = i['type'] = instance_types.get(
@ -58,17 +62,24 @@ class InstanceState(object):
InstanceState.init(metric)
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):
states = InstanceState.get_states(metric)
print 'graph_title Nova Instance States'
print 'graph_title Nova Instance %s' % metric
print 'graph_vlabel instances'
print 'graph_args --base 1000 --lower-limit 0'
print 'graph_category nova'
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:
print '%s.label %s' % (state, state)
print '%s.label %s' % (state, get_name(state))
print '%s.draw LINE2' % state
print '%s.info %s IPs' % (state, state)
@ -78,17 +89,35 @@ def print_values(metric):
for (state, value) in status.iteritems():
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__':
argv = sys.argv[:]
utils.default_flagfile()
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 argv[1] == 'config':
print_config(metric)
elif argv[1] == 'suggest':
print_suggest()
elif argv[1] == 'autoconf':
print 'yes'
if not succesful_import:
print 'no (failed import nova module)'
sys.exit(0)
else:
print 'yes'
elif succesful_import:
print_values(metric)

View File

@ -12,14 +12,20 @@
#
# Magic markers
#%# capabilities=autoconf
#%# family=nova
#%# family=auto
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
import sys
except ImportError:
succesful_import = False
else:
succesful_import = True
def print_config():
global states
@ -46,8 +52,12 @@ if __name__ == '__main__':
if sys.argv[1] == "config":
print_config()
elif sys.argv[1]=="autoconf" :
print "yes"
if not succesful_import:
print 'no (failed import nova module)'
sys.exit(0)
else:
print 'yes'
elif succesful_import:
utils.default_flagfile()
flags.FLAGS(sys.argv)
print_values()

View File

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

View File

@ -8,13 +8,19 @@
#
# Magic markers
#%# capabilities=autoconf
#%# family=nova
#%# family=auto
import sys
try:
from nova import context
from nova import db
from nova import flags
from nova import utils
import sys
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']
@ -70,8 +76,11 @@ if __name__ == '__main__':
if sys.argv[1] == "config":
print_config()
elif sys.argv[1] == "autoconf":
print "yes"
if not succesful_import:
print 'no (failed import nova module]'
else:
print 'yes'
elif succesful_import:
utils.default_flagfile()
flags.FLAGS(sys.argv)
print_values()