use of org.springframework.boot.actuate.metrics.Metric in project spring-boot by spring-projects.
the class MetricsEndpointMetricReader method findAll.
@Override
public Iterable<Metric<?>> findAll() {
List<Metric<?>> metrics = new ArrayList<>();
Map<String, Object> values = this.endpoint.invoke();
Date timestamp = new Date();
for (Entry<String, Object> entry : values.entrySet()) {
String name = entry.getKey();
Object value = entry.getValue();
metrics.add(new Metric<>(name, (Number) value, timestamp));
}
return metrics;
}
use of org.springframework.boot.actuate.metrics.Metric in project spring-boot by spring-projects.
the class MetricRegistryMetricReader method findOne.
@Override
public Metric<?> findOne(String metricName) {
String name = this.names.get(metricName);
if (name == null) {
return null;
}
com.codahale.metrics.Metric metric = this.registry.getMetrics().get(name);
if (metric == null) {
return null;
}
if (metric instanceof Counter) {
Counter counter = (Counter) metric;
return new Metric<Number>(metricName, counter.getCount());
}
if (metric instanceof Gauge) {
Object value = ((Gauge<?>) metric).getValue();
if (value instanceof Number) {
return new Metric<>(metricName, (Number) value);
}
if (logger.isDebugEnabled()) {
logger.debug("Ignoring gauge '" + name + "' (" + metric + ") as its value is not a Number");
}
return null;
}
if (metric instanceof Sampling) {
if (metricName.contains(".snapshot.")) {
Number value = getMetric(((Sampling) metric).getSnapshot(), metricName);
if (metric instanceof Timer) {
// convert back to MILLISEC
value = TimeUnit.MILLISECONDS.convert(value.longValue(), TimeUnit.NANOSECONDS);
}
return new Metric<>(metricName, value);
}
}
return new Metric<>(metricName, getMetric(metric, metricName));
}
use of org.springframework.boot.actuate.metrics.Metric in project spring-boot by spring-projects.
the class DataSourcePublicMetrics method metrics.
@Override
public Collection<Metric<?>> metrics() {
Set<Metric<?>> metrics = new LinkedHashSet<>();
for (Map.Entry<String, DataSourcePoolMetadata> entry : this.metadataByPrefix.entrySet()) {
String prefix = entry.getKey();
prefix = (prefix.endsWith(".") ? prefix : prefix + ".");
DataSourcePoolMetadata metadata = entry.getValue();
addMetric(metrics, prefix + "active", metadata.getActive());
addMetric(metrics, prefix + "usage", metadata.getUsage());
}
return metrics;
}
use of org.springframework.boot.actuate.metrics.Metric in project cas by apereo.
the class CasMetricsRepositoryConfiguration method mongoDbMetricWriter.
@ConditionalOnProperty(prefix = "cas.metrics.mongo", name = "collection")
@Bean
@ExportMetricWriter
public GaugeWriter mongoDbMetricWriter() {
final MetricsProperties.MongoDb prop = casProperties.getMetrics().getMongo();
final MongoDbConnectionFactory factory = new MongoDbConnectionFactory();
final MongoTemplate mongoTemplate = factory.buildMongoTemplate(prop);
return metric -> {
final MongoDbMetric metrics = new MongoDbMetric(metric);
mongoTemplate.save(metrics, prop.getCollection());
};
}
Aggregations