@Override protected MetricValue scalar_fallback_() { return MetricValue.fromIntValue(0); }
@Override protected MetricValue scalar_fallback_() { return MetricValue.fromIntValue(0); }
/** * Convert a duration to a metric value. * * The returned metric value is expressed as the duration in milliseconds. * * @param duration The duration to express. * @return A metric value representing the duration. */ private static MetricValue duration_to_metricvalue_(Duration duration) { return MetricValue.fromIntValue(duration.getMillis()); }
/** * Construct a metric value from a Number implementation. * @param number A floating point or integral type. * @return a MetricValue holding the specified number. * @throws IllegalArgumentException if the derived type of Number is not recognized. */ public static MetricValue fromNumberValue(Number number) { if (number == null) { return EMPTY; } else if (number instanceof Float || number instanceof Double) { return fromDblValue(number.doubleValue()); } else if (number instanceof Byte || number instanceof Short || number instanceof Integer || number instanceof Long) { return fromIntValue(number.longValue()); } else { throw new IllegalArgumentException("Unrecognized number type: " + number.getClass()); } }
/** * Construct a metric value from a Number implementation. * @param number A floating point or integral type. * @return a MetricValue holding the specified number. * @throws IllegalArgumentException if the derived type of Number is not recognized. */ public static MetricValue fromNumberValue(Number number) { if (number == null) { return EMPTY; } else if (number instanceof Float || number instanceof Double) { return fromDblValue(number.doubleValue()); } else if (number instanceof Byte || number instanceof Short || number instanceof Integer || number instanceof Long) { return fromIntValue(number.longValue()); } else { throw new IllegalArgumentException("Unrecognized number type: " + number.getClass()); } }
private static MetricValue strAsMetricValue(String str) { // Try to coerce elem to a boolean. if ("true".equals(str)) return MetricValue.TRUE; if ("false".equals(str)) return MetricValue.FALSE; // Try to coerce elem to an integral number. try { return MetricValue.fromIntValue(Long.parseLong(str)); } catch (NumberFormatException e) { // Ignore. } // Try to coerce elem to a floating point number. try { return MetricValue.fromDblValue(Double.parseDouble(str)); } catch (NumberFormatException e) { // Ignore. } // Give up and just yield a string. return MetricValue.fromStrValue(str); }
result.put(FAILED_COLLECTIONS_METRIC, MetricValue.fromIntValue(failed_collections)); result.put(GROUP_COUNT_METRIC, MetricValue.fromIntValue(ctx.getTSData().getCurrentCollection().getGroups(x -> true).size())); result.put(METRIC_COUNT_METRIC, MetricValue.fromIntValue(metric_count)); result.put(CONFIG_PRESENT_METRIC, MetricValue.fromBoolean(has_config)); result.put(SCRAPE_DURATION, opt_duration_to_metricvalue_(scrape_duration)); result.put(PROCESSOR_DURATION, opt_duration_to_metricvalue_(processor_duration)); result.put(UPTIME_DURATION, duration_to_metricvalue_(uptime)); result.put(SCRAPE_COUNT, MetricValue.fromIntValue(++scrape_count_)); result.put(SCRAPE_INTERVAL, opt_duration_to_metricvalue_(last_scrape.map(prev -> new Duration(prev, now)))); result.put(SCRAPE_TS, MetricValue.fromIntValue(now.getMillis())); return result;
((Metric_constantContext)_localctx).s = MetricValue.fromIntValue(((Metric_constantContext)_localctx).s1_int.s);