CollLinuxHost.java
7.72 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
package com.sitech.ismp.coll.centercoll;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Vector;
import com.sitech.ismp.coll.basic.TblATO_KPIDETAIL;
import com.sitech.util.DES3;
public class CollLinuxHost implements CollLinuxHostMBean {
public Vector collLinux(HashMap params) {
CollLinuxWithCMD cmd = new CollLinuxWithCMD();
return cmd.collLinux(params);
}
public Vector getConfig(HashMap params) {
CollLinuxWithCMD cmd = new CollLinuxWithCMD();
return cmd.getConfig(params);
}// end getConfig
public Vector getCpu(HashMap params) {
CollLinuxWithCMD cmd = new CollLinuxWithCMD();
return cmd.getCpu(params);
}
public Vector getMemory(HashMap params) {
CollLinuxWithCMD cmd = new CollLinuxWithCMD();
return cmd.getMemory(params);
}
public Vector getDisk(HashMap params) {
CollLinuxWithCMD cmd = new CollLinuxWithCMD();
return cmd.getDisk(params);
}// end getDisk
public Vector getFileSystem(HashMap params) {
CollLinuxWithCMD cmd = new CollLinuxWithCMD();
return cmd.getFileSystem(params);
}
public Vector getUserProNum(HashMap params) {
CollLinuxWithCMD cmd = new CollLinuxWithCMD();
return cmd.getUserProNum(params);
}
public Vector getSyslog(HashMap params) {
CollLinuxWithCMD cmd = new CollLinuxWithCMD();
return cmd.getSyslog(params);
}
public Vector getSpecProcess(HashMap params) {
CollLinuxWithCMD cmd = new CollLinuxWithCMD();
return cmd.getSpecProcess(params);
}
public Vector getBusiProcess(HashMap params) {
CollLinuxWithCMD cmd = new CollLinuxWithCMD();
return cmd.getBusiProcess(params);
}
public Vector getPortListenings(HashMap params) {
CollLinuxWithCMD cmd = new CollLinuxWithCMD();
return cmd.getPortListenings(params);
}
@Override
public Vector getProcessTop5Cpu(HashMap params) {
CollLinuxWithCMD cmd = new CollLinuxWithCMD();
return cmd.getProcessTop5Cpu(params);
}
@Override
public Vector getProcessTop5Mem(HashMap params) {
CollLinuxWithCMD cmd = new CollLinuxWithCMD();
return cmd.getProcessTop5Mem(params);
}
public Vector getSyslogBylogPathUseGrep(HashMap params) {
CollLinuxWithCMD cmd = new CollLinuxWithCMD();
return cmd.getSyslogBylogPathUseGrep(params);
}
public Vector getPing(HashMap params) {
CollLinuxWithCMD cmd = new CollLinuxWithCMD();
return cmd.getPing(params);
}
public Vector getDemsg(HashMap params) {
CollLinuxWithCMD cmd = new CollLinuxWithCMD();
return cmd.getDemsg(params);
}
public Vector getNet(HashMap params) {
CollLinuxWithCMD cmd = new CollLinuxWithCMD();
return cmd.getNet(params);
}
public static void main(String[] args) {
System.out
.println("***************Linux Center Collect Test Begin*********************");
//System.out.println(DES3.decrypt("cloud"));
// String ipAddr = "172.21.3.38";
// String username = "root";
// String password = "111111";
// String protocal = "ssh";
// String hostName = "app-123";
String ipAddr = "172.21.0.201";
String username = "ssdbomc";
String password = "bomcssd";
String protocal = "ssh";
String hostName = "172_21_0_201";
String processName = "pf,tomcat";
String listeningPort = "22,48781";
String correctListening = "1,1";
String pingIp = "172.21.0.201";
String pingUsername = "ssdbomc";
String pingPwd = "bomcssd";
String pingProtocal = "ssh";
String pointIPs = "172.21.0.31,172.21.0.203";
String demsgKey = "Detected Tx Unit Hang";
// String ipAddr = read("IP_ADDR(remote host ip):\n");
// String username = read("USERNAME:\n");
// String password = read("PASSWORD:\n");
// String protocal = read("PROTOCAL(ssh/telent):\n");
// String hostName = read("HOST_NAME(remote host name):\n");
// String processName = read("PROCESS_NAME:\n");
// String listeningPort = read("LISTENING_PORT:\n");
// String correctListening = read("CORRECT_LISTENING:\n");
// String methodStr = read("METHOD(0:getAll, 1:getConfig, 2:getCpu, 3:getMemory, 4:getDisk, " +
// "5:getFileSystem, 6:getPortListenings, 7:getBusiProcess, 8:getProcessTop5Mem, 9:getProcessTop5Cpu):\n");
String methodStr = "13";
System.out.println("IP_ADDR=" + ipAddr + ", USERNAME=" + username
+ ", PASSWORD=" + password + ", PROTOTAL=" + protocal
+ ", HOST_NAME=" + hostName + ", METHOD=" + methodStr);
HashMap<String, String> params = new HashMap<String, String>();
params.put("IP_ADDR", ipAddr);
params.put("USERNAME", username);
params.put("PASSWORD", DES3.encrypt(password));
params.put("PROTOCOL", protocal);
params.put("HOSTNAME", hostName);
params.put("PROCESS_NAME", processName);
params.put("LISTENING_PORT", listeningPort);
params.put("CORRECT_LISTENING", correctListening);
params.put("PING_IP_ADDR",pingIp);
params.put("PING_USERNAME",pingUsername);
params.put("PING_PASSWORD",DES3.encrypt(pingPwd));
params.put("PING_PROTOCOL",pingProtocal);
params.put("POINT_IPS", pointIPs);
params.put("DEMSG_KEY", demsgKey);
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));
result.addAll(collector.getPortListenings(params));
result.addAll(collector.getBusiProcess(params));
result.addAll(collector.getProcessTop5Mem(params));
result.addAll(collector.getProcessTop5Cpu(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;
case 6:
result.addAll(collector.getPortListenings(params));
break;
case 7:
result.addAll(collector.getBusiProcess(params));
break;
case 8:
result.addAll(collector.getProcessTop5Mem(params));
break;
case 9:
result.addAll(collector.getProcessTop5Cpu(params));
break;
case 10:
result.addAll(collector.getDemsg(params));
break;
case 11:
result.addAll(collector.getPing(params));
break;
case 12:
result.addAll(collector.getUserProNum(params));
break;
case 13:
result.addAll(collector.getNet(params));
break;
default:
break;
}
System.out
.println("***************Linux Center 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);
String insSql = "INSERT INTO TB_ATO_KPIDETAIL (KPI_ID, UNIT_ID, CLL_TIME, KPI_VALUE, EXT_INFO, DB_TIME, EXT_UNIT_ID, `INTERVAL`) " +
"VALUES ('#KPI_ID#', '#UNIT_ID#', now(), '#KPI_VALUE#', null, now(), '10-10-24:172_21_0_201', #INTERVAL#);";
insSql = insSql.replace("#KPI_ID#", record.KPI_ID);
insSql = insSql.replace("#UNIT_ID#", record.UNIT_ID);
insSql = insSql.replace("#KPI_VALUE#", record.KPI_VALUE);
insSql = insSql.replace("#INTERVAL#", record.INTERVAL);
System.out.println(insSql);
}
}
private static String read(String prompt) {
Scanner scanner = new Scanner(System.in);
System.out.print(prompt);
return scanner.nextLine();
}
}