Merge "Implements monitoring-network"
This commit is contained in:
commit
bf8f536529
68
ceilometer/network/statistics/__init__.py
Normal file
68
ceilometer/network/statistics/__init__.py
Normal file
@ -0,0 +1,68 @@
|
||||
#
|
||||
# Copyright 2014 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import abc
|
||||
|
||||
import six
|
||||
from stevedore import extension
|
||||
|
||||
from ceilometer.central import plugin
|
||||
from ceilometer import sample
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class _Base(plugin.CentralPollster):
|
||||
|
||||
NAMESPACE = 'network.statistics.drivers'
|
||||
extension_manager = extension.ExtensionManager(namespace=NAMESPACE,
|
||||
invoke_on_load=True)
|
||||
|
||||
@abc.abstractproperty
|
||||
def meter_name(self):
|
||||
'''Return a Meter Name.'''
|
||||
|
||||
@abc.abstractproperty
|
||||
def meter_type(self):
|
||||
'''Return a Meter Type.'''
|
||||
|
||||
@abc.abstractproperty
|
||||
def meter_unit(self):
|
||||
'''Return a Meter Unit.'''
|
||||
|
||||
def get_samples(self, manager, cache, resources=[]):
|
||||
for resource in resources:
|
||||
sample_data = self.extension_manager.map_method('get_sample_data',
|
||||
self.meter_name,
|
||||
resource,
|
||||
cache)
|
||||
for data in sample_data:
|
||||
if data is None:
|
||||
continue
|
||||
if not isinstance(data, list):
|
||||
data = [data]
|
||||
for (volume, resource_id,
|
||||
resource_metadata, timestamp) in data:
|
||||
|
||||
yield sample.Sample(
|
||||
name=self.meter_name,
|
||||
type=self.meter_type,
|
||||
unit=self.meter_unit,
|
||||
volume=volume,
|
||||
user_id=None,
|
||||
project_id=None,
|
||||
resource_id=resource_id,
|
||||
timestamp=timestamp,
|
||||
resource_metadata=resource_metadata
|
||||
)
|
29
ceilometer/network/statistics/driver.py
Normal file
29
ceilometer/network/statistics/driver.py
Normal file
@ -0,0 +1,29 @@
|
||||
#
|
||||
# Copyright 2014 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import abc
|
||||
|
||||
import six
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class Driver():
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_sample_data(self, meter_name, resource, cache):
|
||||
'''Return volume, resource_id, resource_metadata, timestamp in tuple.
|
||||
|
||||
If not implemented for meter_name, returns None
|
||||
'''
|
53
ceilometer/network/statistics/flow.py
Normal file
53
ceilometer/network/statistics/flow.py
Normal file
@ -0,0 +1,53 @@
|
||||
#
|
||||
# Copyright 2014 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from ceilometer.network import statistics
|
||||
from ceilometer import sample
|
||||
|
||||
|
||||
class FlowPollster(statistics._Base):
|
||||
|
||||
meter_name = 'switch.flow'
|
||||
meter_type = sample.TYPE_GAUGE
|
||||
meter_unit = 'flow'
|
||||
|
||||
|
||||
class FlowPollsterDurationSeconds(statistics._Base):
|
||||
|
||||
meter_name = 'switch.flow.duration_seconds'
|
||||
meter_type = sample.TYPE_GAUGE
|
||||
meter_unit = 's'
|
||||
|
||||
|
||||
class FlowPollsterDurationNanoseconds(statistics._Base):
|
||||
|
||||
meter_name = 'switch.flow.duration_nanoseconds'
|
||||
meter_type = sample.TYPE_GAUGE
|
||||
meter_unit = 'ns'
|
||||
|
||||
|
||||
class FlowPollsterPackets(statistics._Base):
|
||||
|
||||
meter_name = 'switch.flow.packets'
|
||||
meter_type = sample.TYPE_CUMULATIVE
|
||||
meter_unit = 'packet'
|
||||
|
||||
|
||||
class FlowPollsterBytes(statistics._Base):
|
||||
|
||||
meter_name = 'switch.flow.bytes'
|
||||
meter_type = sample.TYPE_CUMULATIVE
|
||||
meter_unit = 'B'
|
109
ceilometer/network/statistics/port.py
Normal file
109
ceilometer/network/statistics/port.py
Normal file
@ -0,0 +1,109 @@
|
||||
#
|
||||
# Copyright 2014 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from ceilometer.network import statistics
|
||||
from ceilometer import sample
|
||||
|
||||
|
||||
class PortPollster(statistics._Base):
|
||||
|
||||
meter_name = 'switch.port'
|
||||
meter_type = sample.TYPE_GAUGE
|
||||
meter_unit = 'port'
|
||||
|
||||
|
||||
class PortPollsterReceivePackets(statistics._Base):
|
||||
|
||||
meter_name = 'switch.port.receive.packets'
|
||||
meter_type = sample.TYPE_CUMULATIVE
|
||||
meter_unit = 'packet'
|
||||
|
||||
|
||||
class PortPollsterTransmitPackets(statistics._Base):
|
||||
|
||||
meter_name = 'switch.port.transmit.packets'
|
||||
meter_type = sample.TYPE_CUMULATIVE
|
||||
meter_unit = 'packet'
|
||||
|
||||
|
||||
class PortPollsterReceiveBytes(statistics._Base):
|
||||
|
||||
meter_name = 'switch.port.receive.bytes'
|
||||
meter_type = sample.TYPE_CUMULATIVE
|
||||
meter_unit = 'B'
|
||||
|
||||
|
||||
class PortPollsterTransmitBytes(statistics._Base):
|
||||
|
||||
meter_name = 'switch.port.transmit.bytes'
|
||||
meter_type = sample.TYPE_CUMULATIVE
|
||||
meter_unit = 'B'
|
||||
|
||||
|
||||
class PortPollsterReceiveDrops(statistics._Base):
|
||||
|
||||
meter_name = 'switch.port.receive.drops'
|
||||
meter_type = sample.TYPE_CUMULATIVE
|
||||
meter_unit = 'packet'
|
||||
|
||||
|
||||
class PortPollsterTransmitDrops(statistics._Base):
|
||||
|
||||
meter_name = 'switch.port.transmit.drops'
|
||||
meter_type = sample.TYPE_CUMULATIVE
|
||||
meter_unit = 'packet'
|
||||
|
||||
|
||||
class PortPollsterReceiveErrors(statistics._Base):
|
||||
|
||||
meter_name = 'switch.port.receive.errors'
|
||||
meter_type = sample.TYPE_CUMULATIVE
|
||||
meter_unit = 'packet'
|
||||
|
||||
|
||||
class PortPollsterTransmitErrors(statistics._Base):
|
||||
|
||||
meter_name = 'switch.port.transmit.errors'
|
||||
meter_type = sample.TYPE_CUMULATIVE
|
||||
meter_unit = 'packet'
|
||||
|
||||
|
||||
class PortPollsterReceiveFrameErrors(statistics._Base):
|
||||
|
||||
meter_name = 'switch.port.receive.frame_error'
|
||||
meter_type = sample.TYPE_CUMULATIVE
|
||||
meter_unit = 'packet'
|
||||
|
||||
|
||||
class PortPollsterReceiveOverrunErrors(statistics._Base):
|
||||
|
||||
meter_name = 'switch.port.receive.overrun_error'
|
||||
meter_type = sample.TYPE_CUMULATIVE
|
||||
meter_unit = 'packet'
|
||||
|
||||
|
||||
class PortPollsterReceiveCRCErrors(statistics._Base):
|
||||
|
||||
meter_name = 'switch.port.receive.crc_error'
|
||||
meter_type = sample.TYPE_CUMULATIVE
|
||||
meter_unit = 'packet'
|
||||
|
||||
|
||||
class PortPollsterCollisionCount(statistics._Base):
|
||||
|
||||
meter_name = 'switch.port.collision.count'
|
||||
meter_type = sample.TYPE_CUMULATIVE
|
||||
meter_unit = 'packet'
|
25
ceilometer/network/statistics/switch.py
Normal file
25
ceilometer/network/statistics/switch.py
Normal file
@ -0,0 +1,25 @@
|
||||
#
|
||||
# Copyright 2014 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from ceilometer.network import statistics
|
||||
from ceilometer import sample
|
||||
|
||||
|
||||
class SWPollster(statistics._Base):
|
||||
|
||||
meter_name = 'switch'
|
||||
meter_type = sample.TYPE_GAUGE
|
||||
meter_unit = 'switch'
|
46
ceilometer/network/statistics/table.py
Normal file
46
ceilometer/network/statistics/table.py
Normal file
@ -0,0 +1,46 @@
|
||||
#
|
||||
# Copyright 2014 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
from ceilometer.network import statistics
|
||||
from ceilometer import sample
|
||||
|
||||
|
||||
class TablePollster(statistics._Base):
|
||||
|
||||
meter_name = 'switch.table'
|
||||
meter_type = sample.TYPE_GAUGE
|
||||
meter_unit = 'table'
|
||||
|
||||
|
||||
class TablePollsterActiveEntries(statistics._Base):
|
||||
|
||||
meter_name = 'switch.table.active.entries'
|
||||
meter_type = sample.TYPE_GAUGE
|
||||
meter_unit = 'entry'
|
||||
|
||||
|
||||
class TablePollsterLookupPackets(statistics._Base):
|
||||
|
||||
meter_name = 'switch.table.lookup.packets'
|
||||
meter_type = sample.TYPE_GAUGE
|
||||
meter_unit = 'packet'
|
||||
|
||||
|
||||
class TablePollsterMatchedPackets(statistics._Base):
|
||||
|
||||
meter_name = 'switch.table.matched.packets'
|
||||
meter_type = sample.TYPE_GAUGE
|
||||
meter_unit = 'packet'
|
28
ceilometer/tests/network/statistics/__init__.py
Normal file
28
ceilometer/tests/network/statistics/__init__.py
Normal file
@ -0,0 +1,28 @@
|
||||
#
|
||||
# Copyright 2014 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from ceilometer.openstack.common import test
|
||||
|
||||
|
||||
class _PollsterTestBase(test.BaseTestCase):
|
||||
|
||||
def _test_pollster(self, pollster_class, meter_name,
|
||||
meter_type, meter_unit):
|
||||
|
||||
pollster = pollster_class()
|
||||
|
||||
self.assertEqual(pollster.meter_name, meter_name)
|
||||
self.assertEqual(pollster.meter_type, meter_type)
|
||||
self.assertEqual(pollster.meter_unit, meter_unit)
|
36
ceilometer/tests/network/statistics/test_driver.py
Normal file
36
ceilometer/tests/network/statistics/test_driver.py
Normal file
@ -0,0 +1,36 @@
|
||||
#
|
||||
# Copyright 2014 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from ceilometer.network.statistics import driver
|
||||
from ceilometer.openstack.common import test
|
||||
|
||||
|
||||
class TestDriver(test.BaseTestCase):
|
||||
|
||||
def test_driver_ok(self):
|
||||
|
||||
class OkDriver(driver.Driver):
|
||||
|
||||
def get_sample_data(self, meter_name, resources, cache):
|
||||
pass
|
||||
|
||||
OkDriver()
|
||||
|
||||
def test_driver_ng(self):
|
||||
|
||||
class NgDriver(driver.Driver):
|
||||
"""get_sample_data method is lost."""
|
||||
|
||||
self.assertRaises(TypeError, NgDriver)
|
56
ceilometer/tests/network/statistics/test_flow.py
Normal file
56
ceilometer/tests/network/statistics/test_flow.py
Normal file
@ -0,0 +1,56 @@
|
||||
#
|
||||
# Copyright 2014 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from ceilometer.network.statistics import flow
|
||||
from ceilometer import sample
|
||||
from ceilometer.tests.network import statistics
|
||||
|
||||
|
||||
class TestFlowPollsters(statistics._PollsterTestBase):
|
||||
|
||||
def test_flow_pollster(self):
|
||||
self._test_pollster(
|
||||
flow.FlowPollster,
|
||||
'switch.flow',
|
||||
sample.TYPE_GAUGE,
|
||||
'flow')
|
||||
|
||||
def test_flow_pollster_duration_seconds(self):
|
||||
self._test_pollster(
|
||||
flow.FlowPollsterDurationSeconds,
|
||||
'switch.flow.duration_seconds',
|
||||
sample.TYPE_GAUGE,
|
||||
's')
|
||||
|
||||
def test_flow_pollster_duration_nanoseconds(self):
|
||||
self._test_pollster(
|
||||
flow.FlowPollsterDurationNanoseconds,
|
||||
'switch.flow.duration_nanoseconds',
|
||||
sample.TYPE_GAUGE,
|
||||
'ns')
|
||||
|
||||
def test_flow_pollster_packets(self):
|
||||
self._test_pollster(
|
||||
flow.FlowPollsterPackets,
|
||||
'switch.flow.packets',
|
||||
sample.TYPE_CUMULATIVE,
|
||||
'packet')
|
||||
|
||||
def test_flow_pollster_bytes(self):
|
||||
self._test_pollster(
|
||||
flow.FlowPollsterBytes,
|
||||
'switch.flow.bytes',
|
||||
sample.TYPE_CUMULATIVE,
|
||||
'B')
|
112
ceilometer/tests/network/statistics/test_port.py
Normal file
112
ceilometer/tests/network/statistics/test_port.py
Normal file
@ -0,0 +1,112 @@
|
||||
#
|
||||
# Copyright 2014 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from ceilometer.network.statistics import port
|
||||
from ceilometer import sample
|
||||
from ceilometer.tests.network import statistics
|
||||
|
||||
|
||||
class TestPortPollsters(statistics._PollsterTestBase):
|
||||
|
||||
def test_port_pollster(self):
|
||||
self._test_pollster(
|
||||
port.PortPollster,
|
||||
'switch.port',
|
||||
sample.TYPE_GAUGE,
|
||||
'port')
|
||||
|
||||
def test_port_pollster_receive_packets(self):
|
||||
self._test_pollster(
|
||||
port.PortPollsterReceivePackets,
|
||||
'switch.port.receive.packets',
|
||||
sample.TYPE_CUMULATIVE,
|
||||
'packet')
|
||||
|
||||
def test_port_pollster_transmit_packets(self):
|
||||
self._test_pollster(
|
||||
port.PortPollsterTransmitPackets,
|
||||
'switch.port.transmit.packets',
|
||||
sample.TYPE_CUMULATIVE,
|
||||
'packet')
|
||||
|
||||
def test_port_pollster_receive_bytes(self):
|
||||
self._test_pollster(
|
||||
port.PortPollsterReceiveBytes,
|
||||
'switch.port.receive.bytes',
|
||||
sample.TYPE_CUMULATIVE,
|
||||
'B')
|
||||
|
||||
def test_port_pollster_transmit_bytes(self):
|
||||
self._test_pollster(
|
||||
port.PortPollsterTransmitBytes,
|
||||
'switch.port.transmit.bytes',
|
||||
sample.TYPE_CUMULATIVE,
|
||||
'B')
|
||||
|
||||
def test_port_pollster_receive_drops(self):
|
||||
self._test_pollster(
|
||||
port.PortPollsterReceiveDrops,
|
||||
'switch.port.receive.drops',
|
||||
sample.TYPE_CUMULATIVE,
|
||||
'packet')
|
||||
|
||||
def test_port_pollster_transmit_drops(self):
|
||||
self._test_pollster(
|
||||
port.PortPollsterTransmitDrops,
|
||||
'switch.port.transmit.drops',
|
||||
sample.TYPE_CUMULATIVE,
|
||||
'packet')
|
||||
|
||||
def test_port_pollster_receive_errors(self):
|
||||
self._test_pollster(
|
||||
port.PortPollsterReceiveErrors,
|
||||
'switch.port.receive.errors',
|
||||
sample.TYPE_CUMULATIVE,
|
||||
'packet')
|
||||
|
||||
def test_port_pollster_transmit_errors(self):
|
||||
self._test_pollster(
|
||||
port.PortPollsterTransmitErrors,
|
||||
'switch.port.transmit.errors',
|
||||
sample.TYPE_CUMULATIVE,
|
||||
'packet')
|
||||
|
||||
def test_port_pollster_receive_frame_errors(self):
|
||||
self._test_pollster(
|
||||
port.PortPollsterReceiveFrameErrors,
|
||||
'switch.port.receive.frame_error',
|
||||
sample.TYPE_CUMULATIVE,
|
||||
'packet')
|
||||
|
||||
def test_port_pollster_receive_overrun_errors(self):
|
||||
self._test_pollster(
|
||||
port.PortPollsterReceiveOverrunErrors,
|
||||
'switch.port.receive.overrun_error',
|
||||
sample.TYPE_CUMULATIVE,
|
||||
'packet')
|
||||
|
||||
def test_port_pollster_receive_crc_errors(self):
|
||||
self._test_pollster(
|
||||
port.PortPollsterReceiveCRCErrors,
|
||||
'switch.port.receive.crc_error',
|
||||
sample.TYPE_CUMULATIVE,
|
||||
'packet')
|
||||
|
||||
def test_port_pollster_collision_count(self):
|
||||
self._test_pollster(
|
||||
port.PortPollsterCollisionCount,
|
||||
'switch.port.collision.count',
|
||||
sample.TYPE_CUMULATIVE,
|
||||
'packet')
|
182
ceilometer/tests/network/statistics/test_statistics.py
Normal file
182
ceilometer/tests/network/statistics/test_statistics.py
Normal file
@ -0,0 +1,182 @@
|
||||
#
|
||||
# Copyright 2014 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from stevedore import extension
|
||||
from stevedore.tests import manager as test_manager
|
||||
|
||||
from ceilometer.network import statistics
|
||||
from ceilometer.network.statistics import driver
|
||||
from ceilometer.openstack.common import test
|
||||
from ceilometer.openstack.common import timeutils
|
||||
from ceilometer import sample
|
||||
|
||||
|
||||
class TestBase(test.BaseTestCase):
|
||||
|
||||
def test_subclass_ok(self):
|
||||
|
||||
class OkSubclass(statistics._Base):
|
||||
|
||||
meter_name = 'foo'
|
||||
meter_type = sample.TYPE_GAUGE
|
||||
meter_unit = 'B'
|
||||
|
||||
OkSubclass()
|
||||
|
||||
def test_subclass_ng(self):
|
||||
|
||||
class NgSubclass1(statistics._Base):
|
||||
'''meter_name is lost.'''
|
||||
|
||||
meter_type = sample.TYPE_GAUGE
|
||||
meter_unit = 'B'
|
||||
|
||||
class NgSubclass2(statistics._Base):
|
||||
'''meter_type is lost.'''
|
||||
|
||||
meter_name = 'foo'
|
||||
meter_unit = 'B'
|
||||
|
||||
class NgSubclass3(statistics._Base):
|
||||
'''meter_unit is lost.'''
|
||||
|
||||
meter_name = 'foo'
|
||||
meter_type = sample.TYPE_GAUGE
|
||||
|
||||
self.assertRaises(TypeError, NgSubclass1)
|
||||
self.assertRaises(TypeError, NgSubclass2)
|
||||
self.assertRaises(TypeError, NgSubclass3)
|
||||
|
||||
|
||||
class TestBaseGetSamples(test.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestBaseGetSamples, self).setUp()
|
||||
|
||||
class FakePollster(statistics._Base):
|
||||
meter_name = 'foo'
|
||||
meter_type = sample.TYPE_CUMULATIVE
|
||||
meter_unit = 'bar'
|
||||
|
||||
self.pollster = FakePollster()
|
||||
|
||||
def _setup_ext_mgr(self, *drivers):
|
||||
extensions = [
|
||||
extension.Extension(str(d), None, None, d())
|
||||
for d in drivers]
|
||||
ext_mgr = test_manager.TestExtensionManager(
|
||||
extensions)
|
||||
self.pollster.extension_manager = ext_mgr
|
||||
|
||||
def _make_fake_driver(self, *return_values):
|
||||
class FakeDriver(driver.Driver):
|
||||
|
||||
def __init__(self):
|
||||
self.index = 0
|
||||
|
||||
def get_sample_data(self, meter_name, resource, cache):
|
||||
if self.index >= len(return_values):
|
||||
return None
|
||||
retval = return_values[self.index]
|
||||
self.index += 1
|
||||
return retval
|
||||
return FakeDriver
|
||||
|
||||
def _make_timestamps(self, count):
|
||||
return [timeutils.isotime() for i in range(count)]
|
||||
|
||||
def _get_samples(self, *resources):
|
||||
|
||||
return [v for v in self.pollster.get_samples(self, {}, resources)]
|
||||
|
||||
def _assert_sample(self, s, volume, resource_id, resource_metadata,
|
||||
timestamp):
|
||||
self.assertEqual(s.name, 'foo')
|
||||
self.assertEqual(s.type, sample.TYPE_CUMULATIVE)
|
||||
self.assertEqual(s.unit, 'bar')
|
||||
self.assertEqual(s.volume, volume)
|
||||
self.assertIsNone(s.user_id)
|
||||
self.assertIsNone(s.project_id)
|
||||
self.assertEqual(s.resource_id, resource_id)
|
||||
self.assertEqual(s.timestamp, timestamp)
|
||||
self.assertEqual(s.resource_metadata, resource_metadata)
|
||||
|
||||
def test_get_samples_one_driver_one_resource(self):
|
||||
times = self._make_timestamps(2)
|
||||
fake_driver = self._make_fake_driver((1, 'a', {'spam': 'egg'},
|
||||
times[0]),
|
||||
(2, 'b', None, times[1]))
|
||||
|
||||
self._setup_ext_mgr(fake_driver)
|
||||
|
||||
samples = self._get_samples('http://foo')
|
||||
|
||||
self.assertEqual(len(samples), 1)
|
||||
self._assert_sample(samples[0], 1, 'a', {'spam': 'egg'}, times[0])
|
||||
|
||||
def test_get_samples_one_driver_two_resource(self):
|
||||
times = self._make_timestamps(3)
|
||||
fake_driver = self._make_fake_driver((1, 'a', {'spam': 'egg'},
|
||||
times[0]),
|
||||
(2, 'b', None, times[1]),
|
||||
(3, 'c', None, times[2]))
|
||||
|
||||
self._setup_ext_mgr(fake_driver)
|
||||
|
||||
samples = self._get_samples('http://foo', 'http://bar')
|
||||
|
||||
self.assertEqual(len(samples), 2)
|
||||
self._assert_sample(samples[0], 1, 'a', {'spam': 'egg'}, times[2])
|
||||
self._assert_sample(samples[1], 2, 'b', None, times[1])
|
||||
|
||||
def test_get_samples_two_driver_one_resource(self):
|
||||
times = self._make_timestamps(4)
|
||||
fake_driver1 = self._make_fake_driver((1, 'a', {'spam': 'egg'},
|
||||
times[0]),
|
||||
(2, 'b', None), times[1])
|
||||
|
||||
fake_driver2 = self._make_fake_driver((11, 'A', None, times[2]),
|
||||
(12, 'B', None, times[3]))
|
||||
|
||||
self._setup_ext_mgr(fake_driver1, fake_driver2)
|
||||
|
||||
samples = self._get_samples('http://foo')
|
||||
|
||||
self.assertEqual(len(samples), 2)
|
||||
self._assert_sample(samples[0], 1, 'a', {'spam': 'egg'}, times[0])
|
||||
self._assert_sample(samples[1], 11, 'A', None, times[2])
|
||||
|
||||
def test_get_samples_multi_samples(self):
|
||||
times = self._make_timestamps(2)
|
||||
fake_driver = self._make_fake_driver([(1, 'a', {'spam': 'egg'},
|
||||
times[0]),
|
||||
(2, 'b', None, times[1])])
|
||||
|
||||
self._setup_ext_mgr(fake_driver)
|
||||
|
||||
samples = self._get_samples('http://foo')
|
||||
|
||||
self.assertEqual(len(samples), 2)
|
||||
self._assert_sample(samples[0], 1, 'a', {'spam': 'egg'}, times[0])
|
||||
self._assert_sample(samples[1], 2, 'b', None, times[1])
|
||||
|
||||
def test_get_samples_return_none(self):
|
||||
fake_driver = self._make_fake_driver(None)
|
||||
|
||||
self._setup_ext_mgr(fake_driver)
|
||||
|
||||
samples = self._get_samples('http://foo')
|
||||
|
||||
self.assertEqual(len(samples), 0)
|
28
ceilometer/tests/network/statistics/test_switch.py
Normal file
28
ceilometer/tests/network/statistics/test_switch.py
Normal file
@ -0,0 +1,28 @@
|
||||
#
|
||||
# Copyright 2014 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from ceilometer.network.statistics import switch
|
||||
from ceilometer import sample
|
||||
from ceilometer.tests.network import statistics
|
||||
|
||||
|
||||
class TestSwitchPollster(statistics._PollsterTestBase):
|
||||
|
||||
def test_table_pollster(self):
|
||||
self._test_pollster(
|
||||
switch.SWPollster,
|
||||
'switch',
|
||||
sample.TYPE_GAUGE,
|
||||
'switch')
|
49
ceilometer/tests/network/statistics/test_table.py
Normal file
49
ceilometer/tests/network/statistics/test_table.py
Normal file
@ -0,0 +1,49 @@
|
||||
#
|
||||
# Copyright 2014 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from ceilometer.network.statistics import table
|
||||
from ceilometer import sample
|
||||
from ceilometer.tests.network import statistics
|
||||
|
||||
|
||||
class TestTablePollsters(statistics._PollsterTestBase):
|
||||
|
||||
def test_table_pollster(self):
|
||||
self._test_pollster(
|
||||
table.TablePollster,
|
||||
'switch.table',
|
||||
sample.TYPE_GAUGE,
|
||||
'table')
|
||||
|
||||
def test_table_pollster_active_entries(self):
|
||||
self._test_pollster(
|
||||
table.TablePollsterActiveEntries,
|
||||
'switch.table.active.entries',
|
||||
sample.TYPE_GAUGE,
|
||||
'entry')
|
||||
|
||||
def test_table_pollster_lookup_packets(self):
|
||||
self._test_pollster(
|
||||
table.TablePollsterLookupPackets,
|
||||
'switch.table.lookup.packets',
|
||||
sample.TYPE_GAUGE,
|
||||
'packet')
|
||||
|
||||
def test_table_pollster_matched_packets(self):
|
||||
self._test_pollster(
|
||||
table.TablePollsterMatchedPackets,
|
||||
'switch.table.matched.packets',
|
||||
sample.TYPE_GAUGE,
|
||||
'packet')
|
@ -195,6 +195,40 @@ energy Cumulative kWh probe ID pollster Amount o
|
||||
power Gauge W probe ID pollster Power consumption
|
||||
========================== ========== ========== ======== ========= ==============================================
|
||||
|
||||
Network (From SDN Controller)
|
||||
=============
|
||||
|
||||
These meters based on OpenFlow Switch metrics.
|
||||
In order to enable these meters, each driver needs to be configured.
|
||||
|
||||
================================= ========== ====== ========= ======== ==============================
|
||||
Meter Type Unit Resource Origin Note
|
||||
================================= ========== ====== ========= ======== ==============================
|
||||
switch Gauge switch switch ID pollster Existence of switch
|
||||
switch.port Gauge port switch ID pollster Existence of port
|
||||
switch.port.receive.packets Cumulative packet switch ID pollster Received Packets
|
||||
switch.port.transmit.packets Cumulative packet switch ID pollster Transmitted Packets
|
||||
switch.port.receive.bytes Cumulative B switch ID pollster Received Bytes
|
||||
switch.port.transmit.bytes Cumulative B switch ID pollster Transmitted Bytes
|
||||
switch.port.receive.drops Cumulative packet switch ID pollster Receive Drops
|
||||
switch.port.transmit.drops Cumulative packet switch ID pollster Transmit Drops
|
||||
switch.port.receive.errors Cumulative packet switch ID pollster Receive Errors
|
||||
switch.port.transmit.errors Cumulative packet switch ID pollster Transmit Errors
|
||||
switch.port.receive.frame_error Cumulative packet switch ID pollster Receive Frame Alignment Errors
|
||||
switch.port.receive.overrun_error Cumulative packet switch ID pollster Receive Overrun Errors
|
||||
switch.port.receive.crc_error Cumulative packet switch ID pollster Receive CRC Errors
|
||||
switch.port.collision.count Cumulative count switch ID pollster Collisions
|
||||
switch.table Gauge table switch ID pollster Duration of Table
|
||||
switch.table.active.entries Gauge entry switch ID pollster Active Entries
|
||||
switch.table.lookup.packets Gauge packet switch ID pollster Packet Lookups
|
||||
switch.table.matched.packets Gauge packet switch ID pollster Packet Matches
|
||||
switch.flow Gauge flow switch ID pollster Duration of Flow
|
||||
switch.flow.duration.seconds Gauge s switch ID pollster Duration(seconds)
|
||||
switch.flow.duration.nanoseconds Gauge ns switch ID pollster Duration(nanoseconds)
|
||||
switch.flow.packets Cumulative packet switch ID pollster Received Packets
|
||||
switch.flow.bytes Cumulative B switch ID pollster Received Bytes
|
||||
================================= ========== ====== ========= ======== ==============================
|
||||
|
||||
Dynamically retrieving the Meters via ceilometer client
|
||||
=======================================================
|
||||
|
||||
|
26
setup.cfg
26
setup.cfg
@ -88,6 +88,30 @@ ceilometer.poll.central =
|
||||
storage.objects.containers = ceilometer.objectstore.swift:ObjectsContainersPollster
|
||||
energy = ceilometer.energy.kwapi:EnergyPollster
|
||||
power = ceilometer.energy.kwapi:PowerPollster
|
||||
switch.port = ceilometer.network.statistics.port:PortPollster
|
||||
switch.port.receive.packets = ceilometer.network.statistics.port:PortPollsterReceivePackets
|
||||
switch.port.transmit.packets = ceilometer.network.statistics.port:PortPollsterTransmitPackets
|
||||
switch.port.receive.bytes = ceilometer.network.statistics.port:PortPollsterReceiveBytes
|
||||
switch.port.transmit.bytes = ceilometer.network.statistics.port:PortPollsterTransmitBytes
|
||||
switch.port.receive.drops = ceilometer.network.statistics.port:PortPollsterReceiveDrops
|
||||
switch.port.transmit.drops = ceilometer.network.statistics.port:PortPollsterTransmitDrops
|
||||
switch.port.receive.errors = ceilometer.network.statistics.port:PortPollsterReceiveErrors
|
||||
switch.port.transmit.errors = ceilometer.network.statistics.port:PortPollsterTransmitErrors
|
||||
switch.port.receive.frame_error = ceilometer.network.statistics.port:PortPollsterReceiveFrameErrors
|
||||
switch.port.receive.overrun_error = ceilometer.network.statistics.port:PortPollsterReceiveOverrunErrors
|
||||
switch.port.receive.crc_error = ceilometer.network.statistics.port:PortPollsterReceiveCRCErrors
|
||||
switch.port.collision.count = ceilometer.network.statistics.port:PortPollsterCollisionCount
|
||||
switch.table = ceilometer.network.statistics.table:TablePollster
|
||||
switch.table.active.entries = ceilometer.network.statistics.table:TablePollsterActiveEntries
|
||||
switch.table.lookup.packets = ceilometer.network.statistics.table:TablePollsterLookupPackets
|
||||
switch.table.matched.packets = ceilometer.network.statistics.table:TablePollsterMatchedPackets
|
||||
switch = ceilometer.network.statistics.switch:SWPollster
|
||||
switch.flow = ceilometer.network.statistics.flow:FlowPollster
|
||||
switch.flow.bytes = ceilometer.network.statistics.flow:FlowPollsterBytes
|
||||
switch.flow.duration.nanoseconds = ceilometer.network.statistics.flow:FlowPollsterDurationNanoseconds
|
||||
switch.flow.duration.seconds = ceilometer.network.statistics.flow:FlowPollsterDurationSeconds
|
||||
switch.flow.packets = ceilometer.network.statistics.flow:FlowPollsterPackets
|
||||
|
||||
|
||||
ceilometer.storage =
|
||||
log = ceilometer.storage.impl_log:LogStorage
|
||||
@ -148,6 +172,8 @@ ceilometer.dispatcher =
|
||||
database = ceilometer.dispatcher.database:DatabaseDispatcher
|
||||
file = ceilometer.dispatcher.file:FileDispatcher
|
||||
|
||||
network.statistics.drivers =
|
||||
|
||||
|
||||
[build_sphinx]
|
||||
all_files = 1
|
||||
|
Loading…
Reference in New Issue
Block a user