Projet

Général

Profil

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

root / plugins / nova / nova_instance_timing @ 22fbe167

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

1
#!/usr/bin/env python
2
#
3
# Plugin to monitor trending of launch/schedule times for last 5 successful instances
4
#
5
# To monitor a floating ips, link floating_ips to this file.
6
# E.g.
7
#    ln -s /usr/share/munin/plugins/nova_instance_timing /etc/munin/plugins/
8
#
9
# Needs following minimal configuration in plugin-conf.d/nova:
10
#   [nova_*]
11
#   user nova
12
#
13
# Magic markers
14
#%# capabilities=autoconf
15
#%# family=nova
16

    
17
from nova import context
18
from nova import db
19
from nova import flags
20
from nova import utils
21
from nova.db.sqlalchemy.session import get_session
22
import sys
23

    
24

    
25
def print_config():
26
    global states
27
    print 'graph_title Nova Launch Times'
28
    print 'graph_vlabel seconds'
29
    print 'graph_args --base 1000 --lower-limit 0'
30
    print 'graph_category nova'
31
    print 'graph_scale no'
32
    print 'graph_info This the average time for the last 5 schedulings/launchings'
33
    print 'schedule.label schedule time'
34
    print 'schedule.draw LINE2'
35
    print 'schedule.info average time for last 5 instance to be scheduled'
36
    print 'launch.label launch time'
37
    print 'launch.draw LINE2'
38
    print 'launch.info average time for last 5 instance to be launched after scheduling'
39

    
40

    
41
def get_status():
42
    connection = get_session().connection()
43
    row = connection.execute("select AVG(TIME_TO_SEC(TIMEDIFF(scheduled_at, created_at))) from instances where scheduled_at is not null order by scheduled_at desc limit 5;").fetchall()[0]
44
    schedule = row[0]
45
    row = connection.execute("select AVG(TIME_TO_SEC(TIMEDIFF(launched_at, scheduled_at))) from instances where launched_at is not null order by launched_at desc limit 5;").fetchall()[0]
46
    launch = row[0]
47
    return (schedule, launch)
48

    
49

    
50
def print_values():
51
    schedule, launch = get_status()
52
    print "schedule.value %s" % schedule
53
    print "launch.value %s" % launch
54

    
55

    
56
if __name__ == '__main__':
57
    if len(sys.argv) > 1:
58
        if sys.argv[1] == "config":
59
            print_config()
60
        elif sys.argv[1] == "autoconf":
61
            print "yes"
62
    else:
63
        utils.default_flagfile()
64
        flags.FLAGS(sys.argv)
65
        print_values()