CollScoUnix.java
22.3 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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
package com.sitech.ismp.coll;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;
import org.apache.log4j.Logger;
import com.sitech.ismp.app.coll.RPCTarget;
import com.sitech.util.Formater;
/**
* @author maozr �İ汾�� ��IBM��HP���ɼ�ָ��Ķ���λһ��,���ڴ��Сָ�꣨CM-00-01-001-07���ɼ�����ֵ��M
*/
public class CollScoUnix implements CollScoUnixMBean {
private Logger logger = Logger.getLogger("COLL");
String PRE_UNITID = "10-10-26"; // Sco-Unix ���ı�ʶ
RPCTarget rpctarget = new RPCTarget();
private String getHostName() {
Vector host = execute("uname -a");
String host_name = (String) host.elementAt(0);
host_name = split(host_name, 1);
return host_name;
}
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 init(HashMap params) {
rpctarget = new RPCTarget();
rpctarget.setRpcCmd("lexe_hp");
}
public Vector getConfig(HashMap params) {
// ����ɼ��������ֵ
CollBase collResult = new CollBase();
// �������õ���kpiֵ��unit_id,����PRE_UNITID + "-10"��ͷ�����Total���
String config_PRE_UNITID = PRE_UNITID + "-10"; // totalֵ
// ��ȡ������
Vector host = execute("uname -a");
String host_name = (String) host.elementAt(0);
String os_version = split((String) host.elementAt(0), 2);
host_name = collResult.split(host_name, 1);
// �õ�unit_id��ʹ�õ�������
String neat_host_name = Formater.neatenunitid(host_name);
// ��Ӳɼ�ʱ��ָ��
String pattern = "yyyy-MM-dd-HH-mm-ss";
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
"CM-00-01-001-22", dateFormat.format(new java.util.Date()));
// ����ip,���ڸ澯����
collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
"CM-00-01-001-50", (String) params.get("IP_ADDR"));
// ������
collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
"CM-00-01-001-01", host_name);
// �������
collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
"CM-00-01-001-03", "Sco-Unix");
// ----cpu��Ϣ �� CM-00-01-001-04(����)/05(�ͺ�)/06(��Ƶ)-----
Vector cpunumV = execute("sh sco/cpucount.sh");
// 1 CM-00-01-001-04 cpu����
String cpu_size = String.valueOf(cpunumV.size());
collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
"CM-00-01-001-04", Formater.formatDecimalKpivalue(cpu_size));
// 2 CM-00-01-001-05 cpu����
Vector cputypeV = execute("sh sco/cputype.sh");
String cpu_type = (String) cputypeV.elementAt(0);
collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
"CM-00-01-001-05", cpu_type.trim());
// 3 CM-00-01-001-06 cpu��Ƶ
Vector cpuclockV = execute("sh sco/cpuclock.sh");
String cpu_clock = (String) cpuclockV.elementAt(0);
collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
"CM-00-01-001-06", cpu_clock.trim());
Vector filerate_result = execute("sh sco/mem.sh");
String filerate_string = (String) filerate_result
.elementAt(filerate_result.size() - 1);
String sub_msg[] = this.split2Array(filerate_string, " ");
String sum = sub_msg[0].trim();
float value = Float.parseFloat(sum) / 1000; // 2009-1-17, maozr�и�,��λ��M
collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
"CM-00-01-001-07", Formater.formatDecimalKpivalue(Float
.toString(value)));
// ������ϵͳ�汾 CM-00-01-001-08
collResult.addKPI(config_PRE_UNITID + ":" + neat_host_name + "-total",
"CM-00-01-001-08", os_version);
/*
* �����ɼ�,���ɼ����ָ��: ϵͳ����ӿ�IP(CM-00-01-001-11),
* ϵͳ����ӿ������ַ(CM-00-01-001-12), �����״̬(FM-00-01-001-03)
* unit_idΪ:10-10-21-16:�����-����
*/
Vector lan = execute("/etc/ifconfig -a");
int size = lan.size();
String net_unit = "10-10-26-16:" + neat_host_name;
String ip_addr = "local";
String phy_addr = "local";
String state = "down";
String network_name = "";
boolean phy_pass = true;
boolean ip_pass = true;
boolean state_pass = true;
boolean hard_pass = true;
try {
// ����ַ��־λ����ָ���ȡ
for (int i = 0; i < size; i++) {
String network = (String) lan.elementAt(i);
// �����
int hard_flag = network.indexOf("flags");
if (hard_flag != -1 && hard_pass) {
network_name = network.substring(0,
network.indexOf("flags")).trim();
network_name = network_name.substring(0, network_name
.indexOf(":"));
net_unit = net_unit + "-" + network_name;
hard_pass = false;
}
// �������ַ��ȡ
int phy_flag = network.indexOf("ether");
if (phy_flag != -1 && phy_pass) {
phy_addr = network.substring(network.indexOf("ether") + 6)
.trim();
phy_pass = false;
}
// ��ȡ���IP��ַ
int ip_flag = network.indexOf("inet");
if (ip_flag != -1 && ip_pass) {
// int index = network.indexOf("Bcast");
// int inde1 = network.indexOf("Mask");
//
// int tmp =(index == -1)?inde1:index;
int tmp = network.indexOf("netmask");
// ip_addr = network.substring(network.indexOf(":")+1, tmp);
ip_addr = network.substring(ip_flag + 4, tmp).trim();
ip_pass = false;
}
// ��ȡ��״̬
int state_flag = network.indexOf("recv size");
if (state_flag != -1 && state_pass) {
// String send =
// network.substring(network.indexOf(":")+1,network.indexOf("(")).trim();
String recv = network.substring(
network.indexOf("recv size") + 11,
network.indexOf(";")).trim();
float sendNUM = Float.parseFloat(recv);
if (sendNUM > 0) {
state = "up";
}
state_pass = false;
}
if (i + 1 == lan.size()
|| ((String) lan.elementAt(i + 1)).indexOf("flags") != -1) {
// �����
collResult
.addKPI(net_unit, "CM-00-01-001-40", network_name);
// ����������ַָ��
collResult.addKPI(net_unit, "CM-00-01-001-12", phy_addr);
// �����ip��ַָ��
collResult.addKPI(net_unit, "CM-00-01-001-11", ip_addr);
// ��״̬
collResult.addKPI(net_unit, "FM-00-01-001-03", state);
phy_pass = true;
ip_pass = true;
state_pass = true;
hard_pass = true;
ip_addr = "local";
phy_addr = "local";
state = "down";
network_name = "";
net_unit = "10-10-26-16:" + neat_host_name;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return collResult.getKPISet();
}
/**
* �ɼ�cpuָ��
*/
public Vector getCpu(HashMap params) {
logger.info("begin getCpu");
init(params);
System.out.println("begin getCPU");
// ����ɼ��������ֵ
CollBase collResult = new CollBase();
// �������õ���kpiֵ��unit_id,����PRE_UNITID + "-11"��ͷ�����cpu���
String cpu_PRE_UNITID = PRE_UNITID + "-11"; // totalֵ
System.out.println("col host name");
// ��ȡ������
String host_name = this.getHostName();
// �õ�unit_id��ʹ�õ�������
String neat_host_name = Formater.neatenunitid(host_name);
// ��Ӳɼ�ʱ��ָ��
String pattern = "yyyy-MM-dd-HH-mm-ss";
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
collResult.addKPI(cpu_PRE_UNITID + ":" + neat_host_name + "-cpu",
"CM-00-01-001-22", dateFormat.format(new java.util.Date()));
String value = ""; // ��ʱ��
Vector cpuout = execute("vmstat 1 3");
String cpurun = (String) cpuout.elementAt(cpuout.size() - 1);
// CPUʱ�䣺���аٷֱ�
collResult.addKPI(cpu_PRE_UNITID + ":" + neat_host_name + "-cpu",
"PM-00-01-001-01", Formater.formatDecimalKpivalue(collResult
.split(cpurun, 19)));
// CPUʱ�䣺ϵͳ�ٷֱ�
collResult.addKPI(cpu_PRE_UNITID + ":" + neat_host_name + "-cpu",
"PM-00-01-001-02", Formater.formatDecimalKpivalue(collResult
.split(cpurun, 18)));
// CPUʱ�䣺�û��ٷֱ�
collResult.addKPI(cpu_PRE_UNITID + ":" + neat_host_name + "-cpu",
"PM-00-01-001-03", Formater.formatDecimalKpivalue(collResult
.split(cpurun, 17)));
// cpu������, 100-idle
// value = String.valueOf(100 -
// Integer.parseInt(collResult.split(cpurun,
// 19)));
value = this.getCPU_Rate(3, 30);
collResult.addKPI(cpu_PRE_UNITID + ":" + neat_host_name + "-cpu",
"PM-00-01-001-05", value);
// CPU���ж����н�̸���
Vector vmstat_result = execute("vmstat 2 2");
String vmstat_string = (String) vmstat_result.elementAt(vmstat_result
.size() - 1);
value = collResult.split(vmstat_string, 0);
collResult.addKPI(cpu_PRE_UNITID + ":" + neat_host_name + "-cpu",
"PM-00-01-001-06", Formater.formatDecimalKpivalue(value));
// CPUʱ�䣺�ȴ�ٷֱ�
try {
Vector sar_cpuout = execute("sar -u 1 3");
String sar_cpurun = (String) sar_cpuout
.elementAt(cpuout.size() - 1);
value = split(sar_cpurun, 3);
collResult.addKPI(cpu_PRE_UNITID + ":" + neat_host_name + "-cpu",
"PM-00-01-001-04", Formater.formatDecimalKpivalue(value));
} catch (Exception e) {
logger.info("cpu�ɼ�����û��sar����!");
}
logger.info("end collCpu");
return collResult.getKPISet();
}
public Vector getDisk(HashMap params) {
logger.info("begin getActiveDisk");
init(params);
// ����ɼ��������ֵ
CollBase collResult = new CollBase();
// �������õ���kpiֵ��unit_id,����PRE_UNITID + "-13"��ͷ�����disk���
String disk_PRE_UNITID = PRE_UNITID + "-13";
// ��ȡ������
String host_name = this.getHostName();
// �õ�unit_id��ʹ�õ�������
String neat_host_name = Formater.neatenunitid(host_name);
// ��Ӳɼ�ʱ��ָ��
String pattern = "yyyy-MM-dd-HH-mm-ss";
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "",
"CM-00-01-001-22", dateFormat.format(new java.util.Date()));
String value = "";// ��ʱ��
try {
Vector diskV = execute("sar -d 5 5");
Set sarDiskSet = new HashSet(); // ��������sar������ȡ����io�豸���
for (int i = 0; i < diskV.size(); i++) {
String disk_value = (String) diskV.elementAt(i);
if (disk_value.indexOf("Average") < 0)
continue;
String disk_name = split(disk_value, 1);
sarDiskSet.add(disk_name);
// String sar_disk_state = (String)disk_stateMap.get(disk_name);
String neat_disk_name = Formater.neatenunitid(disk_name);
collResult.addKPI(PRE_UNITID + "-13" + ":" + neat_host_name
+ "-" + Formater.neatenunitid(disk_name),
"CM-00-01-001-20", disk_name);
// collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name +
// "-"
// + Formater.neatenunitid(disk_name), "FM-00-01-001-02",
// sar_disk_state);
// ��������IO��������
value = split(disk_value, 5);
collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "-"
+ neat_disk_name, "PM-00-01-003-01", Formater
.formatDecimalKpivalue(value));
// �ȴ����ϵͳ����߳���
value = split(disk_value, 3);
collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "-"
+ neat_disk_name, "PM-00-01-003-02", Formater
.formatDecimalKpivalue(value));
// ����æ�İٷֱ�
value = split(disk_value, 2);
collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "-"
+ neat_disk_name, "PM-00-01-003-03", Formater
.formatDecimalKpivalue(value));
// ÿ�������
value = split(disk_value, 4);
collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "-"
+ neat_disk_name, "PM-00-01-003-04", Formater
.formatDecimalKpivalue(value));
// ÿ��д����
value = split(disk_value, 4);
collResult.addKPI(disk_PRE_UNITID + ":" + neat_host_name + "-"
+ neat_disk_name, "PM-00-01-003-05", Formater
.formatDecimalKpivalue(value));
}
} catch (Exception e) {
logger.debug("disk �ɼ�ʱû��sar����");
}
return collResult.getKPISet();
}
public Vector getFileSystem(HashMap params) {
logger.info("begin getFileSystem");
init(params);
// ����ɼ��������ֵ
CollBase collResult = new CollBase();
// ��ȡ������
String host_name = this.getHostName();
// �õ�unit_id��ʹ�õ�������
String neat_host_name = Formater.neatenunitid(host_name);
// �ɼ����ļ�ϵͳռ����
Vector fileSystemV = execute("sh sco/filesys.sh");
int size = fileSystemV.size();
int max = 0;
try {
for (int i = 0; i < size; i++) {
String[] value = this.split2Array(
((String) fileSystemV.get(i)), " ");
String file_sys_name = value[0];
String rate = value[4].substring(0, value[4].indexOf("%"));
String disk_name = value[5];
String max_size = value[1];
String available = value[3];
float avaliavle_tmp = Float.parseFloat(available.trim()) / 1024;
max = max + Integer.parseInt(max_size.trim());
collResult.addKPI(PRE_UNITID + "-14:" + neat_host_name + "-"
+ Formater.neatenunitid(disk_name) + "-"
+ file_sys_name, "CM-00-01-001-16", disk_name);
collResult.addKPI(PRE_UNITID + "-14:" + neat_host_name + "-"
+ Formater.neatenunitid(disk_name) + "-"
+ file_sys_name, "PM-00-01-004-03", Formater
.formatDecimalKpivalue(rate));
collResult.addKPI(PRE_UNITID + "-14:" + neat_host_name + "-"
+ Formater.neatenunitid(disk_name) + "-"
+ file_sys_name, "PM-00-01-004-04", Formater
.formatDecimalKpivalue(Float.toString(avaliavle_tmp)));
}
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
}
// ���������
float value = Float.parseFloat(Integer.toString(max)) / 1000;
collResult.addKPI(PRE_UNITID + "-10" + ":" + neat_host_name + "-total",
"CM-00-01-001-09", Formater.formatDecimalKpivalue(Float
.toString(value)));
return collResult.getKPISet();
}
/**
*
* ��ȡ�����û��û������
*
* @param params
* @return
*/
public Vector getUserProNum(HashMap params) {
logger.info("begin getUserProNum ");
logger.info("begin getUserProName ");
init(params);
// ����ɼ��������ֵ
CollBase collResult = new CollBase();
// �õ������û����б?���û�����ֶ��ٴΣ��ͱ���ps��4�ж����У����ж��ٽ��
Vector userV = new Vector();
Vector processV = execute("sh sco/process.sh");
for (int i = 0; i < processV.size(); i++) {
String processInfo = (String) processV.elementAt(i);
userV.add(collResult.split(processInfo, 0));
}
processV = null;
if (userV == null || userV.size() == 0) {
return new Vector();
}
// �������û��Ľ������������map��
// user - user process numer
Map user_pronum = new HashMap();
// ���û�����Ȼ��������
java.util.Collections.sort(userV);
String userName = "";
for (int i = 0; i < userV.size(); i++) {
userName = ((String) userV.elementAt(i)).trim();
int pro_number = 1;
String nextUer = "";
for (int j = i + 1; j < userV.size(); j++) {
// ������һ���û�
nextUer = ((String) (userV.elementAt(j))).trim();
if (!userName.equals(nextUer)) {
i = j - 1;
break;
}
pro_number++;
}
user_pronum.put(userName, new Integer(pro_number));
}
// �������õ���kpiֵ��unit_id,����PRE_UNITID + "-10"��ͷ�����Total���
String pro_PRE_UNITID = PRE_UNITID + "-15"; // totalֵ
// ��ȡ������
String host_name = this.getHostName();
// �õ�unit_id��ʹ�õ�������
String neat_host_name = Formater.neatenunitid(host_name);
Set users = user_pronum.keySet();
// System.out.println("users------------"+users);
Iterator iter = users.iterator();
while (iter.hasNext()) {
String username = (String) iter.next();
// System.out.println("username------------"+username);
collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-"
+ Formater.neatenunitid(username), "PM-00-01-005-06",
((Integer) user_pronum.get(username)).toString());
collResult.addKPI(pro_PRE_UNITID + ":" + neat_host_name + "-"
+ Formater.neatenunitid(username), "CM-00-01-005-06",
Formater.neatenunitid(username));
}
return collResult.getKPISet();
}
/**
* �ɼ��ڴ�ָ��
*/
public Vector getMemory(HashMap params) {
logger.info("begin getMemory");
init(params);
// ����ɼ��������ֵ
CollBase collResult = new CollBase();
// �������õ���kpiֵ��unit_id,����PRE_UNITID + "-12"��ͷ
String memory_PRE_UNITID = PRE_UNITID + "-12";
// ��ȡ������
String host_name = this.getHostName();
// �õ�unit_id��ʹ�õ�������
String neat_host_name = Formater.neatenunitid(host_name);
// ��Ӳɼ�ʱ��ָ��
String pattern = "yyyy-MM-dd-HH-mm-ss";
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
collResult.addKPI(memory_PRE_UNITID + ":" + neat_host_name + "",
"CM-00-01-001-22", dateFormat.format(new java.util.Date()));
Vector vmstat_result = execute("vmstat 2 2");
String vmstat_string = (String) vmstat_result.elementAt(vmstat_result
.size() - 1);
String value = "";
value = split(vmstat_string, 5);
collResult.addKPI(memory_PRE_UNITID + ":" + neat_host_name + "-memory",
"PM-00-01-002-02", Formater.formatDecimalKpivalue(value));
value = split(vmstat_string, 14);
collResult.addKPI(memory_PRE_UNITID + ":" + neat_host_name + "-memory",
"PM-00-01-002-03", Formater.formatDecimalKpivalue(value));
value = split(vmstat_string, 13);
collResult.addKPI(memory_PRE_UNITID + ":" + neat_host_name + "-memory",
"PM-00-01-002-04", Formater.formatDecimalKpivalue(value));
value = split(vmstat_string, 0);
collResult.addKPI(memory_PRE_UNITID + ":" + neat_host_name + "-memory",
"PM-00-01-002-05", Formater.formatDecimalKpivalue(value));
try {
Vector filerate_result = execute("sh sco/mem.sh");
String filerate_string = (String) filerate_result
.elementAt(filerate_result.size() - 1);
String sub_msg[] = this.split2Array(filerate_string, " ");
String sum = sub_msg[0].trim();
String used = sub_msg[1].trim();
float _count = Float.parseFloat(sum);
float _free = Float.parseFloat(used);
float _used = _count - _free;
float _persent = (_used / _count) * 100;
String persent = Formater.formatDecimalKpivalue(String
.valueOf(_persent));
collResult.addKPI(memory_PRE_UNITID + ":" + neat_host_name
+ "-memory", "PM-00-01-002-08", persent);
Vector filerate_result_rate = execute("sh sco/memrate.sh");
String filerate_string_rate = (String) filerate_result_rate
.elementAt(filerate_result.size() - 1);
String all[] = this.split2Array(filerate_string_rate, ":");
String sum_ = all[0].trim();
String used_ = all[1].trim();
float rate_count = Float.parseFloat(sum_);
float rate_used = Float.parseFloat(used_);
float rate_persent = (rate_used / rate_count);
String rate_persent_value = Formater.formatDecimalKpivalue(String
.valueOf(rate_persent));
collResult.addKPI(memory_PRE_UNITID + ":" + neat_host_name
+ "-memory", "PM-00-01-002-01", rate_persent_value);
} catch (Exception e) {
logger.error(e);
}
logger.info("end getMemory");
return collResult.getKPISet();
}
public ArrayList split(String str, String sp) {
int ip = 0;
ArrayList al = new ArrayList();
ip = str.indexOf(sp);
if (ip != -1) {
al.add(str.substring(0, ip));
str = str.substring(ip + sp.length());
if (str.length() != 0) {
al.addAll(split(str, sp));
}
} else {
al.add(str);
}
return al;
}
public String[] split2Array(String str, String sp) {
ArrayList al = split(str, sp);
Object[] os = al.toArray();
String[] ss = new String[os.length];
for (int i = 0; i < os.length; i++) {
ss[i] = (String) os[i];
}
return ss;
}
// �ɼ�cpu������,���ɼ�times��,ÿ�βɼ����interval��
private String getCPU_Rate(int times, int interval) {
CollBase collResult = new CollBase();
float cpu_value = 0;
for (int i = 0; i < times; i++) {
Vector cpuout = execute("vmstat 1 3");
String cpurun = (String) cpuout.elementAt(cpuout.size() - 1);
cpu_value = (100 - Integer.parseInt(collResult.split(cpurun, 19)))
+ cpu_value;
try {
Thread.sleep(interval * 1000L);
} catch (Exception e) {
e.printStackTrace();
}
}
cpu_value = cpu_value / times;
return Formater.formatDecimalKpivalue(Float.toString(cpu_value));
}
// ִ�����ʼ
private Vector execute(String shellCommand) {
System.out.println("cmd:" + shellCommand);
Vector vResult = null;
try {
// shellCommand = "sh linux/"+shellCommand;
Process process = Runtime.getRuntime().exec(shellCommand);
vResult = new Vector();
BufferedReader reader = null;
reader = new BufferedReader(new InputStreamReader(process
.getInputStream()));
String line = reader.readLine();
while (line != null) {
vResult.addElement(line);
line = reader.readLine();
}
reader.close();
return vResult;
} catch (Exception e) {
logger.error("�ڱ����Ͽ���û�� " + shellCommand + " ����!");
} finally {
Runtime.getRuntime().freeMemory();
Runtime.getRuntime().gc();
}
return vResult;
}
}