Java Code Examples for io.micrometer.core.instrument.Meter#Type

The following examples show how to use io.micrometer.core.instrument.Meter#Type . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertiesMeterFilter.java    From foremast with Apache License 2.0 5 votes vote down vote up
private long[] convertSla(Meter.Type meterType, ServiceLevelAgreementBoundary[] sla) {
    if (sla == null) {
        return null;
    }
    long[] converted = Arrays.stream(sla)
            .map((candidate) -> candidate.getValue(meterType))
            .filter(Objects::nonNull).mapToLong(Long::longValue).toArray();
    return (converted.length != 0) ? converted : null;
}
 
Example 2
Source File: MeterValue.java    From foremast with Apache License 2.0 5 votes vote down vote up
/**
 * Return the underlying value of the SLA in form suitable to apply to the given meter
 * type.
 * @param meterType the meter type
 * @return the value or {@code null} if the value cannot be applied
 */
public Long getValue(Meter.Type meterType) {
    if (meterType == Meter.Type.DISTRIBUTION_SUMMARY) {
        return getDistributionSummaryValue();
    }
    if (meterType == Meter.Type.TIMER) {
        return getTimerValue();
    }
    return null;
}
 
Example 3
Source File: PropertiesMeterFilter.java    From foremast with Apache License 2.0 5 votes vote down vote up
private long[] convertSla(Meter.Type meterType, ServiceLevelAgreementBoundary[] sla) {
    if (sla == null) {
        return null;
    }
    long[] converted = Arrays.stream(sla)
            .map((candidate) -> candidate.getValue(meterType))
            .filter(Objects::nonNull).mapToLong(Long::longValue).toArray();
    return (converted.length != 0) ? converted : null;
}
 
Example 4
Source File: MeterValue.java    From foremast with Apache License 2.0 5 votes vote down vote up
/**
 * Return the underlying value of the SLA in form suitable to apply to the given meter
 * type.
 * @param meterType the meter type
 * @return the value or {@code null} if the value cannot be applied
 */
public Long getValue(Meter.Type meterType) {
    if (meterType == Meter.Type.DISTRIBUTION_SUMMARY) {
        return getDistributionSummaryValue();
    }
    if (meterType == Meter.Type.TIMER) {
        return getTimerValue();
    }
    return null;
}
 
Example 5
Source File: SkywalkingMeterRegistry.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
protected Meter newMeter(Meter.Id id, Meter.Type type, Iterable<Measurement> measurements) {
    final MeterId meterId = convertId(id);
    final String baseName = meterId.getName();

    measurements.forEach(m -> {
        String meterName = baseName;
        boolean isCounter = false;
        switch (m.getStatistic()) {
            case TOTAL:
            case TOTAL_TIME:
                meterName = baseName + "_sum";
                isCounter = true;
                break;
            case COUNT:
                isCounter = true;
                break;
            case MAX:
                meterName = baseName + "_max";
                break;
            case ACTIVE_TASKS:
                meterName = baseName + "_active_count";
                break;
            case DURATION:
                meterName = baseName + "_duration_sum";
                break;
        }

        if (isCounter) {
            new SkywalkingCustomCounter.Builder(meterId.copyTo(meterName, MeterId.MeterType.COUNTER), m, config).build();
        } else {
            MeterFactory.gauge(meterId.copyTo(meterName, MeterId.MeterType.GAUGE), () -> m.getValue()).build();
        }
    });

    return new DefaultMeter(id, type, measurements);
}
 
Example 6
Source File: SkywalkingMeterRegistryTest.java    From skywalking with Apache License 2.0 5 votes vote down vote up
/**
 * Check custom measurement
 */
private void testNewMeter(String meterName, Meter.Type type, Statistic statistic, Consumer<MeterData> meterChecker) {
    final SkywalkingMeterRegistry registry = new SkywalkingMeterRegistry();

    // Create measurement
    Meter.builder(meterName, type, Arrays.asList(new Measurement(() -> 1d, statistic)))
        .tag("skywalking", "test")
        .register(registry);
    final List<MeterId.Tag> tags = Arrays.asList(new MeterId.Tag("skywalking", "test"));
    Assert.assertEquals(1, meterMap.size());
    meterChecker.accept(new MeterData(meterMap.values().iterator().next(), tags));

    // clear all data
    cleanup();
}
 
Example 7
Source File: PropertiesMeterFilter.java    From foremast with Apache License 2.0 4 votes vote down vote up
private Long convertMeterValue(Meter.Type meterType, String value) {
    return (value != null) ? MeterValue.valueOf(value).getValue(meterType) : null;
}
 
Example 8
Source File: PropertiesMeterFilter.java    From foremast with Apache License 2.0 4 votes vote down vote up
private Long convertMeterValue(Meter.Type meterType, String value) {
    return (value != null) ? MeterValue.valueOf(value).getValue(meterType) : null;
}
 
Example 9
Source File: DefaultMeter.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public DefaultMeter(Meter.Id id, Meter.Type type, Iterable<Measurement> measurements) {
    super(id);
    this.type = type;
    this.measurements = measurements;
}
 
Example 10
Source File: NoopMeterRegistry.java    From dolphin-platform with Apache License 2.0 4 votes vote down vote up
@Override
protected Meter newMeter(final Meter.Id id, final Meter.Type type, final Iterable<Measurement> measurements) {
    return new NoopCounter(id);
}
 
Example 11
Source File: ServiceLevelAgreementBoundary.java    From foremast with Apache License 2.0 2 votes vote down vote up
/**
 * Return the underlying value of the SLA in form suitable to apply to the given meter
 * type.
 * @param meterType the meter type
 * @return the value or {@code null} if the value cannot be applied
 */
public Long getValue(Meter.Type meterType) {
    return this.value.getValue(meterType);
}
 
Example 12
Source File: ServiceLevelAgreementBoundary.java    From foremast with Apache License 2.0 2 votes vote down vote up
/**
 * Return the underlying value of the SLA in form suitable to apply to the given meter
 * type.
 * @param meterType the meter type
 * @return the value or {@code null} if the value cannot be applied
 */
public Long getValue(Meter.Type meterType) {
    return this.value.getValue(meterType);
}