root / plugins / nova / nova_instance_timing @ 33cff547
Historique | Voir | Annoter | Télécharger (2,31 ko)
| 1 | 22fbe167 | Mehdi Abaakouk | #!/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 | 33cff547 | Mehdi Abaakouk | #%# family=auto |
| 16 | 22fbe167 | Mehdi Abaakouk | |
| 17 | import sys |
||
| 18 | |||
| 19 | 33cff547 | Mehdi Abaakouk | try: |
| 20 | from nova import context |
||
| 21 | from nova import db |
||
| 22 | from nova import flags |
||
| 23 | from nova import utils |
||
| 24 | from nova.db.sqlalchemy.session import get_session |
||
| 25 | except ImportError: |
||
| 26 | succesful_import = False |
||
| 27 | else: |
||
| 28 | succesful_import = True |
||
| 29 | |||
| 30 | 22fbe167 | Mehdi Abaakouk | |
| 31 | def print_config(): |
||
| 32 | global states |
||
| 33 | print 'graph_title Nova Launch Times' |
||
| 34 | print 'graph_vlabel seconds' |
||
| 35 | print 'graph_args --base 1000 --lower-limit 0' |
||
| 36 | print 'graph_category nova' |
||
| 37 | print 'graph_scale no' |
||
| 38 | print 'graph_info This the average time for the last 5 schedulings/launchings' |
||
| 39 | print 'schedule.label schedule time' |
||
| 40 | print 'schedule.draw LINE2' |
||
| 41 | print 'schedule.info average time for last 5 instance to be scheduled' |
||
| 42 | print 'launch.label launch time' |
||
| 43 | print 'launch.draw LINE2' |
||
| 44 | print 'launch.info average time for last 5 instance to be launched after scheduling' |
||
| 45 | |||
| 46 | |||
| 47 | def get_status(): |
||
| 48 | connection = get_session().connection() |
||
| 49 | 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]
|
||
| 50 | schedule = row[0] |
||
| 51 | 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]
|
||
| 52 | launch = row[0] |
||
| 53 | return (schedule, launch) |
||
| 54 | |||
| 55 | |||
| 56 | def print_values(): |
||
| 57 | schedule, launch = get_status() |
||
| 58 | print "schedule.value %s" % schedule |
||
| 59 | print "launch.value %s" % launch |
||
| 60 | |||
| 61 | |||
| 62 | if __name__ == '__main__': |
||
| 63 | if len(sys.argv) > 1: |
||
| 64 | if sys.argv[1] == "config": |
||
| 65 | print_config() |
||
| 66 | elif sys.argv[1] == "autoconf": |
||
| 67 | 33cff547 | Mehdi Abaakouk | if not succesful_import: |
| 68 | print 'no (failed import nova module)' |
||
| 69 | sys.exit(0) |
||
| 70 | else: |
||
| 71 | print 'yes' |
||
| 72 | elif succesful_import: |
||
| 73 | 22fbe167 | Mehdi Abaakouk | utils.default_flagfile() |
| 74 | flags.FLAGS(sys.argv) |
||
| 75 | print_values() |
