projects
/
osm
/
MON.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge "chore(gitignore): vscode files to gitignore" into v7.0
[osm/MON.git]
/
osm_mon
/
collector
/
vnf_collectors
/
openstack.py
diff --git
a/osm_mon/collector/vnf_collectors/openstack.py
b/osm_mon/collector/vnf_collectors/openstack.py
index
f63d0b2
..
1bb0fc8
100644
(file)
--- a/
osm_mon/collector/vnf_collectors/openstack.py
+++ b/
osm_mon/collector/vnf_collectors/openstack.py
@@
-19,12
+19,14
@@
# For those usages not covered by the Apache License, Version 2.0 please
# contact: bdiaz@whitestack.com or glavado@whitestack.com
##
# For those usages not covered by the Apache License, Version 2.0 please
# contact: bdiaz@whitestack.com or glavado@whitestack.com
##
-import logging
from enum import Enum
from enum import Enum
+import logging
+import time
from typing import List
from typing import List
+from ceilometerclient import client as ceilometer_client
+from ceilometerclient.exc import HTTPException
import gnocchiclient.exceptions
import gnocchiclient.exceptions
-from ceilometerclient.v2 import client as ceilometer_client
from gnocchiclient.v1 import client as gnocchi_client
from keystoneauth1.exceptions.catalog import EndpointNotFound
from keystoneclient.v3 import client as keystone_client
from gnocchiclient.v1 import client as gnocchi_client
from keystoneauth1.exceptions.catalog import EndpointNotFound
from keystoneclient.v3 import client as keystone_client
@@
-37,6
+39,7
@@
from osm_mon.collector.vnf_metric import VnfMetric
from osm_mon.core.common_db import CommonDbClient
from osm_mon.core.config import Config
from osm_mon.core.common_db import CommonDbClient
from osm_mon.core.config import Config
+
log = logging.getLogger(__name__)
METRIC_MAPPINGS = {
log = logging.getLogger(__name__)
METRIC_MAPPINGS = {
@@
-49,7
+52,15
@@
METRIC_MAPPINGS = {
"packets_out_dropped": "network.incoming.packets.drop",
"packets_received": "network.incoming.packets.rate",
"packets_sent": "network.outgoing.packets.rate",
"packets_out_dropped": "network.incoming.packets.drop",
"packets_received": "network.incoming.packets.rate",
"packets_sent": "network.outgoing.packets.rate",
- "cpu_utilization": "cpu_util",
+ "cpu_utilization": "cpu",
+}
+
+METRIC_MULTIPLIERS = {
+ "cpu": 0.0000001
+}
+
+METRIC_AGGREGATORS = {
+ "cpu": "rate:mean"
}
INTERFACE_METRICS = ['packets_in_dropped', 'packets_out_dropped', 'packets_received', 'packets_sent']
}
INTERFACE_METRICS = ['packets_in_dropped', 'packets_out_dropped', 'packets_received', 'packets_sent']
@@
-80,6
+91,15
@@
class OpenstackCollector(BaseVimCollector):
nsr_id = vnfr['nsr-id-ref']
vnf_member_index = vnfr['member-vnf-index-ref']
vnfd = self.common_db.get_vnfd(vnfr['vnfd-id'])
nsr_id = vnfr['nsr-id-ref']
vnf_member_index = vnfr['member-vnf-index-ref']
vnfd = self.common_db.get_vnfd(vnfr['vnfd-id'])
+
+ # Populate extra tags for metrics
+ tags = {}
+ tags['ns_name'] = self.common_db.get_nsr(nsr_id)['name']
+ if vnfr['_admin']['projects_read']:
+ tags['project_id'] = vnfr['_admin']['projects_read'][0]
+ else:
+ tags['project_id'] = ''
+
metrics = []
for vdur in vnfr['vdur']:
# This avoids errors when vdur records have not been completely filled
metrics = []
for vdur in vnfr['vdur']:
# This avoids errors when vdur records have not been completely filled
@@
-106,7
+126,6
@@
class OpenstackCollector(BaseVimCollector):
value = self.backend.collect_metric(metric_type, openstack_metric_name, resource_id,
interface_name)
if value is not None:
value = self.backend.collect_metric(metric_type, openstack_metric_name, resource_id,
interface_name)
if value is not None:
- tags = {}
if interface_name:
tags['interface'] = interface_name
metric = VnfMetric(nsr_id, vnf_member_index, vdur['name'], metric_name, value, tags)
if interface_name:
tags['interface'] = interface_name
metric = VnfMetric(nsr_id, vnf_member_index, vdur['name'], metric_name, value, tags)
@@
-120,9
+139,9
@@
class OpenstackCollector(BaseVimCollector):
ceilometer = CeilometerBackend(vim_account)
ceilometer.client.capabilities.get()
return ceilometer
ceilometer = CeilometerBackend(vim_account)
ceilometer.client.capabilities.get()
return ceilometer
- except
EndpointNotFound
:
+ except
(HTTPException, EndpointNotFound)
:
gnocchi = GnocchiBackend(vim_account)
gnocchi = GnocchiBackend(vim_account)
- gnocchi.client.
status.get(
)
+ gnocchi.client.
metric.list(limit=1
)
return gnocchi
def _get_metric_type(self, metric_name: str, interface_name: str) -> MetricType:
return gnocchi
def _get_metric_type(self, metric_name: str, interface_name: str) -> MetricType:
@@
-203,11
+222,22
@@
class GnocchiBackend(OpenstackBackend):
def _collect_instance_metric(self, openstack_metric_name, resource_id):
value = None
try:
def _collect_instance_metric(self, openstack_metric_name, resource_id):
value = None
try:
+ aggregation = METRIC_AGGREGATORS.get(openstack_metric_name)
+
measures = self.client.metric.get_measures(openstack_metric_name,
measures = self.client.metric.get_measures(openstack_metric_name,
- resource_id=resource_id,
- limit=1)
+ aggregation=aggregation,
+ start=time.time() - 1200,
+ resource_id=resource_id)
+ # measures[-1][0] is the time of the reporting interval
+ # measures[-1][1] is the durcation of the reporting interval
+ # measures[-1][2] is the value of the metric
if measures:
value = measures[-1][2]
if measures:
value = measures[-1][2]
+ if aggregation:
+ # If this is an aggregate, we need to divide the total over the reported time period.
+ value = value / measures[-1][1]
+ if openstack_metric_name in METRIC_MULTIPLIERS:
+ value = value * METRIC_MULTIPLIERS[openstack_metric_name]
except gnocchiclient.exceptions.NotFound as e:
log.debug("No metric %s found for instance %s: %s", openstack_metric_name, resource_id,
e)
except gnocchiclient.exceptions.NotFound as e:
log.debug("No metric %s found for instance %s: %s", openstack_metric_name, resource_id,
e)
@@
-220,7
+250,7
@@
class CeilometerBackend(OpenstackBackend):
def _build_ceilometer_client(self, vim_account: dict) -> ceilometer_client.Client:
sess = OpenstackUtils.get_session(vim_account)
def _build_ceilometer_client(self, vim_account: dict) -> ceilometer_client.Client:
sess = OpenstackUtils.get_session(vim_account)
- return ceilometer_client.Client(session=sess)
+ return ceilometer_client.Client(
"2",
session=sess)
def collect_metric(self, metric_type: MetricType, metric_name: str, resource_id: str, interface_name: str):
if metric_type != MetricType.INSTANCE:
def collect_metric(self, metric_type: MetricType, metric_name: str, resource_id: str, interface_name: str):
if metric_type != MetricType.INSTANCE: