Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / nova / nova_services @ 22fbe167

Historique | Voir | Annoter | Télécharger (2,12 ko)

1
#!/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
#%# family=nova
12

    
13
from nova import context
14
from nova import db
15
from nova import flags
16
from nova import utils
17
import sys
18

    
19
services = ['nova-compute', 'nova-volume', 'nova-scheduler', 'nova-vncproxy', 'nova-network', 'nova-cert', 'nova-console', 'nova-consoleauth']
20

    
21

    
22
def print_config():
23
    global services
24
    print 'graph_title Nova Services'
25
    print 'graph_vlabel qty'
26
    print 'graph_args --base 1000 --lower-limit 0'
27
    print 'graph_category nova'
28
    print 'graph_scale no'
29
    print 'graph_info Nova services - alive and active'
30
    for service in services:
31
        print '%s_alive.label %s alive' % (service, service)
32
        print '%s_alive.draw LINE2' % service
33
        print '%s_alive.info seen in last 30 seconds' % service
34
        print '%s_active.label %s active' % (service, service)
35
        print '%s_active.draw LINE2' % service
36
        print '%s_active.info alive and enabled' % service
37

    
38

    
39
def get_status():
40
    global services
41
    alive = {}
42
    active = {}
43
    for k in services:
44
        alive[k] = 0
45
        active[k] = 0
46

    
47
    ctxt = context.get_admin_context()
48
    now = utils.utcnow()
49
    services = db.service_get_all(ctxt)
50
    for svc in services:
51
        delta = now - (svc['updated_at'] or svc['created_at'])
52
        if (delta.seconds <= 30):
53
            alive[svc['binary']] += 1
54
            if not svc['disabled']:
55
                active[svc['binary']] += 1
56

    
57
    return {'alive': alive, 'active': active}
58

    
59

    
60
def print_values():
61
    status = get_status()
62
    for (state, value) in status['alive'].iteritems():
63
        print "%s_alive.value %s" % (state, value)
64
    for (state, value) in status['active'].iteritems():
65
        print "%s_active.value %s" % (state, value)
66

    
67

    
68
if __name__ == '__main__':
69
    if len(sys.argv) > 1:
70
        if sys.argv[1] == "config":
71
            print_config()
72
        elif sys.argv[1] == "autoconf":
73
            print "yes"
74
    else:
75
        utils.default_flagfile()
76
        flags.FLAGS(sys.argv)
77
        print_values()