private static String getScopedName(String metricName, MetricGroup group) { return SCOPE_PREFIX + getLogicalScope(group) + SCOPE_SEPARATOR + CHARACTER_FILTER.filterCharacters(metricName); }
@Override public void notifyOfAddedMetric(final Metric metric, final String metricName, final MetricGroup group) { List<String> dimensionKeys = new LinkedList<>(); List<String> dimensionValues = new LinkedList<>(); for (final Map.Entry<String, String> dimension : group.getAllVariables().entrySet()) { final String key = dimension.getKey(); dimensionKeys.add(CHARACTER_FILTER.filterCharacters(key.substring(1, key.length() - 1))); dimensionValues.add(labelValueCharactersFilter.filterCharacters(dimension.getValue())); } final String scopedMetricName = getScopedName(metricName, group); final String helpString = metricName + " (scope: " + getLogicalScope(group) + ")"; final Collector collector; Integer count = 0; synchronized (this) { if (collectorsWithCountByMetricName.containsKey(scopedMetricName)) { final AbstractMap.SimpleImmutableEntry<Collector, Integer> collectorWithCount = collectorsWithCountByMetricName.get(scopedMetricName); collector = collectorWithCount.getKey(); count = collectorWithCount.getValue(); } else { collector = createCollector(metric, dimensionKeys, dimensionValues, scopedMetricName, helpString); try { collector.register(); } catch (Exception e) { log.warn("There was a problem registering metric {}.", metricName, e); } } addMetric(metric, dimensionValues, collector); collectorsWithCountByMetricName.put(scopedMetricName, new AbstractMap.SimpleImmutableEntry<>(collector, count + 1)); } }
@Override public void notifyOfRemovedMetric(final Metric metric, final String metricName, final MetricGroup group) { List<String> dimensionValues = new LinkedList<>(); for (final Map.Entry<String, String> dimension : group.getAllVariables().entrySet()) { dimensionValues.add(labelValueCharactersFilter.filterCharacters(dimension.getValue())); } final String scopedMetricName = getScopedName(metricName, group); synchronized (this) { final AbstractMap.SimpleImmutableEntry<Collector, Integer> collectorWithCount = collectorsWithCountByMetricName.get(scopedMetricName); final Integer count = collectorWithCount.getValue(); final Collector collector = collectorWithCount.getKey(); removeMetric(metric, dimensionValues, collector); if (count == 1) { try { CollectorRegistry.defaultRegistry.unregister(collector); } catch (Exception e) { log.warn("There was a problem unregistering metric {}.", scopedMetricName, e); } collectorsWithCountByMetricName.remove(scopedMetricName); } else { collectorsWithCountByMetricName.put(scopedMetricName, new AbstractMap.SimpleImmutableEntry<>(collector, count - 1)); } } }
@Override protected String getGroupName(CharacterFilter filter) { return filter.filterCharacters(name); } }
@Override protected String getGroupName(CharacterFilter filter) { return filter.filterCharacters(name); } }
@Override protected String getGroupName(CharacterFilter filter) { return filter.filterCharacters(name); } }
@Override protected String getGroupName(CharacterFilter filter) { return filter.filterCharacters(name); } }
private String name2MetricName(String name){ String metricName = name; if (name != null && name.length() > METRICS_OPERATOR_NAME_MAX_LENGTH) { metricName = name.substring(0, METRICS_OPERATOR_NAME_MAX_LENGTH); } metricName = MetricQueryService.FILTER.filterCharacters(metricName); return metricName; }
/** * Concatenates the given component names separated by the delimiter character. Additionally * the character filter is applied to all component names. * * @param filter Character filter to be applied to the component names * @param delimiter Delimiter to separate component names * @param components Array of component names * @return The concatenated component name */ public static String concat(CharacterFilter filter, Character delimiter, String... components) { StringBuilder sb = new StringBuilder(); sb.append(filter.filterCharacters(components[0])); for (int x = 1; x < components.length; x++) { sb.append(delimiter); sb.append(filter.filterCharacters(components[x])); } return sb.toString(); }
/** * Concatenates the given component names separated by the delimiter character. Additionally * the character filter is applied to all component names. * * @param filter Character filter to be applied to the component names * @param delimiter Delimiter to separate component names * @param components Array of component names * @return The concatenated component name */ public static String concat(CharacterFilter filter, Character delimiter, String... components) { StringBuilder sb = new StringBuilder(); sb.append(filter.filterCharacters(components[0])); for (int x = 1; x < components.length; x++) { sb.append(delimiter); sb.append(filter.filterCharacters(components[x])); } return sb.toString(); }
/** * Concatenates the given component names separated by the delimiter character. Additionally * the character filter is applied to all component names. * * @param filter Character filter to be applied to the component names * @param delimiter Delimiter to separate component names * @param components Array of component names * @return The concatenated component name */ public static String concat(CharacterFilter filter, Character delimiter, String... components) { StringBuilder sb = new StringBuilder(); sb.append(filter.filterCharacters(components[0])); for (int x = 1; x < components.length; x++) { sb.append(delimiter); sb.append(filter.filterCharacters(components[x])); } return sb.toString(); }
/** * Concatenates the given component names separated by the delimiter character. Additionally * the character filter is applied to all component names. * * @param filter Character filter to be applied to the component names * @param delimiter Delimiter to separate component names * @param components Array of component names * @return The concatenated component name */ public static String concat(CharacterFilter filter, Character delimiter, String... components) { StringBuilder sb = new StringBuilder(); sb.append(filter.filterCharacters(components[0])); for (int x = 1; x < components.length; x++) { sb.append(delimiter); sb.append(filter.filterCharacters(components[x])); } return sb.toString(); }
@Override protected QueryScopeInfo createQueryServiceMetricInfo(CharacterFilter filter) { return parent.getQueryServiceMetricInfo(filter).copy(filter.filterCharacters(this.name)); }
@Override protected QueryScopeInfo createQueryServiceMetricInfo(CharacterFilter filter) { return parent.getQueryServiceMetricInfo(filter).copy(filter.filterCharacters(this.name)); }
@Override protected QueryScopeInfo createQueryServiceMetricInfo(CharacterFilter filter) { return parent.getQueryServiceMetricInfo(filter).copy(filter.filterCharacters(this.name)); }
@Override protected QueryScopeInfo createQueryServiceMetricInfo(CharacterFilter filter) { return parent.getQueryServiceMetricInfo(filter).copy(filter.filterCharacters(this.name)); }
@Override protected QueryScopeInfo.OperatorQueryScopeInfo createQueryServiceMetricInfo(CharacterFilter filter) { return new QueryScopeInfo.OperatorQueryScopeInfo( this.parent.parent.jobId.toString(), this.parent.vertexId.toString(), this.parent.subtaskIndex, filter.filterCharacters(this.operatorName)); }
@Override protected QueryScopeInfo.OperatorQueryScopeInfo createQueryServiceMetricInfo(CharacterFilter filter) { return new QueryScopeInfo.OperatorQueryScopeInfo( this.parent.parent.jobId.toString(), this.parent.vertexId.toString(), this.parent.subtaskIndex, filter.filterCharacters(this.operatorName)); }
@Override protected QueryScopeInfo.OperatorQueryScopeInfo createQueryServiceMetricInfo(CharacterFilter filter) { return new QueryScopeInfo.OperatorQueryScopeInfo( this.parent.parent.jobId.toString(), this.parent.vertexId.toString(), this.parent.subtaskIndex, filter.filterCharacters(this.operatorName)); }
counters.put((Counter) metric, new Tuple2<>(info, FILTER.filterCharacters(metricName))); } else if (metric instanceof Gauge) { gauges.put((Gauge<?>) metric, new Tuple2<>(info, FILTER.filterCharacters(metricName))); } else if (metric instanceof Histogram) { histograms.put((Histogram) metric, new Tuple2<>(info, FILTER.filterCharacters(metricName))); } else if (metric instanceof Meter) { meters.put((Meter) metric, new Tuple2<>(info, FILTER.filterCharacters(metricName)));