-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_metric_uhost.py
More file actions
executable file
·96 lines (74 loc) · 3.18 KB
/
get_metric_uhost.py
File metadata and controls
executable file
·96 lines (74 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from sdk import UcloudApiClient
from config import *
import sys
import json
import time
#实例化 API 句柄
'''
ResrouceType:uhost
Name Description Unit
CPUUtilization CPU使用率 %
IORead 磁盘读流量 B/s
IOWrite 磁盘写流量 B/s
DiskReadOps 磁盘读次数 次/s
DiskWriteOps 磁盘写次数 次/s
NICIn 网卡入带宽 b/s
NICOut 网卡出带宽 b/s
NetPacketIn 网卡入包量 个/s
NetPacketOut 网卡出包量 个/s
MemUsage 内存使用率 %
RootSpaceUsage 系统盘使用率 %
DataSpaceUsage 数据盘使用率 %
ReadonlyDiskCount 只读磁盘个数 个
RunnableProcessCount 运行进程数量 个
BlockProcessCount 阻塞进程数量 个
'''
#dck is datacenter, dcv is uhostname and sourceID
# print exzample cn-east-01:{'www_coldbackup': 'uhost-cp2v41'}
for dck, dcv in DataCenter.iteritems():
# k is uhostname v is source ID
for k, v in dcv.items():
arg_length = len(sys.argv)
ApiClient = UcloudApiClient(base_url, public_key, private_key)
Parameters={
"ResourceType":"uhost",
"ResourceId":v,
"TimeRange":"180",
"Action":"GetMetric",
"Region":dck,
"MetricName.0":"CPUUtilization",
"MetricName.1":"MemUsage",
"MetricName.2":"RootSpaceUsage",
"MetricName.3":"DataSpaceUsage",
"MetricName.4":"NICOut",
"MetricName.5":"RunnableProcessCount",
"MetricName.6":"BlockProcessCount",
"MetricName.7":"NICIn",
#"Period":"300"
}
print '=============Start================'
print 'uhost: %s' %(k)
print
response = ApiClient.get("/", Parameters );
# ApiClient.
output = json.dumps(response, sort_keys=True, indent=4, separators=(',', ': '))
reson = json.loads(output)
xds = reson.get('DataSets')
print
for item, value in xds.items():
try:
a = value[0]
ltime = time.localtime(a['Timestamp'])
print '%s\t%s\t%s' %( time.strftime("%Y%m%d%H%M%S", ltime), a['Value'], item)
rvalue = [ time.strftime("%Y%m%d%H%M%S", ltime), a['Value'], item ]
ruhost.set( k+item, rvalue )
ruhost.expire( k+item, 120)
except IndexError:
#don't fetch data from ucloudapi is '-1';
print '%s\t%s\t%s' %( '-1', '-1', item)
rvalue = [ '-1', '-1', item ]
ruhost.set( k+item, rvalue )
ruhost.expire( k+item, 120)
print '================End================'