/** * Record a value at a known time. This method is slightly faster than {@link #record(double)} since it will reuse * the time stamp. * @param value The value we are recording * @param timeMs The current POSIX time in milliseconds * @throws QuotaViolationException if recording this value moves a metric beyond its configured maximum or minimum * bound */ public void record(double value, long timeMs) { record(value, timeMs, true); }
void recordBatchSplit() { this.batchSplitSensor.record(); } }
protected void maybeRecordEndOfDrySpell() { if (oomTimeSensor != null) { long startOfDrySpell = startOfNoMemPeriod.getAndSet(0); if (startOfDrySpell != 0) { //how long were we refusing allocation requests for oomTimeSensor.record((System.nanoTime() - startOfDrySpell) / 1000000.0); //fractional (double) millis } } } }
public void recordErrors(String topic, int count) { long now = time.milliseconds(); this.errorSensor.record(count, now); String topicErrorName = "topic." + topic + ".record-errors"; Sensor topicErrorSensor = this.metrics.getSensor(topicErrorName); if (topicErrorSensor != null) topicErrorSensor.record(count, now); }
public void recordBytesReceived(String connection, int bytes) { long now = time.milliseconds(); this.bytesReceived.record(bytes, now); if (!connection.isEmpty()) { String nodeRequestName = "node-" + connection + ".bytes-received"; Sensor nodeRequest = this.metrics.getSensor(nodeRequestName); if (nodeRequest != null) nodeRequest.record(bytes, now); } }
public void recordLatency(String node, long latency) { long now = time.milliseconds(); this.requestTimeSensor.record(latency, now); if (!node.isEmpty()) { String nodeTimeName = "node-" + node + ".latency"; Sensor nodeRequestTime = this.metrics.getSensor(nodeTimeName); if (nodeRequestTime != null) nodeRequestTime.record(latency, now); } }
public void recordRetries(String topic, int count) { long now = time.milliseconds(); this.retrySensor.record(count, now); String topicRetryName = "topic." + topic + ".record-retries"; Sensor topicRetrySensor = this.metrics.getSensor(topicRetryName); if (topicRetrySensor != null) topicRetrySensor.record(count, now); }
public void recordBytesSent(String connectionId, long bytes) { long now = time.milliseconds(); this.bytesSent.record(bytes, now); if (!connectionId.isEmpty()) { String nodeRequestName = "node-" + connectionId + ".bytes-sent"; Sensor nodeRequest = this.metrics.getSensor(nodeRequestName); if (nodeRequest != null) nodeRequest.record(bytes, now); } }
/** * Record an occurrence, this is just short-hand for {@link #record(double) record(1.0)} */ public void record() { if (shouldRecord()) { record(1.0); } }
protected void recordWaitTime(long timeNs) { this.waitTime.record(timeNs, time.milliseconds()); }
/** * Record a value with this sensor * @param value The value to record * @throws QuotaViolationException if recording this value moves a metric beyond its configured maximum or minimum * bound */ public void record(double value) { if (shouldRecord()) { record(value, time.milliseconds()); } }
private void recordPartitionLead(TopicPartition tp, long lead) { this.recordsFetchLead.record(lead); String name = partitionLeadMetricName(tp); Sensor recordsLead = this.metrics.getSensor(name); if (recordsLead == null) { Map<String, String> metricTags = new HashMap<>(2); metricTags.put("topic", tp.topic().replace('.', '_')); metricTags.put("partition", String.valueOf(tp.partition())); recordsLead = this.metrics.sensor(name); recordsLead.add(this.metrics.metricInstance(metricsRegistry.partitionRecordsLead, metricTags), new Value()); recordsLead.add(this.metrics.metricInstance(metricsRegistry.partitionRecordsLeadMin, metricTags), new Min()); recordsLead.add(this.metrics.metricInstance(metricsRegistry.partitionRecordsLeadAvg, metricTags), new Avg()); } recordsLead.record(lead); }
private void recordPartitionLag(TopicPartition tp, long lag) { this.recordsFetchLag.record(lag); String name = partitionLagMetricName(tp); Sensor recordsLag = this.metrics.getSensor(name); if (recordsLag == null) { Map<String, String> metricTags = new HashMap<>(2); metricTags.put("topic", tp.topic().replace('.', '_')); metricTags.put("partition", String.valueOf(tp.partition())); recordsLag = this.metrics.sensor(name); recordsLag.add(this.metrics.metricInstance(metricsRegistry.partitionRecordsLag, metricTags), new Value()); recordsLag.add(this.metrics.metricInstance(metricsRegistry.partitionRecordsLagMax, metricTags), new Max()); recordsLag.add(this.metrics.metricInstance(metricsRegistry.partitionRecordsLagAvg, metricTags), new Avg()); } recordsLag.record(lag); }
@Override public Throwable call() { try { assertTrue(latch.await(5, TimeUnit.SECONDS)); for (int j = 0; j != 20; ++j) { sensor.record(j * index, System.currentTimeMillis() + j, false); sensor.checkQuotas(); } return null; } catch (Throwable e) { return e; } } }));
public void record(double value, long timeMs, boolean checkQuotas) { if (shouldRecord()) { this.lastRecordTime = timeMs; synchronized (this) { synchronized (metricLock()) { // increment all the stats for (Stat stat : this.stats) stat.record(config, value, timeMs); } if (checkQuotas) checkQuotas(timeMs); } for (Sensor parent : parents) parent.record(value, timeMs, checkQuotas); } }
@Test public void testGetAttributesWithUnknown() throws Exception { sensor.record(3.5); sensor.record(4.0); AttributeList attributeList = getAttributes(countMetricName, countMetricName.name(), sumMetricName.name(), "name"); List<Attribute> attributes = attributeList.asList(); assertEquals(2, attributes.size()); for (Attribute attribute : attributes) { if (countMetricName.name().equals(attribute.getName())) assertEquals(2.0, attribute.getValue()); else if (sumMetricName.name().equals(attribute.getName())) assertEquals(7.5, attribute.getValue()); else fail("Unexpected attribute returned: " + attribute.getName()); } }
@Test public void testGetAttributeUnknown() throws Exception { sensor.record(2.5); try { getAttribute(sumMetricName, "name"); fail("Should have gotten attribute not found"); } catch (AttributeNotFoundException e) { // Expected } }
private static Struct parseStructMaybeUpdateThrottleTimeMetrics(ByteBuffer responseBuffer, RequestHeader requestHeader, Sensor throttleTimeSensor, long now) { ResponseHeader responseHeader = ResponseHeader.parse(responseBuffer); // Always expect the response version id to be the same as the request version id Struct responseBody = requestHeader.apiKey().parseResponse(requestHeader.apiVersion(), responseBuffer); correlate(requestHeader, responseHeader); if (throttleTimeSensor != null && responseBody.hasField(CommonFields.THROTTLE_TIME_MS)) throttleTimeSensor.record(responseBody.get(CommonFields.THROTTLE_TIME_MS), now); return responseBody; }
@Test public void testGetAttributes() throws Exception { sensor.record(3.5); sensor.record(4.0); AttributeList attributeList = getAttributes(countMetricName, countMetricName.name(), sumMetricName.name()); List<Attribute> attributes = attributeList.asList(); assertEquals(2, attributes.size()); for (Attribute attribute : attributes) { if (countMetricName.name().equals(attribute.getName())) assertEquals(2.0, attribute.getValue()); else if (sumMetricName.name().equals(attribute.getName())) assertEquals(7.5, attribute.getValue()); else fail("Unexpected attribute returned: " + attribute.getName()); } }
@Test public void testGetAttribute() throws Exception { sensor.record(2.5); Object counterAttribute = getAttribute(countMetricName); assertEquals(1.0, counterAttribute); Object sumAttribute = getAttribute(sumMetricName); assertEquals(2.5, sumAttribute); }