public Map<String, LineChart> buildDashboardByGroup(Date start, Date end, String metricGroup) { Map<String, LineChart> result = new LinkedHashMap<String, LineChart>(); List<MetricKeyConfig> metricConfigs = m_metricGroupConfigManager.queryMetricGroupConfig(metricGroup); Collection<ProductLine> productLines = m_productLineConfigManager.queryAllProductLines().values(); Map<String, LineChart> allCharts = new LinkedHashMap<String, LineChart>(); for (ProductLine productLine : productLines) { if (isProductLineInGroup(productLine.getId(), metricConfigs)) { allCharts.putAll(buildChartsByProductLine(productLine.getId(), start, end)); } } for (MetricKeyConfig metric : metricConfigs) { String domain = metric.getMetricDomain(); String type = metric.getMetricType().equalsIgnoreCase("metric") ? "Metric" : metric.getMetricType(); String key = metric.getMetricKey(); String id = m_metricConfigManager.buildMetricKey(domain, type, key) + ":" + metric.getDisplayType().toUpperCase(); put(allCharts, result, id); } return result; }
private void processMetricItem(int minute, ProductLine productLine, String metricKey) { for (MetricType type : MetricType.values()) { String productlineName = productLine.getId(); AlertResultEntity alertResult = computeAlertInfo(minute, productlineName, metricKey, type); if (alertResult != null && alertResult.isTriggered()) { String metricTitle = buildMetricTitle(metricKey); String mailTitle = getAlertConfig().buildMailTitle(productLine.getTitle(), metricTitle); m_alertInfo.addAlertInfo(metricKey, new Date().getTime()); storeAlert(productlineName, metricTitle, mailTitle, alertResult); sendAlertInfo(productLine, mailTitle, alertResult.getContent(), alertResult.getAlertType()); } } }
@Override public void run() { boolean active = true; try { Thread.sleep(5000); } catch (InterruptedException e) { active = false; } while (active) { Transaction t = Cat.newTransaction("AlertDatabase", TimeHelper.getMinuteStr()); long current = System.currentTimeMillis(); try { Map<String, ProductLine> productLines = m_productLineConfigManager.getCompany().getProductLines(); for (ProductLine productLine : productLines.values()) { try { if (productLine.isDatabaseMonitorDashboard()) { processProductLine(productLine); } } catch (Exception e) { Cat.logError(e); } } t.setStatus(Transaction.SUCCESS); } catch (Exception e) { t.setStatus(e); } finally { m_currentReports.clear(); m_lastReports.clear(); t.complete(); } long duration = System.currentTimeMillis() - current; try { if (duration < DURATION) { Thread.sleep(DURATION - duration); } } catch (InterruptedException e) { active = false; } } }
public Map<String, LineChart> buildDashboard(Date start, Date end) { Collection<ProductLine> productLines = m_productLineConfigManager.queryAllProductLines().values(); Map<String, LineChart> allCharts = new LinkedHashMap<String, LineChart>(); for (ProductLine productLine : productLines) { if (showInDashboard(productLine.getId())) { allCharts.putAll(buildChartsByProductLine(productLine.getId(), start, end)); } } List<MetricItemConfig> configs = new ArrayList<MetricItemConfig>( m_metricConfigManager.getMetricConfig().getMetricItemConfigs().values()); Collections.sort( configs, new Comparator<MetricItemConfig>() { @Override public int compare(MetricItemConfig o1, MetricItemConfig o2) { return (int) (o1.getShowDashboardOrder() * 100 - o2.getShowDashboardOrder() * 100); } }); Map<String, LineChart> result = new LinkedHashMap<String, LineChart>(); for (MetricItemConfig config : configs) { String key = config.getId(); if (config.getShowAvg() && config.getShowAvgDashboard()) { String avgKey = key + ":" + MetricType.AVG.name(); put(allCharts, result, avgKey); } if (config.getShowCount() && config.getShowCountDashboard()) { String countKey = key + ":" + MetricType.COUNT.name(); put(allCharts, result, countKey); } if (config.getShowSum() && config.getShowSumDashboard()) { String sumKey = key + ":" + MetricType.SUM.name(); put(allCharts, result, sumKey); } } return result; }
protected void processProductLine(ProductLine productLine) { long current = (System.currentTimeMillis()) / 1000 / 60; int minute = (int) (current % (60)) - DATA_AREADY_MINUTE; String product = productLine.getId(); MetricReport report = fetchMetricReport(product, ModelPeriod.CURRENT); for (Entry<String, MetricItem> entry : report.getMetricItems().entrySet()) { try { processMetricItem(minute, productLine, entry.getKey()); } catch (Exception e) { Cat.logError(e); } } }