root / plugins / nova / nova_services @ 17f78427
Historique | Voir | Annoter | Télécharger (2,35 ko)
| 1 | 22fbe167 | Mehdi Abaakouk | #!/usr/bin/env python |
|---|---|---|---|
| 2 | # |
||
| 3 | # Plugin to report service status |
||
| 4 | # |
||
| 5 | # Needs following minimal configuration in plugin-conf.d/nova: |
||
| 6 | # [nova_*] |
||
| 7 | # user nova |
||
| 8 | # |
||
| 9 | # Magic markers |
||
| 10 | #%# capabilities=autoconf |
||
| 11 | 33cff547 | Mehdi Abaakouk | #%# family=auto |
| 12 | 22fbe167 | Mehdi Abaakouk | |
| 13 | import sys |
||
| 14 | |||
| 15 | 33cff547 | Mehdi Abaakouk | try: |
| 16 | from nova import context |
||
| 17 | from nova import db |
||
| 18 | from nova import flags |
||
| 19 | from nova import utils |
||
| 20 | except ImportError: |
||
| 21 | fba800ae | Veres Lajos | successful_import = False |
| 22 | 33cff547 | Mehdi Abaakouk | else: |
| 23 | fba800ae | Veres Lajos | successful_import = True |
| 24 | 33cff547 | Mehdi Abaakouk | |
| 25 | 22fbe167 | Mehdi Abaakouk | services = ['nova-compute', 'nova-volume', 'nova-scheduler', 'nova-vncproxy', 'nova-network', 'nova-cert', 'nova-console', 'nova-consoleauth'] |
| 26 | |||
| 27 | |||
| 28 | def print_config(): |
||
| 29 | global services |
||
| 30 | print 'graph_title Nova Services' |
||
| 31 | print 'graph_vlabel qty' |
||
| 32 | print 'graph_args --base 1000 --lower-limit 0' |
||
| 33 | f41b6861 | dipohl | print 'graph_category cloud' |
| 34 | 22fbe167 | Mehdi Abaakouk | print 'graph_scale no' |
| 35 | print 'graph_info Nova services - alive and active' |
||
| 36 | for service in services: |
||
| 37 | print '%s_alive.label %s alive' % (service, service) |
||
| 38 | print '%s_alive.draw LINE2' % service |
||
| 39 | print '%s_alive.info seen in last 30 seconds' % service |
||
| 40 | print '%s_active.label %s active' % (service, service) |
||
| 41 | print '%s_active.draw LINE2' % service |
||
| 42 | print '%s_active.info alive and enabled' % service |
||
| 43 | |||
| 44 | |||
| 45 | def get_status(): |
||
| 46 | global services |
||
| 47 | alive = {}
|
||
| 48 | active = {}
|
||
| 49 | for k in services: |
||
| 50 | alive[k] = 0 |
||
| 51 | active[k] = 0 |
||
| 52 | |||
| 53 | ctxt = context.get_admin_context() |
||
| 54 | now = utils.utcnow() |
||
| 55 | services = db.service_get_all(ctxt) |
||
| 56 | for svc in services: |
||
| 57 | delta = now - (svc['updated_at'] or svc['created_at']) |
||
| 58 | if (delta.seconds <= 30): |
||
| 59 | alive[svc['binary']] += 1 |
||
| 60 | if not svc['disabled']: |
||
| 61 | active[svc['binary']] += 1 |
||
| 62 | |||
| 63 | return {'alive': alive, 'active': active}
|
||
| 64 | |||
| 65 | |||
| 66 | def print_values(): |
||
| 67 | status = get_status() |
||
| 68 | for (state, value) in status['alive'].iteritems(): |
||
| 69 | print "%s_alive.value %s" % (state, value) |
||
| 70 | for (state, value) in status['active'].iteritems(): |
||
| 71 | print "%s_active.value %s" % (state, value) |
||
| 72 | |||
| 73 | |||
| 74 | if __name__ == '__main__': |
||
| 75 | if len(sys.argv) > 1: |
||
| 76 | if sys.argv[1] == "config": |
||
| 77 | print_config() |
||
| 78 | elif sys.argv[1] == "autoconf": |
||
| 79 | 17f78427 | Lars Kruse | if not successful_import: |
| 80 | 33cff547 | Mehdi Abaakouk | print 'no (failed import nova module]' |
| 81 | else: |
||
| 82 | print 'yes' |
||
| 83 | fba800ae | Veres Lajos | elif successful_import: |
| 84 | 22fbe167 | Mehdi Abaakouk | utils.default_flagfile() |
| 85 | flags.FLAGS(sys.argv) |
||
| 86 | print_values() |
