io.micrometer.core.lang.Nullable Java Examples
The following examples show how to use
io.micrometer.core.lang.Nullable.
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: SampleRegistries.java From micrometer with Apache License 2.0 | 6 votes |
public static InfluxMeterRegistry influx() { return new InfluxMeterRegistry(new InfluxConfig() { @Override public String userName() { return "admin"; } @Override public String password() { return "admin"; } @Override public Duration step() { return Duration.ofSeconds(10); } @Override @Nullable public String get(String k) { return null; } }, Clock.SYSTEM); }
Example #2
Source File: AtlasUtils.java From micrometer with Apache License 2.0 | 6 votes |
@Nullable static com.netflix.spectator.api.Statistic toSpectatorStatistic(Statistic stat) { switch (stat) { case COUNT: return count; case TOTAL_TIME: return totalTime; case TOTAL: return totalAmount; case VALUE: return gauge; case ACTIVE_TASKS: return activeTasks; case DURATION: return duration; case MAX: return max; } return null; }
Example #3
Source File: WebMvcTags.java From foremast with Apache License 2.0 | 6 votes |
/** * Creates a {@code uri} tag based on the URI of the given {@code request}. Uses the * {@link HandlerMapping#BEST_MATCHING_PATTERN_ATTRIBUTE} best matching pattern if * available. Falling back to {@code REDIRECTION} for 3xx responses, {@code NOT_FOUND} * for 404 responses, {@code root} for requests with no path info, and {@code UNKNOWN} * for all other requests. * * @param request the request * @param response the response * @return the uri tag derived from the request */ public static Tag uri(@Nullable HttpServletRequest request, @Nullable HttpServletResponse response) { if (request != null) { String pattern = getMatchingPattern(request); if (pattern != null) { return Tag.of("uri", pattern); } else if (response != null) { HttpStatus status = extractStatus(response); if (status != null && status.is3xxRedirection()) { return URI_REDIRECTION; } if (status != null && status.equals(HttpStatus.NOT_FOUND)) { return URI_NOT_FOUND; } } String pathInfo = getPathInfo(request); if (pathInfo.isEmpty()) { return URI_ROOT; } } return URI_UNKNOWN; }
Example #4
Source File: SampleRegistries.java From micrometer with Apache License 2.0 | 6 votes |
public static StatsdMeterRegistry datadogStatsd() { return new StatsdMeterRegistry(new StatsdConfig() { @Override public Duration step() { return Duration.ofSeconds(10); } @Override @Nullable public String get(String k) { return null; } @Override public StatsdFlavor flavor() { return StatsdFlavor.DATADOG; } }, Clock.SYSTEM); }
Example #5
Source File: InfluxMeterRegistryCompatibilityTest.java From micrometer with Apache License 2.0 | 5 votes |
@Override public MeterRegistry registry() { return new InfluxMeterRegistry(new InfluxConfig() { @Override public boolean enabled() { return false; } @Override @Nullable public String get(String key) { return null; } }, new MockClock()); }
Example #6
Source File: HistogramSnapshot.java From micrometer with Apache License 2.0 | 5 votes |
/** * @param count Total number of recordings * @param total In nanos if a unit of time * @param max In nanos if a unit of time * @param percentileValues Pre-computed percentiles. * @param histogramCounts Bucket counts. * @param summaryOutput A function defining how to print the histogram. */ public HistogramSnapshot(long count, double total, double max, @Nullable ValueAtPercentile[] percentileValues, @Nullable CountAtBucket[] histogramCounts, @Nullable BiConsumer<PrintStream, Double> summaryOutput) { this.count = count; this.total = total; this.max = max; this.percentileValues = percentileValues != null ? percentileValues : EMPTY_VALUES; this.histogramCounts = histogramCounts != null ? histogramCounts : EMPTY_COUNTS; this.summaryOutput = summaryOutput; }
Example #7
Source File: SampleRegistries.java From micrometer with Apache License 2.0 | 5 votes |
public static AtlasMeterRegistry atlas() { return new AtlasMeterRegistry(new AtlasConfig() { @Override public Duration step() { return Duration.ofSeconds(10); } @SuppressWarnings("ConstantConditions") @Override @Nullable public String get(String k) { return null; } }, Clock.SYSTEM); }
Example #8
Source File: Meter.java From micrometer with Apache License 2.0 | 5 votes |
/** * @param key The tag key to attempt to match. * @return A matching tag value, or {@code null} if no tag with the provided key exists on this id. */ @Nullable public String getTag(String key) { for (Tag tag : tags) { if (tag.getKey().equals(key)) return tag.getValue(); } return null; }
Example #9
Source File: ProcessorMetrics.java From micrometer with Apache License 2.0 | 5 votes |
@Nullable private Method detectMethod(String name) { requireNonNull(name); if (operatingSystemBeanClass == null) { return null; } try { // ensure the Bean we have is actually an instance of the interface operatingSystemBeanClass.cast(operatingSystemBean); return operatingSystemBeanClass.getDeclaredMethod(name); } catch (ClassCastException | NoSuchMethodException | SecurityException e) { return null; } }
Example #10
Source File: ImmutableTag.java From micrometer with Apache License 2.0 | 5 votes |
@Override public boolean equals(@Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Tag that = (Tag) o; return Objects.equals(key, that.getKey()) && Objects.equals(value, that.getValue()); }
Example #11
Source File: PrometheusMeterRegistry.java From micrometer with Apache License 2.0 | 5 votes |
@Override protected <T> io.micrometer.core.instrument.Gauge newGauge(Meter.Id id, @Nullable T obj, ToDoubleFunction<T> valueFunction) { Gauge gauge = new DefaultGauge<>(id, obj, valueFunction); applyToCollector(id, (collector) -> { List<String> tagValues = tagValues(id); collector.add(tagValues, (conventionName, tagKeys) -> Stream.of(new MicrometerCollector.Family(Collector.Type.GAUGE, conventionName, new Collector.MetricFamilySamples.Sample(conventionName, tagKeys, tagValues, gauge.value())))); }); return gauge; }
Example #12
Source File: StatsdGauge.java From micrometer with Apache License 2.0 | 5 votes |
StatsdGauge(Id id, StatsdLineBuilder lineBuilder, FluxSink<String> sink, @Nullable T obj, ToDoubleFunction<T> value, boolean alwaysPublish) { super(id); this.lineBuilder = lineBuilder; this.sink = sink; this.ref = new WeakReference<>(obj); this.value = value; this.alwaysPublish = alwaysPublish; }
Example #13
Source File: DefaultWebMvcTagsProvider.java From foremast with Apache License 2.0 | 5 votes |
/** * Supplies default tags to the Web MVC server programming model. * * @param request The HTTP request. * @param response The HTTP response. * @param ex The current exception, if any * @return A set of tags added to every Spring MVC HTTP request. */ @Override public Iterable<Tag> httpRequestTags(@Nullable HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable Object handler, @Nullable Throwable ex) { return Arrays.asList(WebMvcTags.method(request), WebMvcTags.uri(request, response), WebMvcTags.exception(ex), WebMvcTags.status(response)); }
Example #14
Source File: FileDescriptorMetrics.java From micrometer with Apache License 2.0 | 5 votes |
@Nullable private Method detectMethod(String name) { if (osBeanClass == null) { return null; } try { // ensure the Bean we have is actually an instance of the interface osBeanClass.cast(osBean); return osBeanClass.getDeclaredMethod(name); } catch (ClassCastException | NoSuchMethodException | SecurityException e) { return null; } }
Example #15
Source File: MeterRegistry.java From micrometer with Apache License 2.0 | 5 votes |
/** * @param mappedId The id of the meter to remove * @return The removed meter, or null if no meter matched the provided id. * @since 1.1.0 */ @Incubating(since = "1.1.0") @Nullable public Meter remove(Meter.Id mappedId) { Meter m = meterMap.get(mappedId); if (m != null) { synchronized (meterMapLock) { m = meterMap.remove(mappedId); if (m != null) { Set<Id> synthetics = syntheticAssociations.remove(mappedId); if (synthetics != null) { for (Id synthetic : synthetics) { remove(synthetic); } } for (Consumer<Meter> onRemove : meterRemovedListeners) { onRemove.accept(m); } return m; } } } return null; }
Example #16
Source File: GangliaMeterRegistryCompatibilityTest.java From micrometer with Apache License 2.0 | 5 votes |
@Override public MeterRegistry registry() { return GangliaMeterRegistry.builder(new GangliaConfig() { @Override public boolean enabled() { return false; } @Override @Nullable public String get(String key) { return null; } }).clock(new MockClock()).build(); }
Example #17
Source File: StatsdMeterRegistryTest.java From micrometer with Apache License 2.0 | 5 votes |
private static StatsdConfig configWithFlavor(StatsdFlavor flavor) { return new StatsdConfig() { @Override @Nullable public String get(String key) { return null; } @Override public StatsdFlavor flavor() { return flavor; } }; }
Example #18
Source File: WebMvcTags.java From foremast with Apache License 2.0 | 5 votes |
@Nullable private static HttpStatus extractStatus(HttpServletResponse response) { try { if (response instanceof MetricsServletResponse) { return HttpStatus.valueOf(((MetricsServletResponse)response).getStatus()); } else { return HttpStatus.OK; } } catch (IllegalArgumentException ex) { return null; } }
Example #19
Source File: MeterRegistry.java From micrometer with Apache License 2.0 | 5 votes |
private <M extends Meter> M registerMeterIfNecessary(Class<M> meterClass, Meter.Id id, @Nullable DistributionStatisticConfig config, BiFunction<Meter.Id, DistributionStatisticConfig, M> builder, Function<Meter.Id, M> noopBuilder) { Id mappedId = getMappedId(id); Meter m = getOrCreateMeter(config, builder, id, mappedId, noopBuilder); if (!meterClass.isInstance(m)) { throw new IllegalArgumentException("There is already a registered meter of a different type with the same name"); } return meterClass.cast(m); }
Example #20
Source File: KairosMeterRegistryCompatibilityTest.java From micrometer with Apache License 2.0 | 5 votes |
@Override public MeterRegistry registry() { return new KairosMeterRegistry(new KairosConfig() { @Override public boolean enabled() { return false; } @Override @Nullable public String get(String key) { return null; } }, new MockClock()); }
Example #21
Source File: DefaultWebMvcTagsProvider.java From foremast with Apache License 2.0 | 5 votes |
/** * Supplies default tags to the Web MVC server programming model. * * @param request The HTTP request. * @param response The HTTP response. * @param ex The current exception, if any * @return A set of tags added to every Spring MVC HTTP request. */ @Override public Iterable<Tag> httpRequestTags(@Nullable HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable Object handler, @Nullable Throwable ex) { return Arrays.asList(WebMvcTags.method(request), WebMvcTags.uri(request, response), WebMvcTags.exception(ex), WebMvcTags.status(response)); }
Example #22
Source File: StringEscapeUtils.java From micrometer with Apache License 2.0 | 5 votes |
public static String escapeJson(@Nullable String v) { if (v == null) return ""; int length = v.length(); if (length == 0) return v; int afterReplacement = 0; StringBuilder builder = null; for (int i = 0; i < length; i++) { char c = v.charAt(i); String replacement; if (c < 0x80) { replacement = REPLACEMENT_CHARS[c]; if (replacement == null) continue; } else if (c == '\u2028') { replacement = U2028; } else if (c == '\u2029') { replacement = U2029; } else { continue; } if (afterReplacement < i) { // write characters between the last replacement and now if (builder == null) builder = new StringBuilder(length); builder.append(v, afterReplacement, i); } if (builder == null) builder = new StringBuilder(length); builder.append(replacement); afterReplacement = i + 1; } if (builder == null) return v; // then we didn't escape anything if (afterReplacement < length) { builder.append(v, afterReplacement, length); } return builder.toString(); }
Example #23
Source File: HibernateMetrics.java From micrometer with Apache License 2.0 | 5 votes |
/** * Unwrap the {@link SessionFactory} from {@link EntityManagerFactory}. * * @param entityManagerFactory {@link EntityManagerFactory} to unwrap * @return unwrapped {@link SessionFactory} */ @Nullable private SessionFactory unwrap(EntityManagerFactory entityManagerFactory) { try { return entityManagerFactory.unwrap(SessionFactory.class); } catch (PersistenceException ex) { return null; } }
Example #24
Source File: StringUtils.java From micrometer with Apache License 2.0 | 5 votes |
/** * Check if the String is null or has only whitespaces. * * Modified from {@link org.apache.commons.lang.StringUtils#isBlank(String)}. * * @param string String to check * @return {@code true} if the String is null or has only whitespaces */ public static boolean isBlank(@Nullable String string) { if (isEmpty(string)) { return true; } for (int i = 0; i < string.length(); i++) { if (!Character.isWhitespace(string.charAt(i))) { return false; } } return true; }
Example #25
Source File: MeterNotFoundException.java From micrometer with Apache License 2.0 | 5 votes |
@Nullable private String nameDetail() { if (search.nameMatches == null) return null; Collection<String> matchingName = Search.in(search.registry) .name(search.nameMatches) .meters() .stream() .map(m -> m.getId().getName()) .distinct() .sorted() .collect(toList()); if (!matchingName.isEmpty()) { if (matchingName.size() == 1) { return OK + " A meter with name '" + matchingName.iterator().next() + "' was found."; } else { return OK + " Meters with names [" + matchingName.stream().map(name -> "'" + name + "'").collect(joining(", ")) + "] were found."; } } if (search.exactNameMatch != null) { return NOT_OK + " No meter with name '" + search.exactNameMatch + "' was found."; } return NOT_OK + " No meter that matches the name predicate was found."; }
Example #26
Source File: OkHttpMetricsEventListener.java From micrometer with Apache License 2.0 | 5 votes |
private Tags generateTagsForRoute(@Nullable Request request) { if (request == null) { return TAGS_TARGET_UNKNOWN; } return Tags.of( TAG_TARGET_SCHEME, request.url().scheme(), TAG_TARGET_HOST, request.url().host(), TAG_TARGET_PORT, Integer.toString(request.url().port()) ); }
Example #27
Source File: EhCache2MetricsCompatibilityTest.java From micrometer with Apache License 2.0 | 4 votes |
@Nullable @Override public String get(String key) { Element element = cache.get(key); return element == null ? null : (String) element.getObjectValue(); }
Example #28
Source File: GangliaConfig.java From micrometer with Apache License 2.0 | 4 votes |
/** * Protocol version. * @return protocol version * @deprecated since 1.5.0 */ @Deprecated @Nullable default String protocolVersion() { return null; }
Example #29
Source File: AppOpticsConfig.java From micrometer with Apache License 2.0 | 4 votes |
/** * @return The tag that will be mapped to {@literal @host} when shipping metrics to AppOptics. */ @Nullable default String hostTag() { return getString(this, "hostTag").orElse("instance"); }
Example #30
Source File: MeterNotFoundException.java From micrometer with Apache License 2.0 | 4 votes |
private MeterNotFoundException(@Nullable String nameDetail, @Nullable String typeDetail, @Nullable List<String> tagDetail) { super("Unable to find a meter that matches all the requirements at once. Here's what was found:" + (nameDetail == null ? "" : "\n " + nameDetail) + (typeDetail == null ? "" : "\n " + typeDetail) + (tagDetail == null ? "" : "\n " + tagDetail.stream().collect(joining("\n ")))); }