mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
PushService for DruidMonitor ,test with druid-monitor
This commit is contained in:
@@ -83,7 +83,7 @@ public class PushService {
|
||||
protected void execute() {
|
||||
Map<String, Object> data = collectAndReset();
|
||||
String json = JSONUtils.toJSONString(data);
|
||||
push(json);
|
||||
push("data=" + json);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.alibaba.druid.support.monitor;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
import com.alibaba.druid.support.logging.LogFactory;
|
||||
|
||||
public class PushServiceListener implements ServletContextListener {
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(PushServiceListener.class);
|
||||
|
||||
private final static String MONITOR_SERVER_URL = "monitorServerUrl";
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
PushService pushService = PushService.getInstance();
|
||||
String serverUrl = sce.getServletContext().getInitParameter(MONITOR_SERVER_URL);
|
||||
if (serverUrl == null) {
|
||||
LOG.error(MONITOR_SERVER_URL + " can't be null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(MONITOR_SERVER_URL + "= " + serverUrl);
|
||||
}
|
||||
pushService.setServerUrl(serverUrl);
|
||||
pushService.start();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,29 +29,46 @@ public class HttpClientUtils {
|
||||
conn.setDoOutput(true);
|
||||
conn.setConnectTimeout(1000 * 5);
|
||||
wr = new OutputStreamWriter(conn.getOutputStream());
|
||||
wr.write("");
|
||||
|
||||
wr.write(data);
|
||||
wr.flush();
|
||||
|
||||
// Get the response
|
||||
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
responseBuilder = new StringBuilder();
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
responseBuilder.append(line + "\n");
|
||||
if (LOG.isDebugEnabled()) {
|
||||
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
responseBuilder = new StringBuilder();
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
responseBuilder.append(line + "\n");
|
||||
}
|
||||
LOG.debug(responseBuilder.toString());
|
||||
}
|
||||
wr.close();
|
||||
reader.close();
|
||||
|
||||
System.out.println(responseBuilder.toString());
|
||||
} catch (IOException e) {
|
||||
LOG.error("", e);
|
||||
} finally {
|
||||
|
||||
if (wr != null) {
|
||||
try {
|
||||
wr.close();
|
||||
} catch (IOException e) {
|
||||
LOG.error("close error", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
LOG.error("close error", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
post("http://www.alibaba.com", "", 6000);
|
||||
post("http://www.alibaba.com/trade/search", "fsb=y&IndexArea=product_en&CatId=&SearchText=test", 6000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user