@Override public void onSubscribe(Subscription s) { if (Operators.validate(this.s, s)) { this.subscribedCounter.increment(); this.subscribeToTerminateSample = Timer.start(clock); this.lastNextEventNanos = clock.monotonicTime(); if (s instanceof Fuseable.QueueSubscription) { //noinspection unchecked this.qs = (Fuseable.QueueSubscription<T>) s; } this.s = s; actual.onSubscribe(this); } }
@Override public long wallTime() { return clock.wallTime(); }
@Override public long wallTime() { return clock.wallTime(); }
@Override public void onNext(T t) { if (done) { this.malformedSourceCounter.increment(); Operators.onNextDropped(t, actual.currentContext()); return; } //record the delay since previous onNext/onSubscribe. This also records the count. long last = this.lastNextEventNanos; this.lastNextEventNanos = clock.monotonicTime(); this.onNextIntervalTimer.record(lastNextEventNanos - last, TimeUnit.NANOSECONDS); actual.onNext(t); }
@Override public long wallTime() { return impl.wallTime(); }
@Override @Nullable public T poll() { if (qs == null) { return null; } try { T v = qs.poll(); if (v == null && fusionMode == SYNC) { //this is also a complete event this.subscribeToTerminateSample.stop(subscribeToCompleteTimer); } if (v != null) { //this is an onNext event //record the delay since previous onNext/onSubscribe. This also records the count. long last = this.lastNextEventNanos; this.lastNextEventNanos = clock.monotonicTime(); this.onNextIntervalTimer.record(lastNextEventNanos - last, TimeUnit.NANOSECONDS); } return v; } catch (Throwable e) { //register a timer for that particular exception Timer timer = subscribeToErrorTimerFactory.apply(e); //record error termination this.subscribeToTerminateSample.stop(timer); throw e; } }
private String indexName() { ZonedDateTime dt = ZonedDateTime.ofInstant(new Date(config().clock().wallTime()).toInstant(), ZoneOffset.UTC); return config.index() + "-" + DateTimeFormatter.ofPattern(config.indexDateFormat()).format(dt); }
@Override public void onNext(T t) { if (this.fusionMode == Fuseable.ASYNC) { actual.onNext(null); return; } if (done) { this.malformedSourceCounter.increment(); Operators.onNextDropped(t, actual.currentContext()); return; } //record the delay since previous onNext/onSubscribe. This also records the count. long last = this.lastNextEventNanos; this.lastNextEventNanos = clock.monotonicTime(); this.onNextIntervalTimer.record(lastNextEventNanos - last, TimeUnit.NANOSECONDS); actual.onNext(t); }
String writeDocument(Meter meter, Consumer<StringBuilder> consumer) { StringBuilder sb = new StringBuilder(INDEX_LINE); String timestamp = FORMATTER.format(Instant.ofEpochMilli(config().clock().wallTime())); String name = getConventionName(meter.getId()); String type = meter.getId().getType().toString().toLowerCase(); sb.append("{\"").append(config.timestampFieldName()).append("\":\"").append(timestamp).append('"') .append(",\"name\":\"").append(escapeJson(name)).append('"') .append(",\"type\":\"").append(type).append('"'); List<Tag> tags = getConventionTags(meter.getId()); for (Tag tag : tags) { sb.append(",\"").append(escapeJson(tag.getKey())).append("\":\"") .append(escapeJson(tag.getValue())).append('"'); } consumer.accept(sb); sb.append("}"); return sb.toString(); }
@Override public long monotonicTime() { return clock.monotonicTime(); } }, config);
Stream<String> writeFunctionCounter(FunctionCounter counter) { double count = counter.count(); if (Double.isFinite(count)) { return Stream.of(writeMetric(counter.getId(), config().clock().wallTime(), count)); } return Stream.empty(); }
@Override public long monotonicTime() { return clock.monotonicTime(); } }), clock, config.step().toMillis());
Stream<String> writeGauge(Gauge gauge) { Double value = gauge.value(); if (Double.isFinite(value)) { return Stream.of(writeMetric(gauge.getId(), config().clock().wallTime(), value)); } return Stream.empty(); }
@Override public long monotonicTime() { return impl.monotonicTime(); } }
private Stream<String> writeMeter(Meter m, Map<String, DatadogMetricMetadata> metadata) { long wallTime = clock.wallTime(); return stream(m.measure().spliterator(), false) .map(ms -> { Meter.Id id = m.getId().withTag(ms.getStatistic()); addToMetadataList(metadata, id, null, ms.getStatistic(), null); return writeMetric(id, null, wallTime, ms.getValue()); }); }
public long start() { long task = nextTask.getAndIncrement(); tasks.put(task, clock.monotonicTime()); return task; }
private Stream<String> writeMeter(Meter meter) { long wallTime = clock.wallTime(); Stream.Builder<String> metrics = Stream.builder(); stream(meter.measure().spliterator(), false) .forEach(measurement -> { Meter.Id id = meter.getId().withTag(measurement.getStatistic()); addMetric(metrics, id, null, wallTime, measurement.getValue()); }); return metrics.build(); }
public long stop(long task) { Long startTime = tasks.get(task); if (startTime != null) { tasks.remove(task); return clock.monotonicTime() - startTime; } else { return -1L; } }
Stream<String> writeCounter(Counter counter) { return Stream.of(writeMetric(counter.getId(), config().clock().wallTime(), counter.count())); }
public double duration(TimeUnit unit) { long now = clock.monotonicTime(); long sum = 0L; for (long startTime : tasks.values()) { sum += now - startTime; } return TimeUtils.nanosToUnit(sum, unit); }