use of io.cdap.cdap.api.metrics.MetricValue in project cdap by cdapio.
the class DefaultMetricStore method add.
@Override
public void add(Collection<? extends MetricValues> metricValues) {
List<CubeFact> facts = Lists.newArrayListWithCapacity(metricValues.size());
for (MetricValues metricValue : metricValues) {
String scope = metricValue.getTags().get(Constants.Metrics.Tag.SCOPE);
List<Measurement> metrics = Lists.newArrayList();
// todo improve this logic?
for (MetricValue metric : metricValue.getMetrics()) {
String measureName = (scope == null ? "system." : scope + ".") + metric.getName();
if (metric.getType() == MetricType.DISTRIBUTION) {
// https://cdap.atlassian.net/browse/CDAP-18769
continue;
}
MeasureType type = metric.getType() == MetricType.COUNTER ? MeasureType.COUNTER : MeasureType.GAUGE;
metrics.add(new Measurement(measureName, type, metric.getValue()));
}
CubeFact fact = new CubeFact(metricValue.getTimestamp()).addDimensionValues(metricValue.getTags()).addMeasurements(metrics);
facts.add(fact);
}
cube.get().add(facts);
}
use of io.cdap.cdap.api.metrics.MetricValue in project cdap by cdapio.
the class MessagingMetricsProcessorService method persistMetrics.
/**
* Persist metrics into metric store
*
* @param metricValues a non-empty deque of {@link MetricValues}
*/
private void persistMetrics(Deque<MetricValues> metricValues) {
long now = System.currentTimeMillis();
long lastMetricTime = metricValues.peekLast().getTimestamp();
List<MetricValue> topicLevelDelays = new ArrayList<>();
// write topic level delay metrics
for (TopicProcessMeta topicProcessMeta : metadataHandler.getCache().values()) {
long delay = now - TimeUnit.SECONDS.toMillis(topicProcessMeta.getOldestMetricsTimestamp());
topicLevelDelays.add(new MetricValue(topicProcessMeta.getOldestMetricsTimestampMetricName(), MetricType.GAUGE, delay));
delay = now - TimeUnit.SECONDS.toMillis(topicProcessMeta.getLatestMetricsTimestamp());
topicLevelDelays.add(new MetricValue(topicProcessMeta.getLatestMetricsTimestampMetricName(), MetricType.GAUGE, delay));
}
List<MetricValue> processorMetrics = new ArrayList<>(topicLevelDelays);
processorMetrics.add(new MetricValue(processMetricName, MetricType.COUNTER, metricValues.size()));
metricValues.add(new MetricValues(metricsContextMap, TimeUnit.MILLISECONDS.toSeconds(now), processorMetrics));
metricsWriter.write(metricValues);
metricsProcessedCount += metricValues.size();
PROGRESS_LOG.debug("{} metrics persisted with {}. Last metric's timestamp: {}", metricsProcessedCount, metricsWriter.getID(), lastMetricTime);
}
use of io.cdap.cdap.api.metrics.MetricValue in project cdap by caskdata.
the class JMXMetricsCollector method runOneIteration.
@Override
protected void runOneIteration() {
Collection<MetricValue> metrics = new ArrayList<>();
try (JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceUrl, null)) {
MBeanServerConnection mBeanConn = jmxConnector.getMBeanServerConnection();
metrics.addAll(getMemoryMetrics(mBeanConn));
metrics.addAll(getCPUMetrics(mBeanConn));
metrics.addAll(getThreadMetrics(mBeanConn));
} catch (IOException e) {
LOG.error("Error occurred while connecting to JMX server.", e);
return;
}
try {
this.metricsPublisher.publish(metrics, this.metricTags);
} catch (Exception e) {
LOG.warn("Error occurred while publishing resource usage metrics.", e);
}
}
use of io.cdap.cdap.api.metrics.MetricValue in project cdap by caskdata.
the class JMXMetricsCollector method getMemoryMetrics.
Collection<MetricValue> getMemoryMetrics(MBeanServerConnection mBeanConn) throws IOException {
MemoryMXBean mxBean = ManagementFactory.newPlatformMXBeanProxy(mBeanConn, ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class);
MemoryUsage heapMemoryUsage = mxBean.getHeapMemoryUsage();
Collection<MetricValue> metrics = new ArrayList<>();
metrics.add(new MetricValue(Constants.Metrics.JVMResource.HEAP_USED_MB, MetricType.GAUGE, heapMemoryUsage.getUsed() / MEGA_BYTE));
if (heapMemoryUsage.getMax() >= 0) {
metrics.add(new MetricValue(Constants.Metrics.JVMResource.HEAP_MAX_MB, MetricType.GAUGE, heapMemoryUsage.getMax() / MEGA_BYTE));
}
return metrics;
}
use of io.cdap.cdap.api.metrics.MetricValue in project cdap by caskdata.
the class JMXMetricsCollector method getCPUMetrics.
Collection<MetricValue> getCPUMetrics(MBeanServerConnection conn) throws IOException {
OperatingSystemMXBean mxBean = ManagementFactory.newPlatformMXBeanProxy(conn, ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class);
Collection<MetricValue> metrics = new ArrayList<>();
double systemLoad = mxBean.getSystemLoadAverage();
if (systemLoad < 0) {
LOG.info("CPU load for JVM process is not yet available");
} else {
double processorCount = mxBean.getAvailableProcessors();
double systemLoadPerProcessorScaled = (systemLoad * SYSTEM_LOAD_SCALING_FACTOR) / processorCount;
metrics.add(new MetricValue(Constants.Metrics.JVMResource.SYSTEM_LOAD_PER_PROCESSOR_SCALED, MetricType.GAUGE, (long) systemLoadPerProcessorScaled));
}
return metrics;
}
Aggregations