Search in sources :

Example 1 with Measurement

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);
        }
    }
}
Also used : Measurement(com.netflix.spectator.api.Measurement) Id(com.netflix.spectator.api.Id) Tag(com.netflix.spectator.api.Tag)

Example 2 with 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;
}
Also used : Measurement(com.netflix.spectator.api.Measurement) MeasurementNode(org.apache.servicecomb.foundation.metrics.publish.spectator.MeasurementNode) Id(com.netflix.spectator.api.Id)

Example 3 with Measurement

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));
    }
}
Also used : Measurement(com.netflix.spectator.api.Measurement)

Example 4 with 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;
}
Also used : Measurement(com.netflix.spectator.api.Measurement) ArrayList(java.util.ArrayList) Id(com.netflix.spectator.api.Id)

Example 5 with Measurement

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;
}
Also used : Measurement(com.netflix.spectator.api.Measurement) Scheduler(rx.Scheduler) StackdriverWriter(com.netflix.spectator.stackdriver.StackdriverWriter) Logger(org.slf4j.Logger) InetAddress(java.net.InetAddress) Date(java.util.Date) Predicate(java.util.function.Predicate) ConfigParams(com.netflix.spectator.stackdriver.ConfigParams) Bean(org.springframework.context.annotation.Bean)

Aggregations

Measurement (com.netflix.spectator.api.Measurement)8 Id (com.netflix.spectator.api.Id)3 Meter (com.netflix.spectator.api.Meter)3 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Tag (com.netflix.spectator.api.Tag)1 ConfigParams (com.netflix.spectator.stackdriver.ConfigParams)1 StackdriverWriter (com.netflix.spectator.stackdriver.StackdriverWriter)1 InetAddress (java.net.InetAddress)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 Predicate (java.util.function.Predicate)1 MeasurementNode (org.apache.servicecomb.foundation.metrics.publish.spectator.MeasurementNode)1 Logger (org.slf4j.Logger)1 Bean (org.springframework.context.annotation.Bean)1 Scheduler (rx.Scheduler)1