![JAR search and dependency download from the Maven repository](/logo.png)
com.alibaba.dubbo.monitor.simple.pages.ChartsPageHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dubbo2-monitor-simple Show documentation
Show all versions of dubbo2-monitor-simple Show documentation
The simple monitor module of dubbo project
The newest version!
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.pages;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
import com.alibaba.dubbo.monitor.MonitorService;
import com.alibaba.dubbo.monitor.simple.SimpleMonitorService;
/**
* ChartsPageHandler
*
* @author william.liangf
*/
public class ChartsPageHandler implements PageHandler {
public Page handle(URL url) {
String service = url.getParameter("service");
if (service == null || service.length() == 0) {
throw new IllegalArgumentException("Please input service parameter.");
}
String date = url.getParameter("date");
if (date == null || date.length() == 0) {
date = new SimpleDateFormat("yyyyMMdd").format(new Date());
}
List> rows = new ArrayList>();
String directory = SimpleMonitorService.getInstance().getChartsDirectory();
File chartsDir = new File(directory);
String filename = directory + "/" + date + "/" + service;
File serviceDir = new File(filename);
if (serviceDir.exists()) {
File[] methodDirs = serviceDir.listFiles();
for (File methodDir : methodDirs) {
String methodUri = chartsDir.getName() + "/" + date + "/" + service + "/" + methodDir.getName() + "/";
rows.add(toRow(methodDir, methodUri));
}
}
StringBuilder nav = new StringBuilder();
nav.append("Services > ");
nav.append(service);
nav.append(" > Providers | Consumers | Statistics | Charts > ");
return new Page(nav.toString(), "Charts (" + rows.size() + ")",
new String[] { "Method", "Requests per second (QPS)", "Average response time (ms)"}, rows);
}
private List toRow(File dir, String uri) {
List row = new ArrayList();
row.add(dir.getName());
if (new File(dir, MonitorService.SUCCESS + ".png").exists()) {
String url = uri + MonitorService.SUCCESS + ".png";
row.add("
");
} else {
row.add("");
}
if (new File(dir, MonitorService.ELAPSED + ".png").exists()) {
String url = uri + MonitorService.ELAPSED + ".png";
row.add("
");
} else {
row.add("");
}
return row;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy