CollDossWithCMD.java
7.36 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package com.sitech.ismp.coll.storage.doss;
import com.sitech.ismp.coll.CollBase;
import com.sitech.ismp.coll.basic.TblATO_KPIDETAIL;
import com.sitech.util.DES3;
import com.sitech.util.Formater;
import com.sitech.util.upload.RomoteController;
import com.sitech.util.upload.SSHThread;
import com.sitech.util.upload.TelnetThread;
import org.apache.log4j.Logger;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
/**
* Created by mooker on 14/11/25.
*/
public class CollDossWithCMD {
private static Logger logger = Logger.getLogger("COLL");
String PRE_UNITID = "10-14-14"; // 分布式对象存储标识
RomoteController tt = null;
String neat_host_name = "";
String storageName = "";
String ipAddr;
boolean isConnect = false;
public void init(HashMap params) {
ipAddr = (String) params.get("IP_ADDR");
String user = (String) params.get("USERNAME");
String passwd = (String) params.get("PASSWORD");
passwd = DES3.decrypt(passwd);
String protol = (String) params.get("PROTOCOL");
storageName = (String) params.get("STORAGENAME");
this.neat_host_name = Formater.neatenunitid(storageName);
String protocolPort = null;
if (params.get("PROTOCOL_PORT") != null) {
protocolPort = ((String) params.get("PROTOCOL_PORT")).trim();
}
if (protol != null && protol.equals("telnet")) {
if(null != protocolPort && !"".equals(protocolPort)){
tt = new TelnetThread(ipAddr, Integer.parseInt(protocolPort), user, passwd);
}else{
tt = new TelnetThread(ipAddr, 23, user, passwd);
}
} else {
if(null != protocolPort && !"".equals(protocolPort)){
tt = new SSHThread(ipAddr, Integer.parseInt(protocolPort), user, passwd);
}else{
tt = new SSHThread(ipAddr, 22, user, passwd);
}
}
tt.initial();
this.isConnect = tt.isAuthorized();
}
public Vector getConfig(HashMap params) {
// 保存采集结果,并返回值
CollBase collResult = new CollBase();
try {
init(params);
String totalUnitId = this.PRE_UNITID + "-10:" + neat_host_name + "-total";
if(!tt.isAuthorized()){
collResult.addKPI(totalUnitId, "FM-00-01-001-06", "Disconnect");
return collResult.KPISet;
}else{
collResult.addKPI(totalUnitId, "FM-00-01-001-06", "UP");
}
Vector diskInfo = tt.getResultAsVector("swift-recon -d | grep 'Disk usage:'");
String diskSpace = split((String) diskInfo.elementAt(0), 6);
// 存储配置容量 CM-00-05-002-01
collResult.addKPI(totalUnitId, "CM-00-05-002-01", Formater.formatDecimalKpivalue(String.valueOf(Double.valueOf(diskSpace) / 1024 / 1024 / 1024 / 1024)));
String diskUsed = split((String) diskInfo.elementAt(2), 7);
// 存储空间使用百分比 PM-40-04-001-12
collResult.addKPI(totalUnitId, "PM-40-04-001-12", Formater.formatDecimalKpivalue(diskUsed.substring(0, diskUsed.length() - 1)));
} catch (Exception e) {
e.printStackTrace();
} finally {
release();
}
return collResult.getKPISet();
}
public Vector getSocket(HashMap params) {
// 保存采集结果,并返回值
CollBase collResult = new CollBase();
try {
init(params);
String totalUnitId = this.PRE_UNITID + "-20:" + neat_host_name + "-socket";
if (!tt.isAuthorized()) {
return collResult.KPISet;
}
Vector socketInfo = tt.getResultAsVector("swift-recon --sockstat | grep avg");
for (int i = 0; i < socketInfo.size(); i++) {
String _socketInfo = (String) socketInfo.elementAt(i);
String socketKey = split(_socketInfo, 0);
String socketAvgValue = split(_socketInfo, 6);
if (socketKey.contains("[tcp_in_use]")) {
// tcp_in_use TCP使用 PM-00-08-001-01
collResult.addKPI(totalUnitId, "PM-00-08-001-01", socketAvgValue.substring(0, socketAvgValue.length() - 1));
} else if (socketKey.contains("[time_wait]")) {
// time_wait 等待时间 PM-00-08-001-02
collResult.addKPI(totalUnitId, "PM-00-08-001-02", socketAvgValue.substring(0, socketAvgValue.length() - 1));
} else if (socketKey.contains("[tcp6_in_use]")) {
// tcp6_in_use TCP6使用 PM-00-08-001-03
collResult.addKPI(totalUnitId, "PM-00-08-001-03", socketAvgValue.substring(0, socketAvgValue.length() - 1));
} else if (socketKey.contains("[tcp_mem_allocated_bytes]")) {
// tcp_mem_allocated_bytes TCP内存分配的字节 PM-00-08-001-04
collResult.addKPI(totalUnitId, "PM-00-08-001-04", socketAvgValue.substring(0, socketAvgValue.length() - 1));
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
release();
}
return collResult.getKPISet();
}
public Vector getLoad(HashMap params) {
// 保存采集结果,并返回值
CollBase collResult = new CollBase();
try {
init(params);
String totalUnitId = this.PRE_UNITID + "-21:" + neat_host_name + "-load";
if (!tt.isAuthorized()) {
return collResult.KPISet;
}
Vector socketInfo = tt.getResultAsVector("swift-recon -l | grep m_load_avg");
for (int i = 0; i < socketInfo.size(); i++) {
String _socketInfo = (String) socketInfo.elementAt(i);
String socketKey = split(_socketInfo, 0);
String socketAvgValue = split(_socketInfo, 6);
if (socketKey.contains("[1m_load_avg]")) {
// 1m_load_avg TCP使用 PM-00-08-002-01
collResult.addKPI(totalUnitId, "PM-00-08-002-01", socketAvgValue.substring(0, socketAvgValue.length() - 1));
} else if (socketKey.contains("[5m_load_avg]")) {
// 5m_load_avg 等待时间 PM-00-08-002-02
collResult.addKPI(totalUnitId, "PM-00-08-002-02", socketAvgValue.substring(0, socketAvgValue.length() - 1));
} else if (socketKey.contains("[15m_load_avg]")) {
// 15m_load_avg TCP6使用 PM-00-08-002-03
collResult.addKPI(totalUnitId, "PM-00-08-002-03", socketAvgValue.substring(0, socketAvgValue.length() - 1));
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
release();
}
return collResult.getKPISet();
}
public String split(String str, int pos) {
StringTokenizer st = new StringTokenizer(str);
Vector values = new Vector();
while (st.hasMoreTokens()) {
values.add(st.nextToken());
}
if (pos >= 0 && pos < values.size()) {
return (String) values.elementAt(pos);
}
return "";
}
public void release() {
if (tt != null){
tt.close();
tt=null;
}
System.gc();
}
}