public PrometheusQmqCounter(final Gauge gauge, final String[] labels) { this.gauge = gauge.labels(labels); }
/** * @see GridRegistry#clearNewSessionRequests() */ public void clearNewSessionRequests() { newSessionQueue.clearNewSessionRequests(); seleniumTestSessionsWaiting.set(0); }
@SuppressWarnings("unchecked") @Override protected <T> io.micrometer.core.instrument.Gauge newGauge(Meter.Id id, T obj, ToDoubleFunction<T> f) { final WeakReference<T> ref = new WeakReference<>(obj); io.prometheus.client.Gauge gauge = collectorByName(Gauge.class, id.getConventionName(), i -> buildCollector(id, io.prometheus.client.Gauge.build())); String[] labelValues = id.getConventionTags().stream() .map(Tag::getValue) .collect(Collectors.toList()) .toArray(new String[]{}); Gauge.Child child = new Gauge.Child() { @Override public double get() { final T obj2 = ref.get(); return (obj2 == null) ? Double.NaN : f.applyAsDouble(obj2); } }; gauge.setChild(child, labelValues); return new PrometheusGauge(id, child); }
/** * Get the Gauge object for the given measurementName from the metricNameGuageMap. If the object does not exist: * create and register the metric and put it into the metricNameGuageMap. * * @param measurement * @param measurementName parameter is added (instead of being fetched from Measurement object) because name of the * complex measurement is calculated for each field * @return Gauge object for the given measurementName */ private Gauge getOrCreateGaugeMeasurement(final Measurement measurement, String measurementName) { Gauge gauge = metricNameGuageMap.get(measurementName); if (gauge == null) { String[] tagKeys = measurement.tags().keySet().toArray(new String[0]); gauge = Gauge.build().labelNames(tagKeys).name(measurementName).help(measurement.name()).register(); metricNameGuageMap.put(measurementName, gauge); } return gauge; }
@Setup public void setup() { prometheusGauge = io.prometheus.client.metrics.Gauge.newBuilder() .name("name") .documentation("some description..") .build(); prometheusGaugeChild = prometheusGauge.newPartial().apply(); prometheusSimpleGauge = io.prometheus.client.Gauge.build() .name("name") .help("some description..") .labelNames("some", "group").create(); prometheusSimpleGaugeChild = prometheusSimpleGauge.labels("test", "group"); prometheusSimpleGaugeNoLabels = io.prometheus.client.Gauge.build() .name("name") .help("some description..") .create(); registry = new MetricRegistry(); codahaleCounter = registry.counter("name"); }
@Override public void handle(AvaIre avaire) { Metrics.uptime.labels("dynamic").set(ManagementFactory.getRuntimeMXBean().getUptime()); Metrics.memoryTotal.set(Runtime.getRuntime().totalMemory()); Metrics.memoryUsed.set(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); if (!avaire.areWeReadyYet() || !hasLoadedGuilds(avaire)) { return; } Metrics.guilds.set(avaire.getShardEntityCounter().getGuilds()); Metrics.users.set(avaire.getShardEntityCounter().getUsers()); Metrics.channels.labels("text").set(avaire.getShardEntityCounter().getTextChannels()); Metrics.channels.labels("voice").set(avaire.getShardEntityCounter().getVoiceChannels()); for (Region region : Region.values()) { Metrics.geoTracker.labels(region.getName()).set(0); } for (JDA shard : avaire.getShardManager().getShards()) { for (Guild guild : shard.getGuilds()) { Metrics.geoTracker.labels(guild.getRegion().getName()).inc(); } } }
private void handleSendGuildLeaveWebhook(Guild guild) { AvaIre.getLogger().info(ConsoleColor.format( "%redLeft guild with an ID of " + guild.getId() + " called: " + guild.getName() + "%reset" )); if (!avaire.areWeReadyYet()) { return; } Metrics.guilds.dec(); Metrics.geoTracker.labels(guild.getRegion().getName()).dec(); TextChannel channel = avaire.getShardManager().getTextChannelById(DiscordConstants.ACTIVITY_LOG_CHANNEL_ID); if (channel == null) { return; } channel.sendMessage( new EmbedBuilder() .setColor(Color.decode("#EF5350")) .setTimestamp(Instant.now()) .addField("Removed", String.format("%s (ID: %s)", guild.getName(), guild.getId() ), false) .build() ).queue(null, RestActionUtil.ignore); }
/** * @see GridRegistry#removeNewSessionRequest(RequestHandler) */ public boolean removeNewSessionRequest(RequestHandler request) { boolean wasRemoved = newSessionQueue.removeNewSessionRequest(request); if (wasRemoved) { seleniumTestSessionsWaiting.dec(); } return wasRemoved; }
/** * @see GridRegistry#addNewSessionRequest(RequestHandler) */ public void addNewSessionRequest(RequestHandler handler) { try { lock.lock(); Map<String, Object> requestedCapabilities = handler.getRequest().getDesiredCapabilities(); proxies.verifyAbilityToHandleDesiredCapabilities(requestedCapabilities); requestedCapabilities.forEach((k, v) -> MDC.put(k,v.toString())); LOG.info("Adding sessionRequest for " + requestedCapabilities.toString()); newSessionQueue.add(handler); seleniumTestSessionsWaiting.inc(); fireMatcherStateChanged(); } finally { MDC.clear(); lock.unlock(); } }
private boolean isMaxCollections() { int limit = this.collectionLimit.get().limit(); if (limit < 1) { log.warn("Ignoring max-concurrent-collections as its lower than 1. Current: {} Default {}", SafeArg.of("current", limit), SafeArg.of("default", PrometheusCollectionLimit.DEFAULT_MAX_COLLECTIONS)); COLLECTION_REQUESTS_MAX.set(PrometheusCollectionLimit.DEFAULT_MAX_COLLECTIONS); } else { COLLECTION_REQUESTS_MAX.set(limit); } return currentRequests.incrementAndGet() > COLLECTION_REQUESTS_MAX.get(); } }
public PrometheusGauge register(CollectorRegistry registry) { gauge.register(registry); return this; } }
@SuppressWarnings("unchecked") @Override public <T> T gauge(String name, Iterable<Tag> tags, T obj, ToDoubleFunction<T> f) { final WeakReference<T> ref = new WeakReference<>(obj); MeterId id = new MeterId(name, tags); io.prometheus.client.Gauge gauge = collectorByName(Gauge.class, name, i -> buildCollector(id, io.prometheus.client.Gauge.build())); computeIfAbsent(meterMap, id, g -> { String[] labelValues = id.getTags().stream() .map(Tag::getValue) .collect(Collectors.toList()) .toArray(new String[]{}); Gauge.Child child = new Gauge.Child() { @Override public double get() { final T obj = ref.get(); return (obj == null) ? Double.NaN : f.applyAsDouble(obj); } }; gauge.setChild(child, labelValues); return new PrometheusGauge(id, child); }); return obj; }
public Size() { sizes = Gauge.build() .name("sizes") .help("Sizes of things") .labelNames("name", "type") .create(); }
private void setMetricsFromReport() { METRIC_SUM_DIRS.set(overallStats.sumDirectories.longValue()); METRIC_SUM_LINKS.set(overallStats.sumSymLinks.longValue()); METRIC_SUM_BLOCKS.set(overallStats.sumBlocks.longValue()); METRIC_USER_SUM_DIRS.labels(labelValues).set(userStat.sumDirectories.longValue()); METRIC_USER_SUM_LINKS.labels(labelValues).set(userStat.sumSymLinks.longValue()); METRIC_USER_SUM_BLOCKS.labels(labelValues).set(userStat.sumBlocks.longValue()); METRIC_GROUP_SUM_DIRS.labels(labelValues).set(groupStat.sumDirectories.longValue()); METRIC_GROUP_SUM_LINKS.labels(labelValues).set(groupStat.sumSymLinks.longValue()); METRIC_GROUP_SUM_BLOCKS.labels(labelValues).set(groupStat.sumBlocks.longValue()); METRIC_PATH_SUM_DIRS.labels(pathStat.path).set(pathStat.sumDirectories.longValue()); METRIC_PATH_SUM_LINKS.labels(pathStat.path).set(pathStat.sumSymLinks.longValue()); METRIC_PATH_SUM_BLOCKS.labels(pathStat.path).set(pathStat.sumBlocks.longValue()); METRIC_PATH_SET_SUM_DIRS.labels(pathStat.path).set(pathStat.sumDirectories.longValue()); METRIC_PATH_SET_SUM_LINKS.labels(pathStat.path).set(pathStat.sumSymLinks.longValue()); METRIC_PATH_SET_SUM_BLOCKS.labels(pathStat.path).set(pathStat.sumBlocks.longValue());
private boolean takeRequestHandler(RequestHandler handler) { final TestSession session = proxies.getNewSession(handler.getRequest().getDesiredCapabilities()); final boolean sessionCreated = session != null; if (sessionCreated) { String remoteName = session.getSlot().getProxy().getId(); long timeToAssignProxy = System.currentTimeMillis() - handler.getRequest().getCreationTime(); LOG.info("Test session with internal key {} assigned to remote ({}) after {} seconds ({} ms).", session.getInternalKey(), remoteName, timeToAssignProxy / 1000, timeToAssignProxy); seleniumTestSessionStartLatency.observe(timeToAssignProxy / Collector.MILLISECONDS_PER_SECOND); seleniumTestSessionsWaiting.dec(); activeTestSessions.add(session); handler.bindSession(session); } return sessionCreated; }
/** * Increment the gauge with no labels by 1. */ public void inc() { inc(1); } /**
log.error(TOO_MANY_REQUESTS_ERROR, SafeArg.of("current", currentRequests.get()), SafeArg.of("max", COLLECTION_REQUESTS_MAX.get()) ); throw TOO_MANY_REQUESTS; try { log.debug("Collecting metrics..."); COLLECTION_REQUESTS.set(currentRequests.get()); TextFormat.write004(writer, registry.metricFamilySamples()); } catch (IOException e) {