Skip to content

Commit f144e15

Browse files
committed
Add monitor APIs
1 parent 8e68aa6 commit f144e15

File tree

3 files changed

+66
-8
lines changed

3 files changed

+66
-8
lines changed

qingcloud/iaas/connection.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,3 +1793,60 @@ def modify_loadbalancer_backend_attributes(self, loadbalancer_backend,
17931793
self.req_checker.check_lb_backend_weight(body['weight'])
17941794

17951795
return self.send_request(action, body)
1796+
1797+
def get_monitoring_data(self, resource,
1798+
meters,
1799+
step,
1800+
start_time,
1801+
end_time,
1802+
**ignore):
1803+
""" Get resource monitoring data.
1804+
1805+
@param resource: the ID of resource, can be instance_id, volume_id, eip_id or router_id.
1806+
@param meters: list of metering types you want to get.
1807+
If resource is instance, meter can be "cpu", "disk-os", "memory",
1808+
"'disk-%s' % attached_volume_id", "'if-%s' % vxnet_mac_address".
1809+
If resource is volume, meter should be "'disk-%s' % volume_id".
1810+
If resource is eip, meter should be "traffic".
1811+
If resource is router, meter should be "vxnet-0".
1812+
@param step: The metering time step, valid steps: "5m", "15m", "30m", "1h", "2h", "1d".
1813+
@param start_time: the starting time stamp. In the format YYYY-MM-DDThh:mm:ssZ.
1814+
@param end_time: the ending time stamp. In the format YYYY-MM-DDThh:mm:ssZ.
1815+
"""
1816+
action = const.ACTION_GET_MONITOR
1817+
valid_keys = ['resource', 'meters', 'step', 'start_time', 'end_time']
1818+
body = filter_out_none(locals(), valid_keys)
1819+
if not self.req_checker.check_params(body,
1820+
required_params=['resource', 'meters', 'step', 'start_time', 'end_time'],
1821+
integer_params=[],
1822+
list_params=['meters']
1823+
):
1824+
return None
1825+
1826+
return self.send_request(action, body)
1827+
1828+
def get_loadbalancer_monitoring_data(self, resource,
1829+
meters,
1830+
step,
1831+
start_time,
1832+
end_time,
1833+
**ignore):
1834+
""" Get load balancer monitoring data.
1835+
1836+
@param resource: the ID of resource, can be loadbalancer_id, listener_id or backend_id.
1837+
@param meters: list of metering types you want to get, valid values: request, traffic.
1838+
@param step: The metering time step, valid steps: "5m", "15m", "30m", "1h", "2h", "1d".
1839+
@param start_time: the starting time stamp. In the format YYYY-MM-DDThh:mm:ssZ.
1840+
@param end_time: the ending time stamp. In the format YYYY-MM-DDThh:mm:ssZ.
1841+
"""
1842+
action = const.ACTION_GET_LOADBALANCER_MONITOR
1843+
valid_keys = ['resource', 'meters', 'step', 'start_time', 'end_time']
1844+
body = filter_out_none(locals(), valid_keys)
1845+
if not self.req_checker.check_params(body,
1846+
required_params=['resource', 'meters', 'step', 'start_time', 'end_time'],
1847+
integer_params=[],
1848+
list_params=['meters']
1849+
):
1850+
return None
1851+
1852+
return self.send_request(action, body)

qingcloud/iaas/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@
114114
ACTION_MODIFY_LOADBALANCER_BACKEND_ATTRIBUTES = "ModifyLoadBalancerBackendAttributes"
115115
ACTION_DESCRIBE_LOADBALANCER_BACKENDS = "DescribeLoadBalancerBackends"
116116

117+
# monitor
118+
ACTION_GET_MONITOR = "GetMonitor"
119+
ACTION_GET_LOADBALANCER_MONITOR = "GetLoadBalancerMonitor"
117120

118121
########## Constants for resource ##########
119122

qingcloud/misc/utils.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import stat
2121

2222
def save_private_key(file_name, private_key):
23-
""" save ssh private key """
23+
""" Save ssh private key
24+
"""
2425
if not save_file(file_name, private_key):
2526
return False
2627
os.chmod(file_name, stat.S_IREAD + stat.S_IWRITE)
@@ -39,9 +40,8 @@ def get_utf8_value(value):
3940
return value
4041

4142
def filter_out_none(dictionary, keys=None):
42-
"""
43-
Filter out items whose value is None.
44-
If `keys` specified, only return non-None and key matched items.
43+
""" Filter out items whose value is None.
44+
If `keys` specified, only return non-None items with matched key.
4545
"""
4646
ret = {}
4747
if keys is None:
@@ -57,16 +57,14 @@ def filter_out_none(dictionary, keys=None):
5757
ISO8601_MS = '%Y-%m-%dT%H:%M:%S.%fZ'
5858

5959
def get_ts(ts=None):
60-
"""
61-
Get formatted time
60+
""" Get formatted time
6261
"""
6362
if not ts:
6463
ts = time.gmtime()
6564
return time.strftime(ISO8601, ts)
6665

6766
def parse_ts(ts):
68-
"""
69-
Return as timestamp
67+
""" Return as timestamp
7068
"""
7169
ts = ts.strip()
7270
try:

0 commit comments

Comments
 (0)