summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Myers <jason@jasonamyers.com>2015-07-21 23:51:40 -0500
committergordon chung <gord@live.ca>2016-01-05 00:38:02 +0000
commit541a87587e1d5bd8c382b85debaa6f37bea6c13d (patch)
treeca963029ce23ed61ab86fd50b716fb6999f1d022
parent0d79ea0edca9c175076742357c83aed07b48711b (diff)
downloadceilometer-541a87587e1d5bd8c382b85debaa6f37bea6c13d.tar.gz
Instance Caching
This is the work to complete the resource-metadata-caching blueprint. * Implement an in-memory cache in the compute agent. * Change compute-agent to populate an in-memory cache. * Change compute-agent to use the changes-since parameter in the Nova API call . * Change compute-agent to record the polling timestamp in the cache. * Change compute-agent to cache the flavor and image metadata as well. Closes-Bug: #1524166 Change-Id: I97594e082db6d8e34d9201a7ec5710978e557d6d Signed-off-by: Jason Myers <jason@jasonamyers.com> (cherry picked from commit 7050d3be10788d695d83d7162bc5e078622a982d)
-rw-r--r--ceilometer/compute/discovery.py16
-rw-r--r--ceilometer/nova_client.py10
2 files changed, 21 insertions, 5 deletions
diff --git a/ceilometer/compute/discovery.py b/ceilometer/compute/discovery.py
index ac6afafd..e85d067b 100644
--- a/ceilometer/compute/discovery.py
+++ b/ceilometer/compute/discovery.py
@@ -14,6 +14,7 @@
# under the License.
from oslo_config import cfg
+from oslo_utils import timeutils
from ceilometer.agent import plugin_base
from ceilometer import nova_client
@@ -31,12 +32,21 @@ class InstanceDiscovery(plugin_base.DiscoveryBase):
def __init__(self):
super(InstanceDiscovery, self).__init__()
self.nova_cli = nova_client.Client()
+ self.last_run = None
+ self.instances = {}
def discover(self, manager, param=None):
"""Discover resources to monitor."""
- instances = self.nova_cli.instance_get_all_by_host(cfg.CONF.host)
- return [i for i in instances
- if getattr(i, 'OS-EXT-STS:vm_state', None) != 'error']
+ instances = self.nova_cli.instance_get_all_by_host(
+ cfg.CONF.host, 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()
+ return self.instances.values()
@property
def group_id(self):
diff --git a/ceilometer/nova_client.py b/ceilometer/nova_client.py
index 8b09219a..cce5139d 100644
--- a/ceilometer/nova_client.py
+++ b/ceilometer/nova_client.py
@@ -137,9 +137,15 @@ class Client(object):
setattr(instance, attr, ameta)
@logged
- def instance_get_all_by_host(self, hostname):
- """Returns list of instances on particular host."""
+ def instance_get_all_by_host(self, hostname, since=None):
+ """Returns list of instances on particular host.
+
+ If since is supplied, it will return the instances changed since that
+ datetime. since should be in ISO Format '%Y-%m-%dT%H:%M:%SZ'
+ """
search_opts = {'host': hostname, 'all_tenants': True}
+ if since:
+ search_opts['changes-since'] = since
return self._with_flavor_and_image(self.nova_client.servers.list(
detailed=True,
search_opts=search_opts))