import time
import six
+import yaml
from osm_mon.core.message_bus.producer import KafkaProducer
from osm_mon.plugins.OpenStack.common import Common
log = logging.getLogger(__name__)
METRIC_MAPPINGS = {
- "average_memory_utilization": "memory.percent",
+ "average_memory_utilization": "memory.usage",
"disk_read_ops": "disk.read.requests",
"disk_write_ops": "disk.write.requests",
"disk_read_bytes": "disk.read.bytes",
def metric_calls(self, message):
"""Consume info from the message bus to manage metric requests."""
- values = json.loads(message.value)
+ try:
+ values = json.loads(message.value)
+ except ValueError:
+ values = yaml.safe_load(message.value)
log.info("OpenStack metric action required.")
auth_token = Common.get_auth_token(values['vim_uuid'])
# Generate and send a response message
try:
+
+ metric_id = self.get_metric_id(endpoint, auth_token, METRIC_MAPPINGS[values['metric_name']],
+ values['resource_uuid'])
resp_message = self._response.generate_response(
'read_metric_data_response',
- m_id=values['metric_uuid'],
+ m_id=metric_id,
m_name=values['metric_name'],
r_id=values['resource_uuid'],
cor_id=values['correlation_id'],
elif message.key == "delete_metric_request":
# delete the specified metric in the request
- metric_id = values['metric_uuid']
+ metric_id = self.get_metric_id(endpoint, auth_token, METRIC_MAPPINGS[values['metric_name']],
+ values['resource_uuid'])
status = self.delete_metric(
endpoint, auth_token, metric_id)
def get_metric_id(self, endpoint, auth_token, metric_name, resource_id):
"""Check if the desired metric already exists for the resource."""
url = "{}/v1/resource/generic/%s".format(endpoint) % resource_id
-
try:
# Try return the metric id if it exists
result = Common.perform_request(
timestamps = []
data = []
try:
+ #get metric_id
+ metric_id = self.get_metric_id(endpoint, auth_token, METRIC_MAPPINGS[values['metric_name']], values['resource_uuid'])
# Try and collect measures
- metric_id = values['metric_uuid']
collection_unit = values['collection_unit'].upper()
collection_period = values['collection_period']