@Override public String toString() { return "UpdateMetricCommand{" + "metric='" + getMetric() + "'" + "resource='" + getResource() + "'" + ", value=" + getValue() + ", range=" + getTimeRange() + "}"; }
/** * Similar in design to the old AddPointCommand */ public UpdateMetricCommand(ResourceMetricKey resourceKey, DataPoint dataPoint) { this(resourceKey, createRangeFromPoint(dataPoint), dataPoint.getValue()); }
public UpdateMetricCommand(ResourceMetricKey resourceKey, TimeRange timeRange, double metricValue) { setKey(resourceKey); setTimeRange(timeRange); setValue(metricValue); }
@Override @InsightEndPoint public void executeCommand(UpdateMetricCommand command) { ResourceMetricKey key = command.getKey(); MetricData adapter = dataRepo.createOrGetMetricData(key); if (adapter instanceof CounterMetricDataAdapter) { CounterMetricDataAdapter mData = (CounterMetricDataAdapter) adapter; mData.increment(command.getCounterMetricValue()); return; } if (adapter instanceof GaugeMetricDataAdapter) { GaugeMetricDataAdapter mData = (GaugeMetricDataAdapter) adapter; IDataPoint point = command.getPoint(); GaugeMetricValue value = new GaugeMetricValueBuilder(command.getTimeRange()).addPoint(point.getValue()).build(); mData.addValues(singletonList(value)); return; } } }
public List<UpdateMetricCommand> generateCommands(TraceAnalysis analysis) { Resource endPoint=analysis.getEndPoint(); ResourceMetricKey rmKey=ResourceMetricKey.valueOf(endPoint.getKey(), Metrics.ENDPOINT_RESPONSE_TIME); return asList(new UpdateMetricCommand(rmKey, analysis.getResponseTimePoint())); }
public CounterMetricValue getCounterMetricValue() { if (counter != null) { return counter; } counter = new CounterMetricValue(getTimeRange(), value); return counter; }
public boolean isCounter() { return Metrics.COUNTER_TYPE.equals(getKey().getMetricKey().getType()); }
public List<UpdateMetricCommand> generateCommands(TraceAnalysis analysis) { if (!analysis.isError()) { return Collections.emptyList(); } ResourceMetricKey rmKey = ResourceMetricKey.valueOf(analysis.getEndPoint().getKey(), ERROR_COUNT); CounterMetricValue val = new CounterMetricValue(analysis.getResponseTime(), 1); return Collections.singletonList(new UpdateMetricCommand(rmKey, val)); }
@Override public boolean equals(Object obj) { if (obj == null) return false; if (this == obj) return true; if (getClass() != obj.getClass()) return false; UpdateMetricCommand other = (UpdateMetricCommand) obj; return (Double.compare(getValue(), other.getValue()) == 0) && ObjectUtil.typedEquals(getMetric(), other.getMetric()) && ObjectUtil.typedEquals(getTimeRange(), other.getTimeRange()) && ObjectUtil.typedEquals(getResource(), other.getResource()) ; }
public List<UpdateMetricCommand> generateCommands(TraceAnalysis analysis) { List<MetricKey> tagMetricKeys = getMetricsForTags(analysis.getTraceTags()); List<UpdateMetricCommand> commands = new ArrayList<UpdateMetricCommand>(tagMetricKeys.size()); TimeRange responseTime = analysis.getResponseTime(); ResourceKey resourceKey = analysis.getEndPoint().getKey(); for (MetricKey tagMetricKey : tagMetricKeys) { ResourceMetricKey rmKey = ResourceMetricKey.valueOf(resourceKey, tagMetricKey); CounterMetricValue value = new CounterMetricValue(responseTime, 1); commands.add(new UpdateMetricCommand(rmKey, value)); } return commands; }
@Override public int hashCode() { int result=ObjectUtil.hashCode(getTimeRange()); result = 31 * result + MathUtil.hashValue(getValue()); result = 31 * result + ObjectUtil.hashCode(getResource()); result = 31 * result + ObjectUtil.hashCode(getMetric()); return result; } }
public List<UpdateMetricCommand> generateCommands(TraceAnalysis analysis) { Resource endPoint=analysis.getEndPoint(); ResourceMetricKey rmKey=ResourceMetricKey.valueOf(endPoint.getKey(), INVOCATION_COUNT); CounterMetricValue value=new CounterMetricValue(analysis.getResponseTime(), 1.0d); return singletonList(new UpdateMetricCommand(rmKey, value)); } }
public static UpdateMetricCommand getAddPointCommand() { ResourceMetricKey key = ResourceMetricKey.valueOf(getServerResourceCommand("butter", "butter-label").getResource().getKey(), Metrics.ENDPOINT_RESPONSE_TIME); return new UpdateMetricCommand(key, DataPoint.dp(45, 23)); }
public static UpdateMetricCommand getIncrementCommand() { ResourceMetricKey key = ResourceMetricKey.valueOf(getServerResourceCommand("butter", "butter-label").getResource().getKey(), Metrics.INVOCATION_COUNT); CounterMetricValue counter = new CounterMetricValue(TimeRange.range(0, 56), 56.0); return new UpdateMetricCommand(key, counter); }
static Command createMetricCommand (ResourceKey resKey, TimeRange range, String key, PointType pt, Collection<? extends IDataPoint> points) { if (ListUtil.size(points) <= 0) { return null; } ResourceMetricKey metricKey = ResourceMetricKey.valueOf(resKey, MetricKey.valueOf(key)); switch (pt) { case COUNTER: { CounterMetricValueBuilder valueBuilder = new CounterMetricValueBuilder(range); CounterMetricValue mValue = (CounterMetricValue)aggregateValue(points, valueBuilder); return new UpdateMetricCommand(metricKey, mValue); } case GAUGE: { GaugeMetricValueBuilder valueBuilder=new GaugeMetricValueBuilder(range); GaugeMetricValue gValue = (GaugeMetricValue)aggregateValue(points, valueBuilder); return new UpdateMetricDistributionCommand(metricKey, gValue); } default: throw new IllegalStateException("createMetricCommand(" + metricKey + ")[" + range + "] unhandled point type: " + pt); } }