mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
109 lines
2.9 KiB
Python
Executable file
109 lines
2.9 KiB
Python
Executable file
#!/usr/bin/env python
|
|
#
|
|
# Plugin to monitor used size of a tenant in glance
|
|
#
|
|
# To monitor the used size of a tenant in glance do:
|
|
# E.g.
|
|
# ln -s /usr/share/munin/plugins/glance_size_ /etc/munin/plugins/glance_size_<tenant_uuid>
|
|
#
|
|
# Needs following minimal configuration in plugin-conf.d/glance:
|
|
# [glance_*]
|
|
# user glance
|
|
#
|
|
# Magic markers
|
|
#%# capabilities=autoconf suggest
|
|
#%# family=auto
|
|
|
|
|
|
import sys
|
|
import os
|
|
|
|
try:
|
|
from sqlalchemy.orm import exc, joinedload
|
|
|
|
from glance.common.cfg import CommonConfigOpts
|
|
from glance.registry.db import models
|
|
from glance.registry.db.api import get_session, configure_db
|
|
except ImportError:
|
|
succesful_import = False
|
|
else:
|
|
succesful_import = True
|
|
|
|
|
|
def load_conf():
|
|
CONF = CommonConfigOpts(project="glance", prog="glance-registry")
|
|
CONF()
|
|
|
|
# Hide missing logger warning message
|
|
sys.stderr = open(os.devnull, 'w')
|
|
configure_db(CONF)
|
|
sys.stderr = sys.__stderr__
|
|
|
|
|
|
def print_config(tenant):
|
|
print 'graph_title Glance used size for tenant %s' % tenant
|
|
print 'graph_vlabel Bytes'
|
|
print 'graph_args --base 1024 --lower-limit 0'
|
|
print 'graph_category glance'
|
|
print 'graph_info This graph shows the used size in glance for tenant %s' % tenant
|
|
print '%s.label %s' % (tenant, tenant)
|
|
print '%s.draw LINE2' % tenant
|
|
print '%s.info %s MBytes' % (tenant, tenant)
|
|
|
|
def request(**kwargs):
|
|
|
|
session = get_session()
|
|
try:
|
|
query = session.query(models.Image).\
|
|
options(joinedload(models.Image.properties)).\
|
|
options(joinedload(models.Image.members))
|
|
if kwargs:
|
|
query = query.filter_by(**kwargs)
|
|
|
|
images = query.all()
|
|
|
|
except exc.NoResultFound:
|
|
return []
|
|
return images
|
|
|
|
def print_suggest():
|
|
print "Global"
|
|
print "\n".join(set( image["owner"] for image in request(deleted=False) ))
|
|
|
|
def print_values(tenant):
|
|
|
|
if tenant != "Global" :
|
|
images = request(deleted=False, owner=tenant)
|
|
else:
|
|
images = request(deleted=False)
|
|
|
|
total_size = sum([ image["size"] for image in images ])
|
|
print '%s.value %s' % (tenant, total_size)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
argv = sys.argv[:]
|
|
tenant = argv[0].split('glance_size_').pop() or 'Global'
|
|
|
|
if len(argv) > 1:
|
|
if argv[1] == 'config':
|
|
print_config(tenant)
|
|
elif argv[1] == 'suggest' and succesful_import:
|
|
load_conf()
|
|
print_suggest()
|
|
elif argv[1] == 'autoconf':
|
|
if not succesful_import:
|
|
print 'no (failed import glance and/or sqlachemy module)'
|
|
sys.exit(0)
|
|
try:
|
|
load_conf()
|
|
get_session()
|
|
except:
|
|
print 'no (failed to connect glance backend, check user)'
|
|
sys.exit(0)
|
|
print 'yes'
|
|
|
|
elif succesful_import:
|
|
load_conf()
|
|
print_values(tenant)
|
|
|