Skip to content

Is there a way to register a callback that will be called on scrape? #830

@scottbelden

Description

@scottbelden

Maybe I'm going about this the wrong way, but I'd like to create dynamic gauges for users logged in to a system and the gauge will track the active jobs they are running. I think I would do this with something like the following:

USER_GAUGES = {}

def update_user_gauges():
    for user, active_jobs in data_structure.items():
        g = USER_GAUGES.set_default(user, Gauge(f"namespace_{user}_current_jobs"))
        g.set(active_jobs)

And then I would like register update_user_gauges to get called when a scrape is about to happen (similar to doing Guage.set_function(callable)).

Is there a way to do this? Or am I going about this the wrong way and there is a better approach?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions