Change measurements JSON response format to be tabular
This commit is contained in:
parent
c2c74bb558
commit
a64f03738b
|
@ -6,13 +6,15 @@ package com.hpcloud.mon.domain.model.measurement;
|
|||
* @author Jonathan Halterman
|
||||
*/
|
||||
public class Measurement {
|
||||
private long id;
|
||||
private long timestamp;
|
||||
private double value;
|
||||
|
||||
public Measurement() {
|
||||
}
|
||||
|
||||
public Measurement(long timestamp, double value) {
|
||||
public Measurement(long id, long timestamp, double value) {
|
||||
this.setId(id);
|
||||
this.timestamp = timestamp;
|
||||
this.value = value;
|
||||
}
|
||||
|
@ -26,6 +28,8 @@ public class Measurement {
|
|||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Measurement other = (Measurement) obj;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
if (timestamp != other.timestamp)
|
||||
return false;
|
||||
if (Double.doubleToLongBits(value) != Double.doubleToLongBits(other.value))
|
||||
|
@ -33,6 +37,10 @@ public class Measurement {
|
|||
return true;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
@ -45,6 +53,7 @@ public class Measurement {
|
|||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (int) (id ^ (id >>> 32));
|
||||
result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(value);
|
||||
|
@ -52,6 +61,10 @@ public class Measurement {
|
|||
return result;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
@ -62,6 +75,6 @@ public class Measurement {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Measurement [timestamp=%s, value=%s]", timestamp, value);
|
||||
return String.format("Measurement [id=%s, timestamp=%s, value=%s]", id, timestamp, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,20 +9,23 @@ import java.util.Map;
|
|||
* @author Jonathan Halterman
|
||||
*/
|
||||
public class Measurements {
|
||||
private static final String[] COLUMNS = new String[] { "id", "timestamp", "value" };
|
||||
|
||||
private String name;
|
||||
private Map<String, String> dimensions;
|
||||
private List<Measurement> measurements;
|
||||
private final String[] columns = COLUMNS;
|
||||
private List<Object[]> measurements;
|
||||
|
||||
public Measurements() {
|
||||
}
|
||||
|
||||
public Measurements(String name, Map<String, String> dimensions, List<Measurement> measurements) {
|
||||
public Measurements(String name, Map<String, String> dimensions, List<Object[]> measurements) {
|
||||
this.name = name;
|
||||
this.dimensions = dimensions;
|
||||
this.measurements = measurements;
|
||||
}
|
||||
|
||||
public void addMeasurement(Measurement measurement) {
|
||||
public void addMeasurement(Object[] measurement) {
|
||||
measurements.add(measurement);
|
||||
}
|
||||
|
||||
|
@ -53,11 +56,15 @@ public class Measurements {
|
|||
return true;
|
||||
}
|
||||
|
||||
public String[] getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public Map<String, String> getDimensions() {
|
||||
return dimensions;
|
||||
}
|
||||
|
||||
public List<Measurement> getMeasurements() {
|
||||
public List<Object[]> getMeasurements() {
|
||||
return measurements;
|
||||
}
|
||||
|
||||
|
@ -79,7 +86,7 @@ public class Measurements {
|
|||
this.dimensions = dimensions;
|
||||
}
|
||||
|
||||
public void setMeasurements(List<Measurement> measurements) {
|
||||
public void setMeasurements(List<Object[]> measurements) {
|
||||
this.measurements = measurements;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.skife.jdbi.v2.DBI;
|
|||
import org.skife.jdbi.v2.Handle;
|
||||
import org.skife.jdbi.v2.Query;
|
||||
|
||||
import com.hpcloud.mon.domain.model.measurement.Measurement;
|
||||
import com.hpcloud.mon.domain.model.measurement.MeasurementRepository;
|
||||
import com.hpcloud.mon.domain.model.measurement.Measurements;
|
||||
|
||||
|
@ -27,7 +26,7 @@ import com.hpcloud.mon.domain.model.measurement.Measurements;
|
|||
* @author Jonathan Halterman
|
||||
*/
|
||||
public class MeasurementRepositoryImpl implements MeasurementRepository {
|
||||
private static final String FIND_BY_METRIC_DEF_SQL = "select m.definition_dimensions_id, dd.dimension_set_id, m.time_stamp, m.value "
|
||||
private static final String FIND_BY_METRIC_DEF_SQL = "select m.definition_dimensions_id, dd.dimension_set_id, m.id, m.time_stamp, m.value "
|
||||
+ "from MonMetrics.Measurements m, MonMetrics.Definitions def, MonMetrics.DefinitionDimensions dd%s "
|
||||
+ "where m.definition_dimensions_id = dd.id and def.id = dd.definition_id "
|
||||
+ "and def.tenant_id = :tenantId and m.time_stamp >= :startTime%s order by dd.id";
|
||||
|
@ -73,17 +72,18 @@ public class MeasurementRepositoryImpl implements MeasurementRepository {
|
|||
byte[] defIdBytes = (byte[]) row.get("definition_dimensions_id");
|
||||
byte[] dimSetIdBytes = (byte[]) row.get("dimension_set_id");
|
||||
ByteBuffer defId = ByteBuffer.wrap(defIdBytes);
|
||||
long measurementId = (Long) row.get("id");
|
||||
long timestamp = ((Timestamp) row.get("time_stamp")).getTime() / 1000;
|
||||
double value = (double) row.get("value");
|
||||
|
||||
Measurements measurements = results.get(defId);
|
||||
if (measurements == null) {
|
||||
measurements = new Measurements(name, MetricQueries.dimensionsFor(h, dimSetIdBytes),
|
||||
new ArrayList<Measurement>());
|
||||
new ArrayList<Object[]>());
|
||||
results.put(defId, measurements);
|
||||
}
|
||||
|
||||
measurements.addMeasurement(new Measurement(timestamp, value));
|
||||
measurements.addMeasurement(new Object[]{measurementId, timestamp, value});
|
||||
}
|
||||
|
||||
return results.values();
|
||||
|
|
Loading…
Reference in New Issue