use of org.opennms.newts.api.Timestamp in project newts by OpenNMS.
the class CassandraSampleRepository method delete.
@Override
public void delete(Context context, Resource resource) {
/**
* Check for ttl value > 0
*/
if (m_ttl > 0) {
/**
* Delete exactly from (now - ttl) till now
*/
final Timestamp start = Timestamp.now().minus(m_ttl, TimeUnit.SECONDS);
final Timestamp end = Timestamp.now();
final Duration resourceShard = m_contextConfigurations.getResourceShard(context);
final List<Future<ResultSet>> futures = Lists.newArrayList();
for (Timestamp partition : new IntervalGenerator(start.stepFloor(resourceShard), end.stepFloor(resourceShard), resourceShard)) {
BoundStatement bindStatement = m_deleteStatement.bind();
bindStatement.setString(SchemaConstants.F_CONTEXT, context.getId());
bindStatement.setInt(SchemaConstants.F_PARTITION, (int) partition.asSeconds());
bindStatement.setString(SchemaConstants.F_RESOURCE, resource.getId());
futures.add(m_session.executeAsync(bindStatement));
}
for (final Future<ResultSet> future : futures) {
try {
future.get();
} catch (final InterruptedException | ExecutionException e) {
throw Throwables.propagate(e);
}
}
} else {
// Choose (now - one year) till now...
Timestamp end = Timestamp.now();
Timestamp start = end.minus(DELETION_INTERVAL, TimeUnit.DAYS);
// ... and check whether samples exist for this period of time.
while (cassandraSelect(context, resource, start, end).hasNext()) {
// Now delete the samples...
final Duration resourceShard = m_contextConfigurations.getResourceShard(context);
final List<Future<ResultSet>> futures = Lists.newArrayList();
for (Timestamp partition : new IntervalGenerator(start.stepFloor(resourceShard), end.stepFloor(resourceShard), resourceShard)) {
BoundStatement bindStatement = m_deleteStatement.bind();
bindStatement.setString(SchemaConstants.F_CONTEXT, context.getId());
bindStatement.setInt(SchemaConstants.F_PARTITION, (int) partition.asSeconds());
bindStatement.setString(SchemaConstants.F_RESOURCE, resource.getId());
futures.add(m_session.executeAsync(bindStatement));
}
for (final Future<ResultSet> future : futures) {
try {
future.get();
} catch (final InterruptedException | ExecutionException e) {
throw Throwables.propagate(e);
}
}
// ...set end to start and start to (end - one year)
end = start;
start = end.minus(DELETION_INTERVAL, TimeUnit.DAYS);
// and start over again until no more samples are found
}
}
}
use of org.opennms.newts.api.Timestamp in project newts by OpenNMS.
the class NewtsReporter method report.
@Override
@SuppressWarnings("rawtypes")
public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) {
Timestamp timestamp = Timestamp.fromEpochMillis(clock.getTime());
List<Sample> samples = Lists.newArrayList();
for (Map.Entry<String, Gauge> entry : gauges.entrySet()) {
reportGauge(samples, timestamp, entry.getKey(), entry.getValue());
}
for (Map.Entry<String, Counter> entry : counters.entrySet()) {
reportCounter(samples, timestamp, entry.getKey(), entry.getValue());
}
for (Map.Entry<String, Histogram> entry : histograms.entrySet()) {
reportHistogram(samples, timestamp, entry.getKey(), entry.getValue());
}
for (Map.Entry<String, Meter> entry : meters.entrySet()) {
reportMeter(samples, timestamp, entry.getKey(), entry.getValue());
}
for (Map.Entry<String, Timer> entry : timers.entrySet()) {
reportTimer(samples, timestamp, entry.getKey(), entry.getValue());
}
this.repository.insert(samples);
}
use of org.opennms.newts.api.Timestamp in project newts by OpenNMS.
the class MeasurementsResource method getMeasurements.
@POST
@Path("/{resource}")
@Timed
public Collection<Collection<MeasurementDTO>> getMeasurements(ResultDescriptorDTO descriptorDTO, @PathParam("resource") Resource resource, @QueryParam("start") Optional<TimestampParam> start, @QueryParam("end") Optional<TimestampParam> end, @QueryParam("resolution") Optional<DurationParam> resolution, @QueryParam("context") Optional<String> contextId) {
Optional<Timestamp> lower = Transform.toTimestamp(start);
Optional<Timestamp> upper = Transform.toTimestamp(end);
Optional<Duration> step = Transform.toDuration(resolution);
Context context = contextId.isPresent() ? new Context(contextId.get()) : Context.DEFAULT_CONTEXT;
LOG.debug("Retrieving measurements for resource {}, from {} to {} w/ resolution {} and w/ report {}", resource, lower, upper, step, descriptorDTO);
ResultDescriptor rDescriptor = Transform.resultDescriptor(descriptorDTO);
return Transform.measurementDTOs(m_repository.select(context, resource, lower, upper, rDescriptor, step));
}
use of org.opennms.newts.api.Timestamp in project newts by OpenNMS.
the class SelectDispatcher method go.
@Override
void go() throws InterruptedException {
createThreads();
for (Timestamp t : new IntervalGenerator(m_config.getStart(), m_config.getEnd(), m_config.getSelectLength(), true)) {
for (String resource : m_config.getResources()) {
m_queryQueue.put(new Query(resource, t.minus(m_config.getSelectLength()), t, m_config.getResolution()));
}
}
shutdown();
}
use of org.opennms.newts.api.Timestamp in project newts by OpenNMS.
the class LineParser method parseLine.
List<Sample> parseLine(String line) throws ParseException {
LOG.trace("Parsing {}", line);
List<Sample> samples = Lists.newArrayList();
Resource station = new Resource(stringAt(line, 0));
String wban = stringAt(line, 7);
String dateYMD = stringAt(line, 14);
Date date = getDateFormat().parse(dateYMD);
Timestamp ts = new Timestamp(date.getTime(), TimeUnit.MILLISECONDS);
double meanTemp = doubleAt(line, 24);
samples.add(new Sample(ts, station, "meanTemperature", GAUGE, LineParser.valueFor(meanTemp, 9999.9)));
double dewpoint = doubleAt(line, 35);
samples.add(new Sample(ts, station, "dewPoint", GAUGE, LineParser.valueFor(dewpoint, 9999.9)));
double slp = doubleAt(line, 46);
Gauge seaLevelPressure = LineParser.valueFor(slp, 9999.9);
samples.add(new Sample(ts, station, "seaLevelPressure", GAUGE, seaLevelPressure));
double stp = doubleAt(line, 57);
Gauge stationPressure = LineParser.valueFor(stp, 9999.9);
samples.add(new Sample(ts, station, "stationPressure", GAUGE, stationPressure));
double vis = doubleAt(line, 68);
Gauge visibility = LineParser.valueFor(vis, 999.9);
samples.add(new Sample(ts, station, "visibility", GAUGE, visibility));
double speed = doubleAt(line, 78);
Gauge meanWindSpeed = new Gauge(speed);
samples.add(new Sample(ts, station, "meanWindSpeed", GAUGE, meanWindSpeed));
double maxSpeed = doubleAt(line, 88);
Gauge maxWindSpeed = LineParser.valueFor(maxSpeed, 999.9);
samples.add(new Sample(ts, station, "maxWindSpeed", GAUGE, maxWindSpeed));
double maxGust = doubleAt(line, 95);
Gauge maxWindGust = LineParser.valueFor(maxGust, 999.9);
samples.add(new Sample(ts, station, "maxWindGust", GAUGE, maxWindGust));
double maxTemp = doubleAt(line, 102);
Gauge maxTemperature = LineParser.valueFor(maxTemp, 9999.9);
samples.add(new Sample(ts, station, "maxTemperature", GAUGE, maxTemperature));
double minTemp = doubleAt(line, 110);
Gauge minTemperature = LineParser.valueFor(minTemp, 9999.9);
samples.add(new Sample(ts, station, "minTemperature", GAUGE, minTemperature));
LOG.trace("Station number {}, WBAN {}, date {}, Max Temp {}...", station, wban, dateYMD, maxTemperature);
return samples;
}
Aggregations