use of com.srotya.sidewinder.core.storage.ItemNotFoundException in project sidewinder by srotya.
the class DatabaseOpsApi method querySeries.
@Path("/{" + DB_NAME + "}/query")
@POST
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.TEXT_PLAIN })
public String querySeries(@PathParam(DatabaseOpsApi.DB_NAME) String dbName, String query) {
try {
String[] queryParts = query.split("<=?");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
long endTs = System.currentTimeMillis();
long startTs = endTs;
String startTime = queryParts[0];
String endTime = queryParts[2];
if (startTime.contains("now")) {
String[] split = startTime.split("-");
int offset = Integer.parseInt(split[1].charAt(0) + "");
startTs = startTs - (offset * 3600 * 1000);
} else if (startTime.matches("\\d+")) {
startTs = Long.parseLong(startTime);
endTs = Long.parseLong(endTime);
} else {
startTs = sdf.parse(startTime).getTime();
endTs = sdf.parse(endTime).getTime();
}
// cpu.load.host=v1.domain=test\.com=>derivative,10,mean
TargetSeries tagSeries = MiscUtils.extractTargetFromQuery(query);
List<Series> points = storageEngine.queryDataPoints(dbName, tagSeries.getMeasurementName(), tagSeries.getFieldName(), startTs, endTs, tagSeries.getTagFilter(), null, tagSeries.getAggregationFunction());
return new Gson().toJson(points);
} catch (ItemNotFoundException e) {
throw new NotFoundException(e);
} catch (BadRequestException e) {
throw e;
} catch (Exception e) {
e.printStackTrace();
throw new InternalServerErrorException(e);
}
}
use of com.srotya.sidewinder.core.storage.ItemNotFoundException in project sidewinder by srotya.
the class MeasurementOpsApi method getSeries.
public List<Number[]> getSeries(@PathParam(DatabaseOpsApi.DB_NAME) String dbName, @PathParam(MEASUREMENT) String measurementName, @QueryParam("field") String valueFieldName, @DefaultValue("now-1h") @QueryParam(START_TIME) String startTime, @QueryParam(END_TIME) String endTime) {
if (valueFieldName == null) {
throw new BadRequestException("Must specify a value field");
}
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long endTs = System.currentTimeMillis();
long startTs = endTs;
if (startTime.contains("now")) {
String[] split = startTime.split("-");
int offset = Integer.parseInt(split[1].charAt(0) + "");
startTs = startTs - (offset * 3600 * 1000);
} else {
startTs = sdf.parse(startTime).getTime();
endTs = sdf.parse(endTime).getTime();
}
List<Series> points = engine.queryDataPoints(dbName, measurementName, valueFieldName, startTs, endTs, null);
List<Number[]> response = new ArrayList<>();
for (Series entry : points) {
for (DataPoint dataPoint : entry.getDataPoints()) {
if (entry.isFp()) {
response.add(new Number[] { dataPoint.getLongValue(), dataPoint.getTimestamp() });
} else {
response.add(new Number[] { dataPoint.getValue(), dataPoint.getTimestamp() });
}
}
}
return response;
} catch (ItemNotFoundException e) {
throw new NotFoundException(e);
} catch (Exception e) {
throw new InternalServerErrorException(e);
}
}
use of com.srotya.sidewinder.core.storage.ItemNotFoundException in project sidewinder by srotya.
the class MeasurementOpsApi method updateRetentionPolicy.
@Path("/series/retention/{retentionPolicy}")
@PUT
public void updateRetentionPolicy(@PathParam(DatabaseOpsApi.DB_NAME) String dbName, @PathParam(MEASUREMENT) String measurementName, @PathParam("retentionPolicy") int retentionPolicy) {
try {
engine.updateDefaultTimeSeriesRetentionPolicy(dbName, retentionPolicy);
logger.info("Updated retention policy for:" + dbName + "\t" + retentionPolicy + " hours");
} catch (ItemNotFoundException e) {
throw new NotFoundException(e);
}
}
use of com.srotya.sidewinder.core.storage.ItemNotFoundException in project sidewinder by srotya.
the class MeasurementOpsApi method listMeasurements.
@GET
@Produces({ MediaType.APPLICATION_JSON })
public String listMeasurements(@PathParam(DatabaseOpsApi.DB_NAME) String dbName, @PathParam(MEASUREMENT) String measurementName) {
try {
Set<String> fields = engine.getFieldsForMeasurement(dbName, measurementName);
Set<String> tagsForMeasurement = engine.getTagKeysForMeasurement(dbName, measurementName);
JsonObject obj = new JsonObject();
JsonArray fieldAry = new JsonArray();
for (String field : fields) {
fieldAry.add(field);
}
obj.add("fields", fieldAry);
JsonArray tagAry = new JsonArray();
for (String tag : tagsForMeasurement) {
tagAry.add(tag);
}
obj.add("tags", tagAry);
return new Gson().toJson(obj);
} catch (ItemNotFoundException e) {
throw new NotFoundException(e);
} catch (Exception e) {
throw new InternalServerErrorException(e);
}
}
use of com.srotya.sidewinder.core.storage.ItemNotFoundException in project sidewinder by srotya.
the class GrafanaQueryApi method queryFields.
@Path("/query/fields")
@POST
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
public Set<String> queryFields(@PathParam(DatabaseOpsApi.DB_NAME) String dbName, String queryString) {
try {
Gson gson = new Gson();
JsonObject measurement = gson.fromJson(queryString, JsonObject.class);
if (measurement.has("target")) {
Set<String> response = engine.getFieldsForMeasurement(dbName, measurement.get("target").getAsString());
logger.log(Level.FINE, () -> "Query fields for db:" + dbName + "\t" + response + "\t" + queryString);
return response;
} else {
throw new ItemNotFoundException("Bad request");
}
} catch (ItemNotFoundException e) {
throw new NotFoundException(e.getMessage());
} catch (Exception e) {
throw new InternalServerErrorException(e.getMessage());
}
}
Aggregations