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

Prometheus: Add format_down config param #2201

Closed
wants to merge 3 commits into from

Conversation

bbusse
Copy link
Contributor

@bbusse bbusse commented Jun 17, 2023

No description provided.

Comment on lines 10 to 12
(default "{__v:.0f}")
format_down: Output if prometheus is not available
(default 'n/a')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use this module.

Does format = "[{__v:.0f}]" work ? It hides.
Does format = "{__v:.0f}|\?show n/a" work ? It shows n/a. -- It's a replacement for format_down.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format = "{__v:.0f}|\?show n/a" works! Thanks. Is this documented somewhere?
It only works in the module code, not from user config, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it doesn't work, then prometheus is not updated to py3status standards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module has to be updated to use safe_format() for this to work it seems

Comment on lines +107 to +97
try:
r = self.py3.request(self.server + "/api/v1/query", params={"query": query})
except Exception as e:
self.py3.log(f"prometheus: Request failed {e}")
return []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prometheus {
    on_error = "hide"
}

... might be what you want in your config... It retries every 10 seconds, I think.

@bbusse
Copy link
Contributor Author

bbusse commented Jun 22, 2023

Maybe something like this, now using py3.safe_format()

r = self.py3.request(self.server + "/api/v1/query", params={"query": query})
try:
r = self.py3.request(self.server + "/api/v1/query", params={"query": query})
except Exception as e:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like @lasers I would rather display the error on the bar than silencing it please

on_error is the way to go for users who wish to dismiss errors like you

@ultrabug
Copy link
Owner

Almost there, thanks!

@ultrabug
Copy link
Owner

ultrabug commented Dec 4, 2023

@bbusse would you like to cope with the feedbacks so we can get this in?

@bbusse
Copy link
Contributor Author

bbusse commented Dec 4, 2023

Yes, absolutely! Will take care of it tomorrow

@lasers
Copy link
Contributor

lasers commented Feb 5, 2024

@bbusse If you don't mind... Can I get a r.json() output from you? I could try and fix this... And maybe update this module with other things too... such as thresholds. You can test it too when I'm done.

@ultrabug
Copy link
Owner

ultrabug commented Mar 4, 2024

@bbusse I'm closing this until you can/want to make some time to finish this, thanks again!

@ultrabug ultrabug closed this Mar 4, 2024
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

Successfully merging this pull request may close these issues.

None yet

3 participants