summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ceilometer/hardware/discovery.py21
-rw-r--r--ceilometer/nova_client.py10
2 files changed, 26 insertions, 5 deletions
diff --git a/ceilometer/hardware/discovery.py b/ceilometer/hardware/discovery.py
index 75868914..e9a44473 100644
--- a/ceilometer/hardware/discovery.py
+++ b/ceilometer/hardware/discovery.py
@@ -14,6 +14,7 @@
from oslo_config import cfg
from oslo_log import log
+from oslo_utils import timeutils
from ceilometer.agent import plugin_base
from ceilometer.i18n import _
@@ -41,17 +42,31 @@ class NodesDiscoveryTripleO(plugin_base.DiscoveryBase):
def __init__(self):
super(NodesDiscoveryTripleO, self).__init__()
self.nova_cli = nova_client.Client()
+ self.last_run = None
+ self.instances = {}
@staticmethod
def _address(instance, field):
return instance.addresses['ctlplane'][0].get(field)
def discover(self, manager, param=None):
- """Discover resources to monitor."""
+ """Discover resources to monitor.
- instances = self.nova_cli.instance_get_all()
- resources = []
+ instance_get_all will return all instances if last_run is None,
+ and will return only the instances changed since the last_run time.
+ """
+
+ instances = self.nova_cli.instance_get_all(self.last_run)
for instance in instances:
+ if getattr(instance, 'OS-EXT-STS:vm_state', None) in ['deleted',
+ 'error']:
+ self.instances.pop(instance.id, None)
+ else:
+ self.instances[instance.id] = instance
+ self.last_run = timeutils.utcnow(True).isoformat()
+
+ resources = []
+ for instance in self.instances.values():
try:
ip_address = self._address(instance, 'addr')
final_address = (
diff --git a/ceilometer/nova_client.py b/ceilometer/nova_client.py
index 832499bd..084c4ea5 100644
--- a/ceilometer/nova_client.py
+++ b/ceilometer/nova_client.py
@@ -150,9 +150,15 @@ class Client(object):
search_opts=search_opts))
@logged
- def instance_get_all(self):
- """Returns list of all instances."""
+ def instance_get_all(self, since=None):
+ """Returns list of all instances.
+
+ If since is supplied, it will return the instances changes since that
+ datetime. since should be in ISO Format '%Y-%m-%dT%H:%M:%SZ'
+ """
search_opts = {'all_tenants': True}
+ if since:
+ search_opts['changes-since'] = since
return self.nova_client.servers.list(
detailed=True,
search_opts=search_opts)