CollMySQL.java
6.21 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
package com.sitech.ismp.coll;
import com.sitech.ismp.coll.basic.TblATO_KPIDETAIL;
import com.sitech.util.DES3;
import org.apache.log4j.Logger;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Vector;
/**
* Created with IntelliJ IDEA.
* User: mooker
* Date: 14-3-20
* Time: 下午1:27
* To change this template use File | Settings | File Templates.
*/
public class CollMySQL implements CollMySQLMBean {
private Logger logger = Logger.getLogger(CollMySQL.class);
@Override
public Vector<TblATO_KPIDETAIL> getSystem(HashMap<String, String> params) {
try {
CollMySQLBySql collector = new CollMySQLBySql();
return collector.getSystem(params);
} catch (Exception e) {
logger.error("Exception while getSystem", e);
return new Vector<TblATO_KPIDETAIL>();
}
}
/**
* 获取数据库jdbc的连接状态。
* @param params
* @return
*/
@Override
public Vector<TblATO_KPIDETAIL> getStatus(HashMap<String, String> params) {
try {
CollMySQLBySql collector = new CollMySQLBySql();
return collector.getStatus(params);
} catch (Exception e) {
logger.error("Exception while getStatus", e);
return new Vector<TblATO_KPIDETAIL>();
}
}
/**
* 获取数据库ping状态。
* @param params
* @return
*/
@Override
public Vector<TblATO_KPIDETAIL> getPingStatus(HashMap<String, String> params) {
try {
CollMySQLBySql collector = new CollMySQLBySql();
return collector.getPingStatus(params);
} catch (Exception e) {
logger.error("Exception while getPingStatus", e);
return new Vector<TblATO_KPIDETAIL>();
}
}
@Override
public Vector<TblATO_KPIDETAIL> getPerformance(HashMap<String, String> params) {
try {
CollMySQLBySql collector = new CollMySQLBySql();
return collector.getPerformance(params);
} catch (Exception e) {
logger.error("Exception while getPerformance", e);
return new Vector<TblATO_KPIDETAIL>();
}
}
@Override
public Vector<TblATO_KPIDETAIL> getInnodb(HashMap<String, String> params) {
try {
CollMySQLBySql collector = new CollMySQLBySql();
return collector.getInnodb(params);
} catch (Exception e) {
logger.error("Exception while getInnodb", e);
return new Vector<TblATO_KPIDETAIL>();
}
}
public Vector<TblATO_KPIDETAIL> getSlave(HashMap<String, String> params) {
try {
CollMySQLBySql collector = new CollMySQLBySql();
return collector.getSlave(params);
} catch (Exception e) {
logger.error("Exception while getSlave", e);
return new Vector<TblATO_KPIDETAIL>();
}
}
public Vector<TblATO_KPIDETAIL> getTableSpaceIO(HashMap<String, String> params) {
try {
CollMySQLBySql collector = new CollMySQLBySql();
return collector.getTableSpaceIO(params);
} catch (Exception e) {
logger.error("Exception while getTableSpaceIO", e);
return new Vector<TblATO_KPIDETAIL>();
}
}
private static String read(String prompt) {
Scanner scanner = new Scanner(System.in);
System.out.print(prompt);
return scanner.nextLine();
}
public static void main(String[] args) {
System.out.println("***************MySQL Collect Test Begin*********************");
// String db_url = read("DB_URL(jdbc:main://172.21.0.67:3306):");
// String username = read("USERNAME:");
// String password = read("PASSWORD:");
// String deviceId = read("DEVICE_ID:");
// String methodStr = read("METHOD(0:getAll, 1:getSystem, 2:getStatus, 3:getInnodb, 4:getSlaveStatus):");
String db_url = "jdbc:mysql://172.21.0.67:3306/bnms";
String username = "bnms";
String password = "bnms";
String deviceId = "bnms";
String methodStr = "5";
HashMap params = new HashMap();
params.put("DB_URL", db_url);
params.put("USERNAME", username);
params.put("PASSWORD", DES3.encrypt(password));
params.put("DEVICE_ID", deviceId);
CollMySQL coll = new CollMySQL();
Vector lst = new Vector<TblATO_KPIDETAIL>();
int method = Integer.parseInt(methodStr);
switch (method) {
case 0:
lst.addAll(coll.getSystem(params));
lst.addAll(coll.getStatus(params));
lst.addAll(coll.getInnodb(params));
lst.addAll(coll.getSlave(params));
lst.addAll(coll.getTableSpaceIO(params));
break;
case 1:
lst.addAll(coll.getSystem(params));
break;
case 2:
lst.addAll(coll.getStatus(params));
break;
case 3:
lst.addAll(coll.getInnodb(params));
break;
case 4:
lst.addAll(coll.getSlave(params));
break;
case 5:
lst.addAll(coll.getTableSpaceIO(params));
break;
default:
break;
}
System.out.println("***************MySQL Collect Test End*********************");
System.out.println("lst.size() is " + lst.size());
for (int i = 0; i < lst.size(); i++) {
TblATO_KPIDETAIL record = (TblATO_KPIDETAIL) lst.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#', sysdate, '#KPI_VALUE#', 'null', sysdate, '10-11-35:bnms', #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);
}
}
}