use of com.srotya.sidewinder.core.rpc.Point.Builder in project sidewinder by srotya.
the class InfluxDecoder method pointsFromString.
public static List<Point> pointsFromString(String dbName, String payload) {
List<Point> dps = new ArrayList<>();
String[] splits = payload.split("[\\r\\n]+");
for (String split : splits) {
try {
String[] parts = split.split("\\s+");
if (parts.length < 2 || parts.length > 3) {
// invalid datapoint => drop
continue;
}
long timestamp = System.currentTimeMillis();
if (parts.length == 3) {
timestamp = Long.parseLong(parts[2]);
if (parts[2].length() > LENGTH_OF_MILLISECOND_TS) {
timestamp = timestamp / (1000 * 1000);
}
} else {
logger.finest("Bad datapoint parts:" + parts.length);
}
String[] key = parts[0].split(",");
String measurementName = key[0];
Set<String> tTags = new HashSet<>();
for (int i = 1; i < key.length; i++) {
tTags.add(key[i]);
}
List<String> tags = new ArrayList<>(tTags);
String[] fields = parts[1].split(",");
for (String field : fields) {
String[] fv = field.split("=");
String valueFieldName = fv[0];
if (!fv[1].endsWith("i")) {
Builder builder = Point.newBuilder();
double value = Double.parseDouble(fv[1]);
builder.setDbName(dbName);
builder.setMeasurementName(measurementName);
builder.setValueFieldName(valueFieldName);
builder.setValue(Double.doubleToLongBits(value));
builder.addAllTags(tags);
builder.setTimestamp(timestamp);
builder.setFp(true);
dps.add(builder.build());
} else {
Builder builder = Point.newBuilder();
fv[1] = fv[1].substring(0, fv[1].length() - 1);
long value = Long.parseLong(fv[1]);
builder.setDbName(dbName);
builder.setMeasurementName(measurementName);
builder.setValueFieldName(valueFieldName);
builder.setValue(value);
builder.addAllTags(tags);
builder.setTimestamp(timestamp);
builder.setFp(false);
dps.add(builder.build());
}
}
} catch (Exception e) {
logger.fine("Rejected:" + split);
}
}
return dps;
}
use of com.srotya.sidewinder.core.rpc.Point.Builder in project sidewinder by srotya.
the class MiscUtils method buildDP.
public static Point buildDP(String dbName, String measurementName, String valueFieldName, List<String> tags, long timestamp, long value, boolean fp) {
Builder builder = Point.newBuilder();
builder.setDbName(dbName);
builder.setMeasurementName(measurementName);
builder.setValueFieldName(valueFieldName);
builder.addAllTags(tags);
builder.setTimestamp(timestamp);
builder.setValue(value);
builder.setFp(fp);
return builder.build();
}
use of com.srotya.sidewinder.core.rpc.Point.Builder in project sidewinder by srotya.
the class TestDatabaseOpsApi method testQuerySeries.
@Test
public void testQuerySeries() throws IOException {
MemStorageEngine engine = new MemStorageEngine();
engine.configure(new HashMap<>(), null);
engine.connect();
Builder dp = Point.newBuilder();
dp.setDbName("test1");
dp.setFp(false);
dp.setValue(1L);
dp.setMeasurementName("cpu");
dp.setTimestamp(System.currentTimeMillis());
dp.addAllTags(Arrays.asList("host=1", "vm=1"));
dp.setValueFieldName("value");
engine.writeDataPoint(dp.build());
DatabaseOpsApi api = new DatabaseOpsApi(engine);
String querySeries = api.querySeries("test1", "2000-12-10T10:10:10<cpu.value.host=1|te=2&vm=1<2020-12-10T10:10:10");
JsonArray results = new Gson().fromJson(querySeries, JsonArray.class);
assertEquals(1, results.size());
querySeries = api.querySeries("test1", "2000-12-10T10:10:10<cpu.value.host=2<2020-12-10T10:10:10");
results = new Gson().fromJson(querySeries, JsonArray.class);
assertEquals(0, results.size());
querySeries = api.querySeries("test1", "2000-12-10T10:10:10<cpu.value.vm=1<2020-12-10T10:10:10");
results = new Gson().fromJson(querySeries, JsonArray.class);
assertEquals(1, results.size());
System.out.println(results);
}
Aggregations