Package com.dianping.cat.consumer.metric.model.entity

Examples of com.dianping.cat.consumer.metric.model.entity.MetricReport


    super(MetricAnalyzer.ID);
  }

  @Override
  protected MetricReport getReport(ModelRequest request, ModelPeriod period, String domain) throws Exception {
    MetricReport report = super.getReport(request, period, domain);

    if (report == null && period.isLast()) {
      long startTime = request.getStartTime();
      report = getReportFromLocalDisk(startTime, domain);

      if (report == null) {
        report = new MetricReport(domain);
        report.setStartTime(new Date(startTime));
        report.setEndTime(new Date(startTime + TimeHelper.ONE_HOUR - 1));
      }
    }
    return report;
  }
View Full Code Here


  @Override
  protected MetricReport buildModel(ModelRequest request) throws Exception {
    String domain = request.getDomain();
    long date = request.getStartTime();
    MetricReport report;

    if (isLocalMode()) {
      report = getReportFromLocalDisk(date, domain);
    } else {
      report = getReportFromDatabase(date, domain);
View Full Code Here

  @Override
  protected MetricReport merge(ModelRequest request, List<ModelResponse<MetricReport>> responses) {
    if (responses.size() == 0) {
      return null;
    }
    MetricReportMerger merger = new MetricReportMerger(new MetricReport(request.getDomain()));

    for (ModelResponse<MetricReport> response : responses) {
      MetricReport model = response.getModel();
      if (model != null) {
        model.accept(merger);
      }
    }

    return merger.getMetricReport();
  }
View Full Code Here

    int totalSize = (int) ((end - start) / TimeHelper.ONE_MINUTE);
    Map<String, double[]> sourceValue = new LinkedHashMap<String, double[]>();
    int index = 0;

    for (; start < end; start += TimeHelper.ONE_HOUR) {
      MetricReport report = m_metricReportService.querySystemReport(group, pars, new Date(start));
      Map<String, double[]> currentValues = m_pruductDataFetcher.buildGraphData(report);

      mergeMap(sourceValue, currentValues, totalSize, index);
      index++;

      Statistic ipList = report.getStatistics().get(SystemReportConvertor.IP_LIST_KEY);

      if (ipList != null) {
        ipAddrs.addAll(ipList.getStatisticsItems().keySet());
      }
    }
View Full Code Here

    return false;
  }

  @Override
  public void visitMetricReport(MetricReport metricReport) {
    m_report = new MetricReport(metricReport.getProduct());
    super.visitMetricReport(metricReport);
  }
View Full Code Here

 
  @Test
  public void testMetricReportMerge() throws Exception {
    String oldXml = Files.forIO().readFrom(getClass().getResourceAsStream("MetricReportOld.xml"), "utf-8");
    String newXml = Files.forIO().readFrom(getClass().getResourceAsStream("MetricReportNew.xml"), "utf-8");
    MetricReport reportOld = DefaultSaxParser.parse(oldXml);
    MetricReport reportNew = DefaultSaxParser.parse(newXml);
    String expected = Files.forIO().readFrom(getClass().getResourceAsStream("MetricReportMergeResult.xml"), "utf-8");
    MetricReportMerger merger = new MetricReportMerger(new MetricReport(reportOld.getProduct()));

    reportOld.accept(merger);
    reportNew.accept(merger);

    Assert.assertEquals("Check the merge result!", expected.replaceAll("\\r", ""), merger.getMetricReport().toString().replaceAll("\\r", ""));
    Assert.assertEquals("Source report is changed!", newXml.replaceAll("\\r", ""), reportNew.toString().replaceAll("\\r", ""));
  }
View Full Code Here

public class MetricReportParseTest {

  @Test
  public void test() throws Exception {
    String oldXml = Files.forIO().readFrom(getClass().getResourceAsStream("metric-report.xml"), "utf-8");
    MetricReport report = DefaultSaxParser.parse(oldXml);
    byte[] bytes = DefaultNativeBuilder.build(report);

    MetricReport report2 = DefaultNativeParser.parse(bytes);

    Assert.assertEquals(report.toString(), report2.toString());
  }
View Full Code Here

    }
    return oldCurrentValues;
  }

  private Map<String, double[]> queryMetricValueByDate(String productLine, long start) {
    MetricReport metricReport = m_metricReportService.queryMetricReport(productLine, new Date(start));
    Map<String, double[]> currentValues = m_pruductDataFetcher.buildGraphData(metricReport);
    double sum = 0;

    for (Entry<String, double[]> entry : currentValues.entrySet()) {
      double[] value = entry.getValue();
View Full Code Here

    String systemReportAllIpXml = Files.forIO().readFrom(getClass().getResourceAsStream("systemReportAllIp.xml"),
          "utf-8");
    String systemReportIpFilterXml = Files.forIO().readFrom(
          getClass().getResourceAsStream("systemReportIpFilter.xml"), "utf-8");

    MetricReport metricReport = DefaultSaxParser.parse(metricReportXml);
    SystemReportConvertor convert = new SystemReportConvertor("system", null);
    convert.visitMetricReport(metricReport);
    MetricReport systemReportAllIp = convert.getReport();

    Assert.assertEquals("Check all ip convert result!", systemReportAllIpXml.replace("\r", ""), systemReportAllIp
          .toString().replace("\r", ""));

    Set<String> ipAddrs = new HashSet<String>(Arrays.asList("10.254.251.60"));
    SystemReportConvertor convertIpFilter = new SystemReportConvertor("system", ipAddrs);
    convertIpFilter.visitMetricReport(metricReport);
    MetricReport systemReportIpFilter = convertIpFilter.getReport();

    Assert.assertEquals("Check all ip convert result!", systemReportIpFilterXml.replace("\r", ""),
          systemReportIpFilter.toString().replace("\r", ""));

  }
View Full Code Here

  @Test
  public void test() throws Exception {

    String reportXml = Files.forIO().readFrom(getClass().getResourceAsStream("metricReport.xml"), "utf-8");
    MetricReport report = DefaultSaxParser.parse(reportXml);
    report.setProduct("userMonitor");
    Map<String, String> prop = new HashMap<String, String>();

    prop.put("city", "江苏-南京");
    prop.put("channel", "中国移动");
    prop.put("type", "info");

    MetricReport reportInfo = hackForTest(report, prop);
    String userMonitorReportInfo = Files.forIO().readFrom(
          getClass().getResourceAsStream("userMonitorReportInfo.xml"), "utf-8");

    Assert.assertEquals("Check info info convert result!", userMonitorReportInfo.replace("\r", ""), reportInfo
          .toString().replace("\r", ""));

    prop.put("city", "江苏-南京");
    prop.put("channel", "中国联通");
    prop.put("type", "httpStatus");

    MetricReport reportHttpStatus = hackForTest(report, prop);
    String userMonitorReportHttpStatus = Files.forIO().readFrom(
          getClass().getResourceAsStream("userMonitorReportHttpStatus.xml"), "utf-8");

    Assert.assertEquals("Check http status convert result!", userMonitorReportHttpStatus.replace("\r", ""),
          reportHttpStatus.toString().replace("\r", ""));

    prop.put("city", "江苏-扬州");
    prop.put("channel", "中国联通");
    prop.put("type", "errorCode");

    MetricReport reportErrorCode = hackForTest(report, prop);
    String userMonitorReportErrorCode = Files.forIO().readFrom(
          getClass().getResourceAsStream("userMonitorReportErrorCode.xml"), "utf-8");

    Assert.assertEquals("Check error code convert result!", userMonitorReportErrorCode.replace("\r", ""),
          reportErrorCode.toString().replace("\r", ""));
  }
View Full Code Here

TOP

Related Classes of com.dianping.cat.consumer.metric.model.entity.MetricReport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.