public IntervalMetricDataSummary(MetricKey metricKey, long startTime, long endTime, double metricValue, String metricLabel, String type) { this.metric = metricKey.getKey(); this.start = startTime; this.end = endTime; this.value = metricValue; this.label = metricLabel; this.metricDataType = type; }
public static MetricKey valueOf(String keyStr) { MetricKey key = cachedMetricKey.get(keyStr); if (key == null) { key = new MetricKey(keyStr); cachedMetricKey.put(keyStr, key); } return key; } /**
public Object readResolve() throws ObjectStreamException { if (StringUtil.isEmpty(key)) { throw new StreamCorruptedException("No current key"); } return valueOf(key); }
public Metric(MetricKey key) { this.key = key; this.type = MetricDataType.get(key.getType()); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Metric other = (Metric) obj; return key.equals(other.key); }
@Override public int hashCode() { return key.hashCode(); }
@Override public String toString() { return key.toString(); }
private MetricKey(String keyValue) { this.key = keyValue; validateFormat(); }
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { long version = in.readLong(); if (version != serialVersionUID) { throw new IllegalStateException("Unable to deserialize GaugeMetricCommand; unexpected serialVersionUID: " + version); } resource = ResourceKey.valueOf((String) in.readObject()); metric = MetricKey.valueOf((String) in.readObject()); value = (GaugeMetricValue)in.readObject(); }
public boolean isCounter() { return Metrics.COUNTER_TYPE.equals(getKey().getMetricKey().getType()); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; MetricMemberKey other = (MetricMemberKey) obj; return key.equals(other.key); }
@Override public int hashCode() { return key.hashCode(); }
@Override public String toString() { return getKey(); }
/** * Returns a metric key which corresponds to the invocation * count of the given tag. */ public MetricKey getMetricKey() { if (key == null) { key = MetricKey.valueOf("tag." + getTag() + ":type=counter"); } return key; } }
public String getKey() { return key.getKey(); } }
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { long version = in.readLong(); if (version != serialVersionUID) { throw new IllegalStateException("Unable to deserialize ScalarMetricCommand; unexpected serialVersionUID: " + version); } resource = ResourceKey.valueOf((String) in.readObject()); metric = MetricKey.valueOf((String) in.readObject()); range = (TimeRange) in.readObject(); value = in.readDouble(); }
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); } }
public void writeExternal(ObjectOutput out) throws IOException { out.writeLong(serialVersionUID); out.writeObject(resource.getKey()); out.writeObject(metric.getKey()); out.writeObject(value); }