Java Code Examples for org.eclipse.microprofile.metrics.MetricUnits#HOURS

The following examples show how to use org.eclipse.microprofile.metrics.MetricUnits#HOURS . 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: ExporterUtil.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
public static Double convertNanosTo(Double value, String unit) {

        Double out;

        switch (unit) {
            case MetricUnits.NANOSECONDS:
                out = value;
                break;
            case MetricUnits.MICROSECONDS:
                out = value / NANOS_PER_MICROSECOND;
                break;
            case MetricUnits.MILLISECONDS:
                out = value / NANOS_PER_MILLI;
                break;
            case MetricUnits.SECONDS:
                out = value / NANOS_PER_SECOND;
                break;
            case MetricUnits.MINUTES:
                out = value / NANOS_PER_MINUTE;
                break;
            case MetricUnits.HOURS:
                out = value / NANOS_PER_HOUR;
                break;
            case MetricUnits.DAYS:
                out = value / NANOS_PER_DAY;
                break;
            default:
                out = value;
        }
        return out;
    }
 
Example 2
Source File: OpenMetricsUnitScalingTest.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindBaseUnit1() {
    String foo = MetricUnits.HOURS;
    String out = OpenMetricsUnit.getBaseUnitAsOpenMetricsString(Optional.ofNullable(foo));
    assertEquals(MetricUnits.SECONDS, out);
    String promUnit = OpenMetricsUnit.getBaseUnitAsOpenMetricsString(Optional.ofNullable(out));
    assertEquals("seconds", promUnit);
}
 
Example 3
Source File: OpenMetricsUnit.java    From smallrye-metrics with Apache License 2.0 4 votes vote down vote up
/**
 * Determines the basic unit to be used by OpenMetrics exporter based on the input unit from parameter.
 * That is:
 * - for memory size units, returns "bytes"
 * - for time units, returns "seconds"
 * - for any other unit, returns the input unit itself
 */
public static String getBaseUnitAsOpenMetricsString(Optional<String> optUnit) {

    if (!optUnit.isPresent()) {
        return MetricUnits.NONE;
    }

    String unit = optUnit.get();

    String out;
    switch (unit) {

        /* Represents bits. Not defined by SI, but by IEC 60027 */
        case MetricUnits.BITS:
            /* 1000 {@link #BITS} */
        case MetricUnits.KILOBITS:
            /* 1000 {@link #KIBIBITS} */
        case MetricUnits.MEGABITS:
            /* 1000 {@link #MEGABITS} */
        case MetricUnits.GIGABITS:
            /* 1024 {@link #BITS} */
        case MetricUnits.KIBIBITS:
            /* 1024 {@link #KIBIBITS} */
        case MetricUnits.MEBIBITS:
            /* 1024 {@link #MEBIBITS} */
        case MetricUnits.GIBIBITS:
            /* 8 {@link #BITS} */
        case MetricUnits.BYTES:
            /* 1000 {@link #BYTES} */
        case MetricUnits.KILOBYTES:
            /* 1000 {@link #KILOBYTES} */
        case MetricUnits.MEGABYTES:
            /* 1000 {@link #MEGABYTES} */
        case MetricUnits.GIGABYTES:
            out = "bytes";
            break;

        /* 1/1000 {@link #MICROSECONDS} */
        case MetricUnits.NANOSECONDS:
            /* 1/1000 {@link #MILLISECONDS} */
        case MetricUnits.MICROSECONDS:
            /* 1/1000 {@link #SECONDS} */
        case MetricUnits.MILLISECONDS:
            /* Represents seconds */
        case MetricUnits.SECONDS:
            /* 60 {@link #SECONDS} */
        case MetricUnits.MINUTES:
            /* 60 {@link #MINUTES} */
        case MetricUnits.HOURS:
            /* 24 {@link #HOURS} */
        case MetricUnits.DAYS:
            out = "seconds";
            break;
        default:
            out = unit;
    }
    return out;
}