/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.monitor.simple;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.utils.ConfigUtils;
import com.alibaba.dubbo.common.utils.NamedThreadFactory;
import com.alibaba.dubbo.common.utils.NetUtils;
import com.alibaba.dubbo.monitor.MonitorService;
import com.alibaba.dubbo.monitor.simple.common.CountUtils;
//import org.apache.dubbo.common.Constants;
//import org.apache.dubbo.common.URL;
//import org.apache.dubbo.common.logger.Logger;
//import org.apache.dubbo.common.logger.LoggerFactory;
//import org.apache.dubbo.common.utils.ConfigUtils;
//import org.apache.dubbo.common.utils.NamedThreadFactory;
//import org.apache.dubbo.common.utils.NetUtils;
//import org.apache.dubbo.monitor.MonitorService;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.time.Minute;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;
/**
* SimpleMonitorService
*/
public class SimpleMonitorService implements MonitorService {
// private static final Logger logger = LoggerFactory.getLogger(SimpleMonitorService.class);
private static final String[] types = {SUCCESS, FAILURE, ELAPSED, CONCURRENT, MAX_ELAPSED, MAX_CONCURRENT};
private static final String POISON_PROTOCOL = "poison";
private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1, new NamedThreadFactory("DubboMonitorTimer", true));
private final ScheduledFuture<?> chartFuture;
private final Thread writeThread;
private final BlockingQueue<URL> queue;
private String statisticsDirectory = "statistics";
private String chartsDirectory = "charts";
private volatile boolean running = true;
public SimpleMonitorService() {
queue = new LinkedBlockingQueue<URL>(Integer.parseInt(ConfigUtils.getProperty("dubbo.monitor.queue", "100000")));
writeThread = new Thread(new Runnable() {
public void run() {
while (running) {
try {
write(); // write statistics
} catch (Throwable t) {
// logger.error("Unexpected error occur at write stat log, cause: " + t.getMessage(), t);
try {
Thread.sleep(5000); // retry after 5 secs
} catch (Throwable t2) {
}
}
}
}
});
writeThread.setDaemon(true);
writeThread.setName("DubboMonitorAsyncWriteLogThread");
writeThread.start();
chartFuture = scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {
public void run() {
try {
draw(); // draw chart
} catch (Throwable t) {
// logger.error("Unexpected error occur at draw stat chart, cause: " + t.getMessage(), t);
}
}
}, 1, 60, TimeUnit.SECONDS);
statisticsDirectory = ConfigUtils.getProperty("dubbo.statistics.directory");
chartsDirectory = ConfigUtils.getProperty("dubbo.charts.directory");
}
private static void createChart(String key, String service, String method, String date, String[] types, Map<String, long[]> data, double[] summary, String path) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
DecimalFormat numberFormat = new DecimalFormat("###,##0.##");
TimeSeriesCollection xydataset = new TimeSeriesCollection();
for (int i = 0; i < types.length; i++) {
String type = types[i];
TimeSeries timeseries = new TimeSeries(type);
for (Map.Entry<String, long[]> entry : data.entrySet()) {
try {
timeseries.add(new Minute(dateFormat.parse(date + entry.getKey())), entry.getValue()[i]);
} catch (ParseException e) {
// logger.error(e.getMessage(), e);
}
}
xydataset.addSeries(timeseries);
}
JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(
"max: " + numberFormat.format(summary[0]) + (summary[1] >= 0 ? " min: " + numberFormat.format(summary[1]) : "")
+ " avg: " + numberFormat.format(summary[2]) + (summary[3] >= 0 ? " sum: " + numberFormat.format(summary[3]) : ""),
toDisplayService(service) + " " + method + " " + toDisplayDate(date), key, xydataset, true, true, false);
jfreechart.setBackgroundPaint(Color.WHITE);
XYPlot xyplot = (XYPlot) jfreechart.getPlot();
xyplot.setBackgroundPaint(Color.WHITE);
xyplot.setDomainGridlinePaint(Color.GRAY);
xyplot.setRangeGridlinePaint(Color.GRAY);
xyplot.setDomainGridlinesVisible(true);
xyplot.setRangeGridlinesVisible(true);
DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
dateaxis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
BufferedImage image = jfreechart.createBufferedImage(600, 300);
try {
// if (logger.isInfoEnabled()) {
// logger.info("write chart: " + path);
// }
File methodChartFile = new File(path);
File methodChartDir = methodChartFile.getParentFile();
if (methodChartDir != null && !methodChartDir.exists()) {
methodChartDir.mkdirs();
}
FileOutputStream output = new FileOutputStream(methodChartFile);
try {
ImageIO.write(image, "png", output);
output.flush();
} finally {
output.close();
}
} catch (IOException e) {
// logger.warn(e.getMessage(), e);
}
}
private static String toDisplayService(String service) {
int i = service.lastIndexOf('.');
if (i >= 0) {
return service.substring(i + 1);
}
return service;
}
private static String toDisplayDate(String date) {
try {
return new SimpleDateFormat("yyyy-MM-dd").format(new SimpleDateFormat("yyyyMMdd").parse(date));
} catch (ParseException e) {
return date;
}
}
public void close() {
try {
running = false;
queue.offer(new URL(POISON_PROTOCOL, NetUtils.LOCALHOST, 0));
} catch (Throwable t) {
// logger.warn(t.getMessage(), t);
}
try {
chartFuture.cancel(true);
} catch (Throwable t) {
// logger.warn(t.getMessage(), t);
}
}
private void write() throws Exception {
URL statistic
没有合适的资源?快使用搜索试试~ 我知道了~
dubbo-monitor-simple.zip
共48个文件
java:32个
xml:5个
sh:5个
需积分: 5 0 下载量 137 浏览量
2022-01-04
15:29:44
上传
评论
收藏 72KB ZIP 举报
温馨提示
dubbo-monitor监控中心,基于alibaba dubbo.jar开发,解决Decode rpc invocation failed: expected map/object at java.lang.String (Ljava/lang/String)、com.alibaba.dubbo.common.URL' could not be instantiated等项目dubbo.jar不一致问题
资源详情
资源评论
资源推荐
收起资源包目录
dubbo-monitor-simple.zip (48个子文件)
dubbo-monitor-simple
pom.xml 12KB
src
test
resources
log4j.xml 1KB
dubbo.properties 1KB
java
com
alibaba
dubbo
monitor
simple
SimpleMonitor.java 1KB
SimpleMonitorServiceTest.java 1KB
main
assembly
assembly.xml 1KB
resources
conf
dubbo.properties 1KB
META-INF
assembly
bin
dump.sh 2KB
stop.sh 852B
server.sh 575B
restart.sh 49B
start.sh 3KB
start.bat 848B
dubbo
internal
com.alibaba.dubbo.monitor.simple.servlet.PageHandler 1KB
com.alibaba.dubbo.container.Container 141B
spring
dubbo-monitor-simple.xml 2KB
log4j.xml 2KB
java
com
alibaba
dubbo
monitor
simple
SimpleMonitorService.java 17KB
container
JettyContainer.java 4KB
RegistryContainer.java 13KB
servlet
ResourceFilter.java 5KB
PageHandler.java 1KB
PageServlet.java 13KB
pages
ChartsPageHandler.java 4KB
HomePageHandler.java 2KB
ServersPageHandler.java 3KB
ProvidersPageHandler.java 5KB
UnsubscribePageHandler.java 3KB
ConsumersPageHandler.java 5KB
StatusPageHandler.java 4KB
StatisticsPageHandler.java 8KB
LogPageHandler.java 4KB
SubscribedPageHandler.java 4KB
RegisteredPageHandler.java 4KB
DependenciesPageHandler.java 4KB
SystemPageHandler.java 5KB
UnregisterPageHandler.java 2KB
ClientsPageHandler.java 4KB
RegistriesPageHandler.java 3KB
HostsPageHandler.java 4KB
ApplicationsPageHandler.java 4KB
ServicesPageHandler.java 4KB
common
Menu.java 1KB
MenuComparator.java 2KB
CountUtils.java 3KB
Page.java 2KB
MonitorStarter.java 1KB
dubbo-monitor-simple.iml 4KB
共 48 条
- 1
青烟尽_梦离城
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0