-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Virtual threads metrics #5067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Virtual threads metrics #5067
Changes from 1 commit
0e699be
41ce1be
046bf08
6f4efdb
d44f305
fa842aa
609f103
f1de36d
1cd17b4
da232cc
9ddc77e
13291d3
d142cfe
1dc9470
784225c
b787eb2
063d3f2
2fe817d
ffb902a
11f1016
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright 2024 VMware, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.micrometer.core.instrument.binder.jvm; | ||
|
|
||
| import io.micrometer.core.instrument.Counter; | ||
| import io.micrometer.core.instrument.MeterRegistry; | ||
| import io.micrometer.core.instrument.Tag; | ||
| import io.micrometer.core.instrument.Timer; | ||
| import io.micrometer.core.instrument.binder.MeterBinder; | ||
| import jdk.jfr.consumer.RecordingStream; | ||
|
|
||
| import static java.util.Collections.emptyList; | ||
|
|
||
| public class JvmVirtualThreadEventMetrics implements MeterBinder, AutoCloseable { | ||
|
|
||
| private final Iterable<Tag> tags; | ||
|
|
||
| private final RecordingStream recordingStream; | ||
|
|
||
| public JvmVirtualThreadEventMetrics() { | ||
| this(emptyList()); | ||
| } | ||
|
|
||
| public JvmVirtualThreadEventMetrics(Iterable<Tag> tags) { | ||
| this.tags = tags; | ||
| this.recordingStream = new RecordingStream(); | ||
|
|
||
| recordingStream.enable("jdk.VirtualThreadPinnedEvent"); | ||
| recordingStream.enable("jdk.VirtualThreadSubmitFailedEvent"); | ||
|
||
| } | ||
|
|
||
| @Override | ||
| public void bindTo(MeterRegistry registry) { | ||
| final Timer pinnedTimer = | ||
| Timer.builder("jvm.virtual.thread.pinned") | ||
| .tags(tags) | ||
| .description("The duration of virtual threads that were pinned to a physical thread") | ||
| .register(registry); | ||
|
|
||
| final Counter submitFailedCounter = | ||
| Counter.builder("jvm.virtual.thread.submit.failed") | ||
| .tags(tags) | ||
| .description("The number of virtual thread submissions that failed") | ||
| .register(registry); | ||
|
|
||
| recordingStream.onEvent("jdk.VirtualThreadPinnedEvent", event -> | ||
| pinnedTimer.record(event.getDuration())); | ||
|
|
||
| recordingStream.onEvent("jdk.VirtualThreadSubmitFailedEvent", | ||
| event -> submitFailedCounter.increment()); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws Exception { | ||
| recordingStream.close(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.