Fuel plugin to collect Logging Monitoring and Alerting metrics
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

openstack_glance.py 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/python
  2. # Copyright 2015 Mirantis, Inc.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. # Collectd plugin for getting resource statistics from Glance
  17. import collectd
  18. import collectd_openstack as openstack
  19. PLUGIN_NAME = 'glance'
  20. INTERVAL = openstack.INTERVAL
  21. class GlanceStatsPlugin(openstack.CollectdPlugin):
  22. """ Class to report the statistics on Glance service.
  23. number of image broken down by state
  24. total size of images usable and in error state
  25. """
  26. def __init__(self, *args, **kwargs):
  27. super(GlanceStatsPlugin, self).__init__(*args, **kwargs)
  28. self.plugin = PLUGIN_NAME
  29. self.interval = INTERVAL
  30. self.pagination_limit = 25
  31. def itermetrics(self):
  32. def is_snap(d):
  33. return d.get('properties', {}).get('image_type') == 'snapshot'
  34. def groupby(d):
  35. p = 'public' if d.get('is_public', True) else 'private'
  36. status = d.get('status', 'unknown').lower()
  37. if is_snap(d):
  38. return 'snapshots.%s.%s' % (p, status)
  39. return 'images.%s.%s' % (p, status)
  40. images_details = self.get_objects_details('glance', 'images',
  41. api_version='v1',
  42. params={},
  43. detail=True)
  44. status = self.count_objects_group_by(images_details,
  45. group_by_func=groupby)
  46. for s, nb in status.iteritems():
  47. (name, visibility, status) = s.split('.')
  48. yield {
  49. 'type_instance': name,
  50. 'values': nb,
  51. 'meta': {'visibility': visibility, 'status': status}
  52. }
  53. # sizes
  54. def count_size_bytes(d):
  55. return d.get('size', 0)
  56. def groupby_size(d):
  57. p = 'public' if d.get('is_public', True) else 'private'
  58. status = d.get('status', 'unknown').lower()
  59. if is_snap(d):
  60. return 'snapshots_size.%s.%s' % (p, status)
  61. return 'images_size.%s.%s' % (p, status)
  62. sizes = self.count_objects_group_by(images_details,
  63. group_by_func=groupby_size,
  64. count_func=count_size_bytes)
  65. for s, nb in sizes.iteritems():
  66. (name, visibility, status) = s.split('.')
  67. yield {
  68. 'type_instance': name,
  69. 'values': nb,
  70. 'meta': {'visibility': visibility, 'status': status},
  71. }
  72. plugin = GlanceStatsPlugin(collectd, PLUGIN_NAME)
  73. def config_callback(conf):
  74. plugin.config_callback(conf)
  75. def notification_callback(notification):
  76. plugin.notification_callback(notification)
  77. def read_callback():
  78. plugin.conditional_read_callback()
  79. collectd.register_config(config_callback)
  80. collectd.register_notification(notification_callback)
  81. collectd.register_read(read_callback, INTERVAL)