| 1 |
# (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP |
| 2 |
# Copyright 2017 FUJITSU LIMITED |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
# you may not use this file except in compliance with the License. |
| 6 |
# You may obtain a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 13 |
# implied. |
| 14 |
# See the License for the specific language governing permissions and |
| 15 |
# limitations under the License. |
| 16 |
|
| 17 |
from monascaclient.common import monasca_manager |
| 18 |
|
| 19 |
|
| 20 |
class MetricsManager(monasca_manager.MonascaManager): |
| 21 |
base_url = '/metrics' |
| 22 |
|
| 23 |
def create(self, **kwargs): |
| 24 |
"""Create a metric.""" |
| 25 |
url_str = self.base_url |
| 26 |
if 'tenant_id' in kwargs: |
| 27 |
url_str = url_str + '?tenant_id=%s' % kwargs['tenant_id'] |
| 28 |
del kwargs['tenant_id'] |
| 29 |
|
| 30 |
data = kwargs['jsonbody'] if 'jsonbody' in kwargs else kwargs |
| 31 |
body = self.client.create(url=url_str, json=data) |
| 32 |
return body |
| 33 |
|
| 34 |
def list(self, **kwargs): |
| 35 |
"""Get a list of metrics.""" |
| 36 |
return self._list('', 'dimensions', **kwargs) |
| 37 |
|
| 38 |
def list_names(self, **kwargs): |
| 39 |
"""Get a list of metric names.""" |
| 40 |
return self._list('/names', 'dimensions', **kwargs) |
| 41 |
|
| 42 |
def list_measurements(self, **kwargs): |
| 43 |
"""Get a list of measurements based on metric definition filters.""" |
| 44 |
return self._list('/measurements', 'dimensions', **kwargs) |
| 45 |
|
| 46 |
def list_statistics(self, **kwargs): |
| 47 |
"""Get a list of measurement statistics based on metric def filters.""" |
| 48 |
return self._list('/statistics', 'dimensions', **kwargs) |
| 49 |
|
| 50 |
def list_dimension_names(self, **kwargs): |
| 51 |
"""Get a list of metric dimension names.""" |
| 52 |
return self._list('/dimensions/names', **kwargs) |
| 53 |
|
| 54 |
def list_dimension_values(self, **kwargs): |
| 55 |
"""Get a list of metric dimension values.""" |
| 56 |
return self._list('/dimensions/names/values', **kwargs) |