-
Notifications
You must be signed in to change notification settings - Fork 81
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
Implementing a process collector #29
Comments
Hi Gerry, As you noted above
That sounds good. I am open to whether that crate would live in this repository or not. The former would likely make development easier as one can make atomic changes across both crates at once (with one pull request). Off the top of my head the interface of such crate could look like: fn register_process_metrics(registry: &mut Registry) The crate would register multiple custom metrics, e.g. a gauge metric exposing the number of threads. Those custom metrics would each implement @gagbo does the above make sense? Would you be interested in contributing such a crate? |
If I can find some time it’d be nice yeah, hopefully I’ll be able to find time to dig into this. I think I’d like a way to specify running the |
Great. Let me know in case you need any help!
Can you expand on what you want to optimize? All metric implementations are synchronized (e.g.
I am guessing that you are referring to interior mutability and not the |
Hello, Sorry for the late answer, I've been struggling to find time these days :( For the time being I don't see myself working too much on this as our monitoring coverage is decent now and we have other priorities but I'll keep this in mind when it becomes an important subject again!
I thought that all
I was really thinking about the marker trait here (so that registries can be borrowed by an |
Hi, all I've tried to take a stab at implementing this, since we need this as well. I looked at the current implementation for the other prometheus crate. As part of the implementation it reads data from procfs to figure out stats on the process. In the current implementation, it is implemented as a custom collector, so the data is read once, and then used for all metrics. But with the design of the current crate, I found it hard to emulate this, since each metrics is its own separate thing, and the logic is spread out across each encode metric impl (If I understood it correctly). I think it would help if it was also possible to have something analogous to the Collect trait for a group of metrics that share a source, so to speak. I also found issue #49 which I think is showing other usecases where it would be helpful. Just my 2c. |
@dovreshef would you be retrieving the information from the system in time or on an interval. I think the former is the Prometheus way. Would the custom metric example not be the interface you need? I.e. be called on scrape to retrieve and generate the metrics? https://github.com/prometheus/client_rust/blob/master/examples/custom-metric.rs |
Sorry, I'm not sure I understand the question. I'll be retrieving the info in the There are multiple metrics that the process collector gathers, and the process to gather each one is similar. We read the /proc file system for the calling process, and extract the data from several files there. In the existing Prometheus client implementation all the metrics are gathered in a single collect call, and so they share those initial steps. So I think it would help if we would have a way to collect/encode multiple metrics in a single call. |
Ah, sorry, I forgot having this discussion in the past. As suggested on #49 (comment), what do you think of the option to be able to register a For the process collector, you would implement the Does that make sense @dovreshef? If so, would you like to prototype this? As an aside, we would likely want to introduce |
So the design is:
trait Collector<'a, M>
where
M: EncodeMetric + 'a,
Self::List: Iterator<Item = &'a (Descriptor, M)>
{
type List;
fn collect(&self) -> Self::List;
}
Now I can see two ways to continue from here: Either:
Or:
WDYT? Any other design? |
👍 Small nit, maybe
👍
Instead of taking a
That would be very clean in my opinion. My gut feeling tells me we will be running in some trait object issues. That said, I think we should give it a try. Thanks @dovreshef for looking into this! |
@dovreshef are you still interested in contributing the |
The `Collector` abstraction allows users to provide additional metrics and their description on each scrape. See also: - https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#hdr-Custom_Collectors_and_constant_Metrics - prometheus#49 - prometheus#29
Cross referencing proposal for |
Sorry I missed that message (and disappeared) but I planned to do this for work, and got pulled to other issues. |
The `Collector` abstraction allows users to provide additional metrics and their description on each scrape. See also: - https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#hdr-Custom_Collectors_and_constant_Metrics - prometheus#49 - prometheus#29
The `Collector` abstraction allows users to provide additional metrics and their description on each scrape. See also: - https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#hdr-Custom_Collectors_and_constant_Metrics - prometheus#49 - prometheus#29 Signed-off-by: Max Inden <mail@max-inden.de>
The `Collector` abstraction allows users to provide additional metrics and their description on each scrape. See also: - https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#hdr-Custom_Collectors_and_constant_Metrics - prometheus#49 - prometheus#29 Signed-off-by: Max Inden <mail@max-inden.de>
The `Collector` abstraction allows users to provide additional metrics and their description on each scrape. See also: - https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#hdr-Custom_Collectors_and_constant_Metrics - #49 - #29 Signed-off-by: Max Inden <mail@max-inden.de>
Is there standardized process collector available as a library? I would like to have as a minimum something similar to Go, Python: Generic - MUST haves really:
(I often also add own Rust specific, with some inspiration from Go (of course goroutine , gc does not make sense, but compiler version, thread count, any allocation statistics, i.e. allocator cache hits, fragmentation estimation, number and sum of allocations, etc would be nice)
Th |
As the above conversation says, the |
We implemented this for Linkerd a while ago. Feel free to borrow from it, if useful: https://github.com/olix0r/kubert/blob/main/kubert-prometheus-process/src/lib.rs |
Nice, thanks a lot @olix0r! Most probably will do |
@olix0r great to see the |
Hello,
I recently stumbled upon tikv/rust-prometheus#392 and now I'm preparing a migration from
rust-prometheus
. I'm wondering how it would be possible to add a collector for process metrics just like whatrust-prometheus
does currently. I'm really inexperienced in those packages, and I don't really see how theProcessCollector
thing would translate here, to add some metrics related to the running process.Can you tell me what would be necessary to add support for this ? I was thinking probably as another crate that exposes a single global function like
crate::export_process_metrics()
; so that crate would have to add timers to run the collection and hope that the timer runs often enough to give a precise measurement when prometheus scrapes the endpoint ?Regards,
Gerry
The text was updated successfully, but these errors were encountered: