public static MetricType getByIdentifier(String identifier) { for (int i = 0; i < MetricType.values().length; i++) { MetricType metricType = MetricType.values()[i]; if (metricType.getIdentifier().equals(identifier)) { return metricType; } } return null; }
/** * Conflates the passed metric value into this one * * @param metricValue The metric value to conflate into this metric value */ public synchronized void conflate(ICEMetricValue metricValue) { if (!type.isLong() || !metricValue.type.isLong()) { StringBuilder b = new StringBuilder("Cannot conflate non-numeric values."); b.append("\n\tThis metric:").append(this.toString()); b.append("\n\tThat value:").append(metricValue); throw new RuntimeException(b.toString(), new Throwable()); } if (type != metricValue.type) { StringBuilder b = new StringBuilder("Cannot conflate values of different types."); b.append("\n\tThis metric:").append(this.toString()); b.append("\n\tThat value:").append(metricValue); throw new RuntimeException(b.toString(), new Throwable()); } if (type.isGauge()) { this.longValue = avg(2, this.longValue + metricValue.longValue); } else { this.longValue += metricValue.longValue; } }
/** * Computes totals for each of the {@link MetricType}s. * * @return aggregates for each global metric type. * @throws StorageException if there was a problem fetching tasks from storage. */ public List<GlobalMetric> computeConsumptionTotals() throws StorageException { List<GlobalMetric> counts = FluentIterable.from(Arrays.asList(MetricType.values())) .transform(TO_GLOBAL_METRIC) .toList(); for (ITaskConfig task : getTasks(Query.unscoped().active())) { for (GlobalMetric count : counts) { count.accumulate(task); } } return counts; }
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()); } } }
/** * Returns the value as a long, or throws a RuntimeException if the type is not long based * * @return the long value */ public long getLongValue() { if (!type.isLong()) throw new RuntimeException("This value is not a long type", new Throwable()); return longValue; }
/** * Returns the value of this metricId * * @return the value */ public Object getValue() { return type.getDataAccessor().read(this); }
/** * Generates an ID for an {@link MetricInstance}. * * @param resource the resource that owns the MetricInstance * @param metricType the type of the MetricInstance whose ID is being generated * @return the ID */ public static ID generateMetricInstanceId( Resource<?, ?, ?, ?, ?> resource, MetricType metricType) { ID id = new ID(String.format("MI~R~[%s]~MT~%s", resource.getID(), metricType.getName())); return id; }