CollLinuxHost.java
5.11 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
package com.sitech.ismp.coll.host;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Vector;
import com.sitech.ismp.coll.basic.TblATO_KPIDETAIL;
public class CollLinuxHost implements CollLinuxHostMBean {
public Vector<TblATO_KPIDETAIL> getConfig(HashMap<String, String> params) {
Vector<TblATO_KPIDETAIL> result = new Vector<TblATO_KPIDETAIL>();
CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();
CollLinuxWithCMDByCron collByCron = new CollLinuxWithCMDByCron();
result.addAll(coll.collBaseInfo(params));
result.addAll(coll.collCpuInfo(params));
result.addAll(coll.collMemSize(params));
result.addAll(coll.collOsVersion(params));
// result.addAll(coll.collInterface(params));
result.addAll(coll.collSwap(params));
result.addAll(collByCron.getConfig(params));
return result;
}
public Vector<TblATO_KPIDETAIL> getCpu(HashMap<String, String> params) {
CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();
return coll.collCpu(params);
}
public Vector<TblATO_KPIDETAIL> getDisk(HashMap<String, String> params) {
CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();
return coll.collDisk(params);
}
public Vector<TblATO_KPIDETAIL> getDiskByCron(HashMap<String, String> params) {
CollLinuxWithCMDByCron coll = new CollLinuxWithCMDByCron();
return coll.collDisk(params);
}
public Vector<TblATO_KPIDETAIL> getFileSystem(HashMap<String, String> params) {
CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();
return coll.collFileSystem(params);
}
public Vector<TblATO_KPIDETAIL> getMemory(HashMap<String, String> params) {
CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();
return coll.collMemory(params);
}
public Vector<TblATO_KPIDETAIL> getUnavailableCpu(HashMap<String, String> params){
CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();
return coll.getUnavailableCpu(params);
}
public Vector<TblATO_KPIDETAIL> getUnavailableMem(HashMap<String, String> params){
CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();
return coll.getUnavailableMem(params);
}
public Vector<TblATO_KPIDETAIL> collIO(HashMap<String, String> params){
CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();
return coll.collIO(params);
}
public void getHapervisor(HashMap<String, String> params){
CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();
coll.getHapervisor(params);
}
public Vector<TblATO_KPIDETAIL> getVMInfo(HashMap<String, String> params){
CollLinuxHostWithCMD coll = new CollLinuxHostWithCMD();
return coll.collVMInfo(params);
}
public Vector<TblATO_KPIDETAIL> getProcessTop10(HashMap<String, String> params) {
CollLinuxWithCMDByCron coll = new CollLinuxWithCMDByCron();
return coll.getProcessTop10(params);
}
public Vector<TblATO_KPIDETAIL> getProcessByKey(HashMap<String, String> params) {
CollLinuxWithCMDByCron coll = new CollLinuxWithCMDByCron();
return coll.getProcessByKey(params);
}
@Override
public Vector<TblATO_KPIDETAIL> getNet(HashMap<String, String> params) {
CollLinuxWithCMDByCron coll = new CollLinuxWithCMDByCron();
Vector<TblATO_KPIDETAIL> result = new Vector<TblATO_KPIDETAIL>();
result.addAll(coll.collInterface(params));
result.addAll(coll.getNet(params));
// return coll.getNet(params);
return result;
}
/**
* 采集文件变更指标
*/
@Override
public Vector<TblATO_KPIDETAIL> getFileChange(HashMap<String, String> params) {
CollLinuxWithCMDByCron cmd = new CollLinuxWithCMDByCron();
return cmd.getFileChange(params);
}
public static void main(String[] args) {
System.out
.println("***************Linux Collect Test Begin*********************");
String methodStr = read("METHOD(0:getAll, 1:getConfig, 2:getCpu, 3:getMemory, 4:getDisk, 5:getFileSystem):\n");
HashMap<String, String> params = new HashMap<String, String>();
int method = Integer.parseInt(methodStr);
Vector<TblATO_KPIDETAIL> result = new Vector<TblATO_KPIDETAIL>();
CollLinuxHost collector = new CollLinuxHost();
switch (method) {
case 0:
result.addAll(collector.getConfig(params));
result.addAll(collector.getCpu(params));
result.addAll(collector.getMemory(params));
result.addAll(collector.getDisk(params));
result.addAll(collector.getFileSystem(params));
break;
case 1:
result.addAll(collector.getConfig(params));
break;
case 2:
result.addAll(collector.getCpu(params));
break;
case 3:
result.addAll(collector.getMemory(params));
break;
case 4:
result.addAll(collector.getDisk(params));
break;
case 5:
result.addAll(collector.getFileSystem(params));
break;
default:
break;
}
System.out
.println("***************Linux Collect Test End*********************");
System.out.println();
for (int i = 0; i < result.size(); i++) {
TblATO_KPIDETAIL record = (TblATO_KPIDETAIL) result.get(i);
System.out.println(record.UNIT_ID + "\t" + record.KPI_ID + "\t"
+ record.KPI_VALUE);
}
}
private static String read(String prompt) {
Scanner scanner = new Scanner(System.in);
System.out.print(prompt);
return scanner.nextLine();
}
}