Révision 33cff547
Add autoconf and enhance graphs
| plugins/nova/nova_instance_ | ||
|---|---|---|
| 11 | 11 |
# user nova |
| 12 | 12 |
# |
| 13 | 13 |
# Magic markers |
| 14 |
#%# capabilities=autoconf |
|
| 15 |
#%# family=nova
|
|
| 14 |
#%# capabilities=autoconf suggest
|
|
| 15 |
#%# family=auto
|
|
| 16 | 16 |
|
| 17 |
from nova import context |
|
| 18 |
from nova import db |
|
| 19 |
from nova import flags |
|
| 20 |
from nova import utils |
|
| 21 | 17 |
import sys |
| 22 | 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.compute import power_state |
|
| 25 |
except ImportError: |
|
| 26 |
succesful_import = False |
|
| 27 |
else: |
|
| 28 |
succesful_import = True |
|
| 29 |
|
|
| 23 | 30 |
|
| 24 | 31 |
class InstanceState(object): |
| 25 | 32 |
instance_counts = None |
| ... | ... | |
| 33 | 40 |
instances = db.instance_get_all(ctxt) |
| 34 | 41 |
cls.instance_counts = {}
|
| 35 | 42 |
instance_types = {}
|
| 36 |
for it in db.instance_type_get_all(ctxt, True).values():
|
|
| 43 |
for it in db.instance_type_get_all(ctxt, True): |
|
| 37 | 44 |
instance_types[it['id']] = it['name'] |
| 38 | 45 |
|
| 39 |
if metric == 'state': |
|
| 40 |
metric = 'state_description' |
|
| 41 |
|
|
| 42 | 46 |
for instance in instances: |
| 43 | 47 |
i = dict(instance) |
| 44 | 48 |
i['instance_type'] = i['type'] = instance_types.get( |
| ... | ... | |
| 58 | 62 |
InstanceState.init(metric) |
| 59 | 63 |
return cls.instance_counts |
| 60 | 64 |
|
| 65 |
def get_name(metric, code): |
|
| 66 |
if metric == "power_state": |
|
| 67 |
return power_state.name(code) |
|
| 68 |
elif metric in ["root_gb", "ephemeral_gb"]: |
|
| 69 |
return "%d_gb", code |
|
| 70 |
else: |
|
| 71 |
return code |
|
| 61 | 72 |
|
| 62 | 73 |
def print_config(metric): |
| 63 | 74 |
states = InstanceState.get_states(metric) |
| 64 |
print 'graph_title Nova Instance States'
|
|
| 75 |
print 'graph_title Nova Instance %s' % metric
|
|
| 65 | 76 |
print 'graph_vlabel instances' |
| 66 | 77 |
print 'graph_args --base 1000 --lower-limit 0' |
| 67 | 78 |
print 'graph_category nova' |
| 68 | 79 |
print 'graph_scale no' |
| 69 |
print 'graph_info This graph shows the number of instances by state'
|
|
| 80 |
print 'graph_info This graph shows the number of instances by %s' % metric
|
|
| 70 | 81 |
for state in states: |
| 71 |
print '%s.label %s' % (state, state)
|
|
| 82 |
print '%s.label %s' % (state, get_name(state))
|
|
| 72 | 83 |
print '%s.draw LINE2' % state |
| 73 | 84 |
print '%s.info %s IPs' % (state, state) |
| 74 | 85 |
|
| ... | ... | |
| 78 | 89 |
for (state, value) in status.iteritems(): |
| 79 | 90 |
print '%s.value %s' % (state, value) |
| 80 | 91 |
|
| 92 |
def print_suggest(): |
|
| 93 |
suggest = [ "vm_state", |
|
| 94 |
"vcpus", |
|
| 95 |
"task_state", |
|
| 96 |
"root_gb", |
|
| 97 |
"ephemeral_gb", |
|
| 98 |
"power_state", |
|
| 99 |
"memory_mb", |
|
| 100 |
"instance_type_id", |
|
| 101 |
] |
|
| 102 |
print "\n".join(suggest) |
|
| 103 |
|
|
| 81 | 104 |
|
| 82 | 105 |
if __name__ == '__main__': |
| 83 | 106 |
argv = sys.argv[:] |
| 84 | 107 |
utils.default_flagfile() |
| 85 | 108 |
flags.FLAGS(sys.argv) |
| 86 |
metric = argv[0].split('nova_instance_').pop() or 'state'
|
|
| 109 |
metric = argv[0].split('nova_instance_').pop() or 'vm_state'
|
|
| 87 | 110 |
|
| 88 | 111 |
if len(argv) > 1: |
| 89 | 112 |
if argv[1] == 'config': |
| 90 | 113 |
print_config(metric) |
| 114 |
elif argv[1] == 'suggest': |
|
| 115 |
print_suggest() |
|
| 91 | 116 |
elif argv[1] == 'autoconf': |
| 92 |
print 'yes' |
|
| 93 |
else: |
|
| 117 |
if not succesful_import: |
|
| 118 |
print 'no (failed import nova module)' |
|
| 119 |
sys.exit(0) |
|
| 120 |
else: |
|
| 121 |
print 'yes' |
|
| 122 |
elif succesful_import: |
|
| 94 | 123 |
print_values(metric) |
Formats disponibles : Unified diff