use of com.srotya.sidewinder.core.rpc.Point 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 in project sidewinder by srotya.
the class TestInfluxDecoder method testIdenticalWriteMultipoints.
@Test
public void testIdenticalWriteMultipoints() {
String testPoints = "cpu,host=server01,region=uswest value=1i 1434055562000000000\ncpu,host=server01,region=uswest value=1i 1434055562000000000\ncpu,host=server01,region=uswest value=1i 1434055562000000000";
List<Point> dps = InfluxDecoder.pointsFromString("test", testPoints);
for (Point dp : dps) {
assertEquals("cpu", dp.getMeasurementName());
assertTrue(dp.getTagsList().contains("host=server01"));
assertTrue(dp.getTagsList().contains("region=uswest"));
assertEquals(1, dp.getValue());
assertEquals(1434055562000000000L / (1000 * 1000), dp.getTimestamp());
}
}
use of com.srotya.sidewinder.core.rpc.Point in project sidewinder by srotya.
the class TestInfluxDecoder method testSinglePointMeasurementValueWithoutTimestamp.
@Test
public void testSinglePointMeasurementValueWithoutTimestamp() {
String testPoints = "cpu value=1i";
List<Point> dps = InfluxDecoder.pointsFromString("test", testPoints);
assertEquals(1, dps.size());
Point dp = dps.get(0);
assertEquals("cpu", dp.getMeasurementName());
assertEquals(0, dp.getTagsList().size());
assertEquals(1, dp.getValue());
long ts = System.currentTimeMillis();
assertTrue(dp.getTimestamp() > 0);
assertEquals(1, (dp.getTimestamp() / ts), 1);
}
use of com.srotya.sidewinder.core.rpc.Point in project sidewinder by srotya.
the class TestInfluxDecoder method testIdenticalWriteSinglePoint.
@Test
public void testIdenticalWriteSinglePoint() {
String testPoints = "cpu,host=server01,region=uswest value=1i 1434055562000000000";
List<Point> dps = InfluxDecoder.pointsFromString("test", testPoints);
Point dp = dps.get(0);
assertEquals("cpu", dp.getMeasurementName());
assertTrue(dp.getTagsList().contains("host=server01"));
assertTrue(dp.getTagsList().contains("region=uswest"));
assertEquals(1, dp.getValue());
assertEquals(1434055562000000000L / (1000 * 1000), dp.getTimestamp());
}
use of com.srotya.sidewinder.core.rpc.Point in project sidewinder by srotya.
the class TestInfluxDecoder method testSinglePointMeasurementValue.
@Test
public void testSinglePointMeasurementValue() {
String testPoints = "cpu value=1i 1434055562000000000";
List<Point> dps = InfluxDecoder.pointsFromString("test", testPoints);
assertEquals(1, dps.size());
Point dp = dps.get(0);
assertEquals("cpu", dp.getMeasurementName());
assertEquals(0, dp.getTagsList().size());
assertEquals(1, dp.getValue());
assertEquals(1434055562000000000L / (1000 * 1000), dp.getTimestamp());
}
Aggregations