root / plugins / nova / nova_instance_launched @ 17f78427
Historique | Voir | Annoter | Télécharger (1,69 ko)
| 1 | 22fbe167 | Mehdi Abaakouk | #!/usr/bin/env python |
|---|---|---|---|
| 2 | # |
||
| 3 | # Plugin to monitor instances launched from beginning of time |
||
| 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_launched /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 | fba800ae | Veres Lajos | successful_import = False |
| 27 | 33cff547 | Mehdi Abaakouk | else: |
| 28 | fba800ae | Veres Lajos | successful_import = True |
| 29 | 33cff547 | Mehdi Abaakouk | |
| 30 | 22fbe167 | Mehdi Abaakouk | def print_config(): |
| 31 | global states |
||
| 32 | print 'graph_title Nova Instances Launched' |
||
| 33 | print 'graph_vlabel qty' |
||
| 34 | print 'graph_args --base 1000 --lower-limit 0' |
||
| 35 | f41b6861 | dipohl | print 'graph_category cloud' |
| 36 | 22fbe167 | Mehdi Abaakouk | print 'graph_scale no' |
| 37 | print 'graph_info This graph shows the number of instances launched since the beginning of time' |
||
| 38 | print 'instances.label instances' |
||
| 39 | print 'instances.draw LINE2' |
||
| 40 | |||
| 41 | def get_status(): |
||
| 42 | connection = get_session().connection() |
||
| 43 | row = connection.execute("select count(*) from instances").fetchall()[0]
|
||
| 44 | return row[0] |
||
| 45 | |||
| 46 | def print_values(): |
||
| 47 | qty = get_status() |
||
| 48 | print "instances.value %s" % qty |
||
| 49 | |||
| 50 | if __name__ == '__main__': |
||
| 51 | if len(sys.argv) > 1: |
||
| 52 | if sys.argv[1] == "config": |
||
| 53 | print_config() |
||
| 54 | elif sys.argv[1]=="autoconf" : |
||
| 55 | 17f78427 | Lars Kruse | if not successful_import: |
| 56 | 33cff547 | Mehdi Abaakouk | print 'no (failed import nova module)' |
| 57 | sys.exit(0) |
||
| 58 | else: |
||
| 59 | print 'yes' |
||
| 60 | fba800ae | Veres Lajos | elif successful_import: |
| 61 | 22fbe167 | Mehdi Abaakouk | utils.default_flagfile() |
| 62 | 17f78427 | Lars Kruse | flags.FLAGS(sys.argv) |
| 63 | 22fbe167 | Mehdi Abaakouk | print_values() |
