本文整理了Java中io.prometheus.client.Gauge
类的一些代码示例,展示了Gauge
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Gauge
类的具体详情如下:
包路径:io.prometheus.client.Gauge
类名称:Gauge
[英]Gauge metric, to report instantaneous values.
Examples of Gauges include:
An example Gauge:
class YourClass }
}
You can also use labels to track different types of metric:
class YourClass void processPostRequest()
inprogressRequests.labels("post").inc();
// Your code here.
inprogressRequests.labels("post").dec();
}
}
}
These can be aggregated and processed together much more easily in the Prometheus server than individual metrics for each labelset.
[中]仪表公制,用于报告瞬时值。
仪表示例包括:
*正在进行的请求
*队列中的项目数
*空闲内存
*总内存
*温度
仪表可以上下移动。
一个示例量表:
class YourClass }
}
您还可以使用标签跟踪不同类型的度量:
class YourClass void processPostRequest()
inprogressRequests.labels("post").inc();
// Your code here.
inprogressRequests.labels("post").dec();
}
}
}
在Prometheus服务器中,与每个标签集的单个指标相比,这些指标更容易聚合和处理。
代码示例来源:origin: qunarcorp/qmq
@Override
public Gauge create() {
return Gauge.build().name(name).help(name).labelNames(tags).create().register();
}
}
代码示例来源:origin: qunarcorp/qmq
public PrometheusQmqCounter(final Gauge gauge, final String[] labels) {
this.gauge = gauge.labels(labels);
}
代码示例来源:origin: zalando/zalenium
/**
* @see GridRegistry#clearNewSessionRequests()
*/
public void clearNewSessionRequests() {
newSessionQueue.clearNewSessionRequests();
seleniumTestSessionsWaiting.set(0);
}
代码示例来源:origin: io.micrometer/micrometer-prometheus-starter
@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);
}
代码示例来源:origin: smartcat-labs/cassandra-diagnostics
/**
* 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;
}
代码示例来源:origin: prometheus/client_java
@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");
}
代码示例来源:origin: avaire/avaire
@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();
}
}
}
代码示例来源:origin: avaire/avaire
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);
}
代码示例来源:origin: avaire/avaire
Metrics.guilds.inc();
Metrics.geoTracker.labels(event.getGuild().getRegion().getName()).inc();
代码示例来源:origin: zalando/zalenium
/**
* @see GridRegistry#removeNewSessionRequest(RequestHandler)
*/
public boolean removeNewSessionRequest(RequestHandler request) {
boolean wasRemoved = newSessionQueue.removeNewSessionRequest(request);
if (wasRemoved) {
seleniumTestSessionsWaiting.dec();
}
return wasRemoved;
}
代码示例来源:origin: zalando/zalenium
/**
* @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();
}
}
代码示例来源:origin: com.palantir.srx.prometheus/prometheus-metrics
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();
}
}
代码示例来源:origin: org.apache.pulsar/pulsar-proxy
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
super.channelRegistered(ctx);
activeConnections.inc();
if (activeConnections.get() > service.getConfiguration().getMaxConcurrentInboundConnections()) {
ctx.close();
rejectedConnections.inc();
return;
}
}
代码示例来源:origin: com.jonnymatts.prometheus/metrics-core
public PrometheusGauge register(CollectorRegistry registry) {
gauge.register(registry);
return this;
}
}
代码示例来源:origin: org.springframework.metrics/spring-metrics
@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;
}
代码示例来源:origin: no.skatteetaten.aurora/aurora-prometheus
public Size() {
sizes = Gauge.build()
.name("sizes")
.help("Sizes of things")
.labelNames("name", "type")
.create();
}
代码示例来源:origin: marcelmay/hadoop-hdfs-fsimage-exporter
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());
代码示例来源:origin: zalando/zalenium
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;
}
代码示例来源:origin: prometheus/client_java
/**
* Increment the gauge with no labels by 1.
*/
public void inc() {
inc(1);
}
/**
代码示例来源:origin: com.palantir.srx.prometheus/prometheus-metrics
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) {
内容来源于网络,如有侵权,请联系作者删除!