CollHost.java
11.7 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
package com.sitech.ismp.coll.tivoli.linux;
import java.util.*;
import com.sitech.ismp.coll.CollBase;
import com.sitech.util.JSONUtil;
import org.apache.log4j.Logger;
import com.sitech.util.Formater;
/**
* 该类只采集 规范中的 ibm提供采集方法的 主机相关指标
*
* @author winnerbao
*
*/
public class CollHost {
private boolean debug = false;
private SoapClient soapClient = null;
private String pre_unitid = "";
private Logger logger = Logger.getLogger("COLL");
/**
*
* @param linux采集
* */
public CollHost(String pre_unit) {
this.pre_unitid = pre_unit;
//
String url = SoapParam.getString("SOAP_URL");
soapClient = new SoapClient(url);
}
//cpu 及内存使用率指标采集
public Vector getPerformance_Ten_Minute(java.util.HashMap params)
throws Exception {
String host_name = (String) params.get("HOST_NAME");
String neat_host_name = Formater.neatenunitid(host_name);
String soap_host_name = SOAPITCMNameHelper.getSoapHostName(host_name);
com.sitech.ismp.coll.CollBase collResult = new com.sitech.ismp.coll.CollBase();
String Used_Real_Mem_Pct = "";
String Swap_Used_Pct="";
try {
// 采集PM-00-01-01-01/02/03/04/05
// object=SMP_CPU
System.out.println(new Date());
String soap_cpu_SMPCPU = CollHostSoapHelper
.getSoap_cpu_SMPCPU(soap_host_name); // soap消息
String soap_cpu_SMPCPU_res = soapClient
.getSoapStringResponse(soap_cpu_SMPCPU);
System.out.println(new Date());
if (debug)
System.out.println(new Date() + soap_cpu_SMPCPU_res);
if (soap_cpu_SMPCPU_res.indexOf("faultstring") != -1) {
collResult.addKPI("10-10-991:" + neat_host_name + "-kux",
"FM-10-10-991-01", "DOWN");
} else {
collResult.addKPI("10-10-991:" + neat_host_name + "-kux",
"FM-10-10-991-01", "UP");
}
List cpu_results = CollHostXmlHelper
.parseSoapResponse(soap_cpu_SMPCPU_res);
Map cpu_aggregate = null;
// 得到 CPU_ID=aggregate 的那个 aggregate
for (int i = 0; i < cpu_results.size(); i++) {
Map cpu = (Map) cpu_results.get(i);
String cpu_id = (String) cpu.get("CPU_ID");
if (cpu_id.equals("Aggregate")) {
cpu_aggregate = cpu;
break;
}
}
if (cpu_aggregate == null) {
System.out
.println("@tivoli , no cpu info got by tivoli in collCpu "
+ new Date());
} else {
collResult.addKPI(
pre_unitid + "-11:" + neat_host_name + "-cpu",
"PM-00-01-001-05", (String) cpu_aggregate
.get("Busy_CPU"));
}
} catch (Exception e) {
logger.error("collhost cpu error");
e.printStackTrace();
}
try {
String soap_filesystem_System = CollHostSoapHelper
.getSoap_Unix_Memory(soap_host_name); // soap消息
String soap_filesystem_System_res = soapClient
.getSoapStringResponse(soap_filesystem_System);
List system_results = CollHostXmlHelper
.parseSoapResponse(soap_filesystem_System_res);
if (system_results == null || system_results.size() < 1) {
System.out
.println("@tivoli , no Unix_Memory info got by tivoli in collFileSystem"
+ new Date());
} else {
// 该结果中,肯定只有一条记录,这是由tivoli机制所保证的
Map system_map = (Map) system_results.get(0);
Used_Real_Mem_Pct = (String) system_map
.get("Memory_Used_Pct");
Swap_Used_Pct = (String) system_map
.get("Swap_Used_Pct");
collResult.addKPI(pre_unitid + "-12:" + neat_host_name
+ "-memory", "PM-00-01-002-01", getByScale(String
.valueOf(Used_Real_Mem_Pct)));
collResult.addKPI(pre_unitid + "-10:" + neat_host_name
+ "-total", "PM-00-01-004-02", Formater
.formatDecimalKpivalue(String
.valueOf(Swap_Used_Pct)));
}
} catch (Exception e) {
logger.error("collhost memory error");
e.printStackTrace();
}
return collResult.getKPISet();
}
/**
* 获得用户关注的文件系统,需要对这些文件系统的挂载状态监控
* @param params
* @return
*/
private Vector collFsMountState(HashMap params, Map<String, String> fsUnitIdMap) {
CollBase kpis = new CollBase();
try{
if (null == params.get("FS_FILTER")) {
return kpis.getKPISet();
}
List<String> fsConfList = (List<String>) JSONUtil.fromJSON((String) params.get("FS_FILTER"));
if (null != fsConfList && !fsConfList.isEmpty()) {
for (String fsUnitId : fsConfList) {
if (fsUnitIdMap.containsKey(fsUnitId)) {
kpis.addKPI(fsUnitId, "FM-00-01-004-01",
"OK");
} else {
kpis.addKPI(fsUnitId, "FM-00-01-004-01",
"unmount");
}
}
}
}catch (Exception e){
logger.error("Exception while collFsMountState", e);
}
return kpis.getKPISet();
}
public Vector getPerformance_Fifteen_Minute(
java.util.HashMap params) throws Exception {
String host_name = (String) params.get("HOST_NAME");
String ua_host_name = UaHostHelper.getUaHostName(host_name);
String neat_host_name = Formater.neatenunitid(host_name);
String soap_host_name = SOAPITCMNameHelper.getSoapHostName(host_name);
com.sitech.ismp.coll.CollBase collResult = new com.sitech.ismp.coll.CollBase();
try {
// 得到soap请求
String soap_filesystem_Disk = CollHostSoapHelper
.getSoap_filesystem_Disk(soap_host_name); // soap消息
// 发送soap请求,并返回结果
String soap_filesystem_Disk_res = soapClient
.getSoapStringResponse(soap_filesystem_Disk);
// 分析返回结果,得到list
List disk_results = CollHostXmlHelper
.parseSoapResponse(soap_filesystem_Disk_res);
// 获取每个文件系统的kpi值,顺便计算总的文件系统大小和总的已使用文件系统大小
long total_filesystem = 0;
long used_filesystem = 0;
if (disk_results == null || disk_results.size() < 1) {
System.out
.println("@tivoli , no System info got by tivoli in disk : "
+ new Date());
if (soap_filesystem_Disk_res.indexOf("faultstring") == -1) {
collResult.addKPI("10-10-991:" + neat_host_name + "-Disk",
"FM-10-10-03", "0");
}
} else {
collResult.addKPI("10-10-991:" + neat_host_name + "-Disk",
"FM-10-10-03", "1");
// 保存本次采集到的文件系统UNIT_ID
Map<String, String> fsUnitIdMap = new HashMap<String, String>();
for (int i = 0; i < disk_results.size(); i++) {
Map diskMap = (Map) disk_results.get(i);
String Mount_Point = (String) diskMap.get("Mount_Point");
String Space_Used_Percent = (String) diskMap
.get("Disk_Used_Percent");
if (Mount_Point == null || "".equals(Mount_Point.trim())) {
continue;
}
String neatMount_Point = Formater.neatenunitid(Mount_Point);
String unitId = pre_unitid + "-14:" + neat_host_name
+ "-" + neatMount_Point;
collResult.addKPI(unitId, "PM-00-01-004-03",
Space_Used_Percent);
fsUnitIdMap.put(unitId, unitId);
}
// 采集文件系统挂载状态
collResult.addKPISet(collFsMountState(params, fsUnitIdMap));
}
} catch (Exception e) {
logger.error("collhost total error == " + host_name, e);
e.printStackTrace();
}
return collResult.getKPISet();
}
public Vector getFailure(java.util.HashMap params)
throws Exception {
String host_name = (String) params.get("HOST_NAME");
String ha_host_name = HaHostHelper.getHaHostName(host_name);
String neat_host_name = Formater.neatenunitid(host_name);
com.sitech.ismp.coll.CollBase collResult = new com.sitech.ismp.coll.CollBase();
int count1 = 0;
int count2 = 0;
String status3 = "DOWN";
try {
String bnms1_status = CollHostSoapHelper
.getSoap_PINGSERVERSPINGSTATS00_From_bnms1(ha_host_name);
String bnms2_status = CollHostSoapHelper
.getSoap_PINGSERVERSPINGSTATS00_From_bnms2(ha_host_name);
String bnms3_status = CollHostSoapHelper
.getSoap_PINGSERVERSPINGSTATS00_From_bnms3(ha_host_name);
System.out.println(new Date());
String bnms1_status_res = soapClient
.getSoapStringResponse(bnms1_status);
String bnms2_status_res = soapClient
.getSoapStringResponse(bnms2_status);
String bnms3_status_res = soapClient
.getSoapStringResponse(bnms3_status);
List bnms1_status_result31 = CollHostXmlHelper
.parseSoapResponse(bnms1_status_res);
List bnms2_status_result32 = CollHostXmlHelper
.parseSoapResponse(bnms2_status_res);
List bnms3_status_result33 = CollHostXmlHelper
.parseSoapResponse(bnms3_status_res);
System.out.println(new Date());
if (bnms1_status_result31 == null
|| bnms1_status_result31.size() == 0) {
collResult.addKPI("10-10-991:bnas1_" + host_name + "-total",
"FM-10-10-991-02", "bnas1 PING " + host_name
+ " NULL RESPONSE");
count1++;
} else {
Map statusMap = (Map) bnms1_status_result31.get(0);
status3 = ((String) statusMap.get("Status")).toUpperCase();
if (status3.equalsIgnoreCase("DOWN")) {
count2++;
}
}
if (bnms2_status_result32 == null
|| bnms2_status_result32.size() == 0) {
collResult.addKPI("10-10-991:bnas2_" + host_name + "-total",
"FM-10-10-991-02", "bnas2 PING " + host_name
+ " NULL RESPONSE");
count1++;
} else {
Map statusMap = (Map) bnms2_status_result32.get(0);
status3 = ((String) statusMap.get("Status")).toUpperCase();
if (status3.equalsIgnoreCase("DOWN")) {
count2++;
}
}
if (bnms3_status_result33 == null
|| bnms3_status_result33.size() == 0) {
collResult.addKPI("10-10-991:bnas3_" + host_name + "-total",
"FM-10-10-991-02", "bnas3 PING " + host_name
+ " NULL RESPONSE");
count1++;
} else {
Map statusMap = (Map) bnms3_status_result33.get(0);
status3 = ((String) statusMap.get("Status")).toUpperCase();
if (status3.equalsIgnoreCase("DOWN")) {
count2++;
}
}
System.out.println(count1);
if (count1 < 3) {
if (count2 == (3 - count1)) {
// down
collResult.addKPI(pre_unitid + "-10:" + neat_host_name
+ "-total", "FM-00-01-001-01", "DOWN");
System.out.println("down1");
} else {
// up
collResult.addKPI(pre_unitid + "-10:" + neat_host_name
+ "-total", "FM-00-01-001-01", "UP");
System.out.println("up1");
}
} else {
System.out.println("up2");
}
} catch (Exception e) {
logger.error("collhost getFailure error");
e.printStackTrace();
}
return collResult.getKPISet();
}
/**
*
* 得到指定精度的double类型数值 精度设定为4
*
* @param double_vlaue
* @return
*/
private String getByScale(String double_value) {
int scale = 4;
return Formater.getByScale(double_value, 2);
}
public static void main(String[] args) throws Exception {
CollHost aix = new CollHost("10-10-20");
java.util.HashMap params = new java.util.HashMap();
params.put("HOST_NAME", "linux1");
Vector v = new Vector();
String aa = "aaaaaasoap_cpu_SMPCPU_resaaa";
aix.getFailure(params);
System.out.println(aa.indexOf("wq"));
// v.addAll(aix.getConfiguration_One_Day(params));
//v.addAll(aix.getPerformance_Ten_Minute(params));
//v.addAll(aix.getPerformance_Ten_Minute(params));
// v.addAll(aix.getPerformance_Fifteen_Minute(params));
// v.addAll(aix.getPerformance_One_Hour(params));
// v.addAll(aix.getPerformance_Ten_Minute(params));
// String temp[][] = CheckKPIHelper.Check_AIX_HOST_KPI(v);
// for(int i=0;i<temp.length;i++)
// {
// System.out.println("KPI_ID : " + temp[i][0] + "---" + temp[i][1]);
//}
//String filename = "test1.xls";
//CheckKPIHelper.Write_KPIValue2File(v, filename);
}
}