use of com.netflix.spectator.api.Measurement in project incubator-servicecomb-java-chassis by apache.
the class MeasurementTree method from.
public void from(Iterable<Measurement> measurements, MeasurementGroupConfig groupConfig) {
for (Measurement measurement : measurements) {
Id id = measurement.id();
List<TagFinder> tagFinders = groupConfig.findTagFinders(id.name());
if (tagFinders == null) {
continue;
}
MeasurementNode node = addChild(id.name(), measurement);
for (TagFinder tagFinder : tagFinders) {
Tag tag = tagFinder.find(id.tags());
if (tag == null) {
throw new IllegalStateException(String.format("tag key \"%s\" not exist in %s", tagFinder.getTagKey(), measurement));
}
node = node.addChild(tag.value(), measurement);
}
}
}
use of com.netflix.spectator.api.Measurement in project incubator-servicecomb-java-chassis by apache.
the class Utils method createStageNode.
public static MeasurementNode createStageNode(String stage, double count, double totalTime, double max) {
Id id = registry.createId("id").withTag(Statistic.count);
Measurement countMeasurement = new Measurement(id.withTag(Statistic.count), 0, count);
Measurement totalTimeMeasurement = new Measurement(id.withTag(Statistic.totalTime), 0, totalTime);
Measurement maxMeasurement = new Measurement(id.withTag(Statistic.max), 0, max);
MeasurementNode stageNode = new MeasurementNode(stage, null);
stageNode.addChild(Statistic.count.name(), countMeasurement);
stageNode.addChild(Statistic.totalTime.name(), totalTimeMeasurement);
stageNode.addChild(Statistic.max.name(), maxMeasurement);
return stageNode;
}
use of com.netflix.spectator.api.Measurement in project kork by spinnaker.
the class StackdriverWriter method addMeterToTimeSeries.
/**
* Add a TimeSeries for each appropriate meter measurement.
*/
void addMeterToTimeSeries(Registry registry, Meter meter, List<TimeSeries> tsList) {
Iterable<Measurement> measurements = meter.measure();
boolean applyFilter = true;
if (cache.meterIsTimer(registry, meter)) {
measurements = transformTimerMeasurements(measurements);
applyFilter = false;
}
for (Measurement measurement : measurements) {
if (applyFilter && !measurementFilter.test(measurement)) {
continue;
}
String descriptorType = cache.idToDescriptorType(measurement.id());
tsList.add(measurementToTimeSeries(descriptorType, registry, meter, measurement));
}
}
use of com.netflix.spectator.api.Measurement in project kork by spinnaker.
the class StackdriverWriter method transformTimerMeasurements.
/**
* Transform timer measurements from a composite with count/totalTime tags
* to a pair of specialized measurements without the "statistic" tag.
*
* This is so we can have different units for the measurement
* MetricDescriptor to note that the totalTime is in nanoseconds.
*
* @param measurements
* The list of measurements to transform come from a Timer meter.
*
* @return
* A list of measurements, probably the same as the original size, where
* each of the elements corresponds to an original element but does not
* have the "statistic" label. Where the original was "count", the new
* id name will have a "__count" suffix and "__totalTime" for the
* "totalTime" statistic. The base name will be the same as the original.
*/
private Iterable<Measurement> transformTimerMeasurements(Iterable<Measurement> measurements) {
ArrayList<Measurement> result = new ArrayList<Measurement>();
for (Measurement measurement : measurements) {
if (!measurementFilter.test(measurement)) {
continue;
}
Id id = timerBaseIds.computeIfAbsent(measurement.id(), k -> deriveBaseTimerId(k));
result.add(new Measurement(id, measurement.timestamp(), measurement.value()));
}
return result;
}
use of com.netflix.spectator.api.Measurement in project kork by spinnaker.
the class StackdriverConfig method defaultStackdriverWriter.
/**
* Schedule a thread to flush our registry into stackdriver periodically.
*
* This configures our StackdriverWriter as well.
*/
@Bean
public StackdriverWriter defaultStackdriverWriter(Environment environment, Registry registry, SpectatorStackdriverConfigurationProperties spectatorStackdriverConfigurationProperties) throws IOException {
Logger log = LoggerFactory.getLogger("StackdriverConfig");
log.info("Creating StackdriverWriter.");
Predicate<Measurement> filterNotSpring = new Predicate<Measurement>() {
public boolean test(Measurement measurement) {
// These are from spring; those of interest were replicated in spectator.
if (measurement.id().tags().iterator().hasNext()) {
return true;
}
return false;
}
};
Predicate<Measurement> measurementFilter;
final String prototypeFilterPath = spectatorStackdriverConfigurationProperties.getWebEndpoint().getPrototypeFilter().getPath();
if (!prototypeFilterPath.isEmpty()) {
log.error("Ignoring prototypeFilterPath because it is not yet supported.");
measurementFilter = null;
log.info("Configuring stackdriver filter from {}", prototypeFilterPath);
measurementFilter = PrototypeMeasurementFilter.loadFromPath(prototypeFilterPath).and(filterNotSpring);
} else {
measurementFilter = filterNotSpring;
}
InetAddress hostaddr = serverProperties.getAddress();
if (hostaddr.equals(InetAddress.getLoopbackAddress())) {
hostaddr = InetAddress.getLocalHost();
}
String host = hostaddr.getCanonicalHostName();
String hostPort = host + ":" + serverProperties.getPort();
ConfigParams params = new ConfigParams.Builder().setCounterStartTime(new Date().getTime()).setCustomTypeNamespace("spinnaker").setProjectName(spectatorStackdriverConfigurationProperties.getStackdriver().getProjectName()).setApplicationName(spectatorStackdriverConfigurationProperties.getApplicationName(environment.getProperty("spring.application.name"))).setCredentialsPath(spectatorStackdriverConfigurationProperties.getStackdriver().getCredentialsPath()).setMeasurementFilter(measurementFilter).setInstanceId(hostPort).build();
stackdriver = new StackdriverWriter(params);
Scheduler scheduler = Schedulers.from(Executors.newFixedThreadPool(1));
Observable.timer(spectatorStackdriverConfigurationProperties.getStackdriver().getPeriod(), TimeUnit.SECONDS).repeat().subscribe(interval -> {
stackdriver.writeRegistry(registry);
});
return stackdriver;
}
Aggregations