CollIdmmWithCMD.java
8.92 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
package com.sitech.ismp.coll.centercoll;
import com.sitech.ismp.check.util.JSONUtil;
import com.sitech.ismp.coll.CollBase;
import com.sitech.ismp.util.HttpClientException;
import com.sitech.ismp.util.HttpClientUtil;
import com.sitech.ismp.util.JacksonUtil;
import com.sitech.util.Formater;
import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import java.util.HashMap;
import java.util.Vector;
/**
* Created with IntelliJ IDEA.
* User: Owen
* Date: 15-5-12
* Time: 下午2:01
* To change this template use File | Settings | File Templates.
*/
public class CollIdmmWithCMD {
private static Logger logger = Logger.getLogger("COLL");
String PRE_UNITID = "10-41-12"; // 标识
public Vector getIdmm(HashMap<String, String> params){
// 保存采集结果,并返回值
CollBase collResult = new CollBase();
String ipAddr = params.get("IP_ADDR");
String port = params.get("PORT");
String deviceId = params.get("DEVICEID");
String address = "http://" + ipAddr + ":" + port + "/jolokia/exec/sitech.crmpd.inform:name=bk1,type=Broker/listByLoad";
// String address = "http://localhost:60214/jolokia/exec/sitech.crmpd.inform:name=bk1,type=Broker/listByLoad";
System.out.println("access idmm address: ##########" + address);
try {
String brokers = HttpClientUtil.get(address);
JSONArray array = JSONObject.fromObject(brokers).getJSONArray("value");
JSONObject json = (JSONObject) array.get(0);
String[] ip_port = json.get("name").toString().split(",");
if (ip_port != null) {
for (int i = 0; i < ip_port.length; i++) {
String unitId = PRE_UNITID + "-11:" + deviceId + "-" + ip_port[i].replace(".", "_");
collResult.addKPI(unitId, "CM-00-03-011-01", ip_port[i]);
String jvm_init = "http://" + ip_port[i].split(":")[0] + ":" + port + "/jolokia/read/metrics:name=jvm.memory.heap.init";
System.out.println("access idmm jvm_init: ##########" + jvm_init);
// String jvm_init = "http://localhost:60214/jolokia/read/metrics:name=jvm.memory.heap.init";
//String jvm_init = "http://172.21.3.98:7777/jolokia/read/metrics:name=jvm.memory.heap.init";
String init = ((JSONObject) JSONObject.fromObject(HttpClientUtil.get(jvm_init)).get("value")).get("Value") + "";
String _init = Double.valueOf(init) / 1024 / 1024 + "";
collResult.addKPI(unitId, "PM-00-05-009-03", Formater.formatDecimalKpivalue(_init));
if ("200".equals(JSONObject.fromObject(HttpClientUtil.get(jvm_init)).get("status").toString())) {
collResult.addKPI(unitId, "FM-00-01-001-05", "UP");
// String jvm_used = "http://localhost:60214/jolokia/read/metrics:name=jvm.memory.heap.used";
String jvm_used = "http://" + ip_port[i].split(":")[0] + ":" + port + "/jolokia/read/metrics:name=jvm.memory.heap.used";
//String jvm_used = "http://172.21.3.98:7777/jolokia/read/metrics:name=jvm.memory.heap.used";
String used = ((JSONObject) JSONObject.fromObject(HttpClientUtil.get(jvm_used)).get("value")).get("Value") + "";
String _used = Double.valueOf(used) / 1024 / 1024 + "";
collResult.addKPI(unitId, "PM-00-05-009-22", Formater.formatDecimalKpivalue(_used));
// String jvm_max = "http://localhost:60214/jolokia/read/metrics:name=jvm.memory.heap.max";
String jvm_max = "http://" + ip_port[i].split(":")[0] + ":" + port + "/jolokia/read/metrics:name=jvm.memory.heap.max";
//String jvm_max = "http://172.21.3.98:7777/jolokia/read/metrics:name=jvm.memory.heap.max";
String max = ((JSONObject) JSONObject.fromObject(HttpClientUtil.get(jvm_max)).get("value")).get("Value") + "";
String _max = Double.valueOf(max) / 1024 / 1024 + "";
collResult.addKPI(unitId, "PM-00-05-009-75", Formater.formatDecimalKpivalue(_max));
// String msg_path = "http://localhost:60214/jolokia/read/metrics:name=commits";
String msg_path = "http://" + ip_port[i].split(":")[0] + ":" + port + "/jolokia/read/metrics:name=commits";
System.out.println("access idmm msg_path: ##########" + msg_path);
//String msg_path = "http://192.168.0.214:7777/jolokia/read/metrics:name=commits";
String msg = ((JSONObject) JSONObject.fromObject(HttpClientUtil.get(msg_path)).get("value")).get("Count") + "";
collResult.addKPI(unitId, "PM-00-05-009-23", msg);
// String client_path = "http://localhost:60214/jolokia/exec/sitech.crmpd.inform:name=bk1,type=Broker/listClients";
String client_path = "http://" + ip_port[i].split(":")[0] + ":" + port + "/jolokia/exec/sitech.crmpd.inform:name=bk1,type=Broker/listClients";
//String client_path = "http://172.21.3.98:7777/jolokia/exec/sitech.crmpd.inform:name=bk1,type=Broker/listClients";
JSONArray arr = JSONObject.fromObject(HttpClientUtil.get(client_path)).getJSONArray("value");
if (arr != null && arr.size() != 0) {
JSONObject j = (JSONObject) array.get(0);
String clients = j.get("name").toString();
if (clients != null && !"".equals(clients)) {
collResult.addKPI(unitId, "PM-00-04-001-06", clients.split(",").length + "");
} else {
collResult.addKPI(unitId, "PM-00-04-001-06", "0");
}
} else {
collResult.addKPI(unitId, "PM-00-04-001-06", "0");
}
// String consumer_path = "http://localhost:60214/jolokia/exec/sitech.crmpd.inform:name=consumerData,type=ConsumerData/data";
String consumer_path = "http://" + ip_port[i].split(":")[0] + ":" + port + "/jolokia/exec/sitech.crmpd.inform:name=consumerData,type=ConsumerData/data";
//String client_path = "http://172.21.3.98:7777/jolokia/exec/sitech.crmpd.inform:name=consumerData,type=ConsumerData/data";
JSONObject consumer = (JSONObject) JSONObject.fromObject(HttpClientUtil.get(consumer_path)).getJSONObject("value");
if (consumer != null && consumer.size() != 0) {
for (Object str : consumer.keySet()) {
String subUnitId = PRE_UNITID + "-12:" + deviceId;
String user = str.toString();
System.out.println(str + " " + consumer.get(str));
if (null != consumer.get(str) && !"".equals(consumer.get(str)) && ((JSONObject) consumer.get(str)).size() != 0) {
for (Object keyvalue : ((JSONObject) consumer.get(str)).keySet()) {
String topic = keyvalue.toString();
subUnitId = subUnitId + "-" + user + "_" + topic;
// 消费者标识
collResult.addKPI(subUnitId, "CM-00-03-011-05", user);
// 主题
collResult.addKPI(subUnitId, "CM-00-03-011-06", topic);
// 消息数量
collResult.addKPI(subUnitId, "PM-00-05-009-23", ((JSONObject) consumer.get(str)).get(keyvalue).toString());
}
} else {
subUnitId = subUnitId + "-" + user;
// 消费者标识
collResult.addKPI(subUnitId, "CM-00-03-011-05", user);
// 主题
collResult.addKPI(subUnitId, "CM-00-03-011-06", "");
// 消息数量
collResult.addKPI(subUnitId, "PM-00-05-009-23", "0");
}
}
}
} else {
collResult.addKPI(unitId, "FM-00-01-001-05", "DOWN");
}
}
}
} catch (HttpClientException e) {
e.printStackTrace();
}
logger.info("end getIdmm : " + params.get("IP_ADDR") + ":" + params.get("PORT"));
return collResult.getKPISet();
}
}