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

Dynamic metrics #646

Open
freddiebity opened this issue Nov 21, 2024 · 1 comment
Open

Dynamic metrics #646

freddiebity opened this issue Nov 21, 2024 · 1 comment

Comments

@freddiebity
Copy link

Hi,

I'm trying to do something like this

const task = cron.schedule("*/2 * * * *", async () => {
    const fee_accounts = await getFeeAccounts();

    fee_accounts.forEach((feeAccount) => {
        let feeAccountBalance = new Gauge({
            name: `fee_account_${feeAccount.type}_balance`,
            help: `OGY fee account balance for ${feeAccount.weight}g NFT canister`,
        });
        
        prometheusClient.register.registerMetric(feeAccountBalance);
        feeAccountBalance.set(feeAccount.balance)
    })
})

the account type could be different each time and so i want to set up a new name each time. the problem is, this records once on start up and then the second time the cron schedule runs it never updates. I see the cron job runs correctly and i get fresh data each time too from getFeeAccounts().

@freddiebity
Copy link
Author

also tried storing the Gauge in a object like const metrics = {}

 metrics[metric_name] = feeAccountBalance

but that doesnt work

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

1 participant