Skip to content
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

How to add two different metrics to one register? #110

Closed
c19 opened this issue Nov 16, 2022 · 3 comments
Closed

How to add two different metrics to one register? #110

c19 opened this issue Nov 16, 2022 · 3 comments

Comments

@c19
Copy link

c19 commented Nov 16, 2022

let total_bytes: Family<TrafficLabels, Counter> = Family::default();
    let connection_count: Family<ConnectionLabels, Gauge> = Family::default();
    let mut registry = Registry::default();
    registry.register(
        "total_bytes",
        "Accumulated bytes going through sever",
        Box::new(total_bytes.clone()),
    );
    
    registry.register(
        "connection count",
        "Count of current connections",
        Box::new(connection_count.clone()),
    );

results in:

mismatched types
expected struct `Family<TrafficLabels, prometheus_client::metrics::counter::Counter, fn() -> prometheus_client::metrics::counter::Counter>`
   found struct `Family<ConnectionLabels, prometheus_client::metrics::gauge::Gauge, fn() -> prometheus_client::metrics::gauge::Gauge>`rustc[E0308](https://doc.rust-lang.org/error-index.html#E0308)
@phyber
Copy link
Contributor

phyber commented Nov 16, 2022

You'll want:

let mut registry = <Registry>::default();

Which should let you do what you're attempting here.

@mxinden
Copy link
Member

mxinden commented Nov 17, 2022

Thanks @phyber for all the help you are providing to users of the library! Greatly appreciated.

@c19 what @phyber said above. As a heads up, this will soon be a lot simpler, i.e. your use-case will become the default behavior. In case you are interested, see #100.

@c19
Copy link
Author

c19 commented Nov 24, 2022

Thanks. That solves the problem.

@c19 c19 closed this as completed Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants