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

Add option to serve metrics via http #20

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sudeephb
Copy link

@sudeephb sudeephb commented Dec 9, 2022

A -d flag can be used with the pkg-exporter command to serve metrics via HTTP. We also added a few other flags that can be used to modify the default behavior of the exporter.

@margau
Copy link
Owner

margau commented Dec 15, 2022

Hi,
thanks for the PR, this looks very good to me!
Could you add a brief explanation about the different modes to the README?

Would merge then.

@margau
Copy link
Owner

margau commented Jan 14, 2023

Sorry for the late response,
could you fix the remaining lint errors from the CI Job? Thanks!

Copy link
Owner

@margau margau left a comment

Choose a reason for hiding this comment

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

Can we rebase that instead of merging? That would remove the feature from #21 again.

helgharbi and others added 4 commits January 27, 2024 13:23
We modified the default behaviour to expose Prometheus
metrics in HTTP(using the -d flag). Without the -d flag, it
behaves as it did before.
We also added a few other flags to provide more flexibility.
Check if Gauge exists before creating it.

Use the same registry during all the serve blocking process
instead of recreating and repopulating it every time.
@sudeephb
Copy link
Author

Hello again,
Apologies for the very late response. I have rebased on the main branch. Can you have a look?

@sudeephb sudeephb requested a review from margau January 27, 2024 07:58
@margau
Copy link
Owner

margau commented Jan 27, 2024

In general, this looks good, thanks!
I'd need to test this again, please ping me if you don't hear back within the next week.

Copy link
Owner

@margau margau left a comment

Choose a reason for hiding this comment

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

Looking good overall, thanks!
Some minor remarks attached.

Another thought:

We should consider adding a metric with the timestamp of the last update. When using a file, this information is implicitly part of node_textfile_mtime_seconds, but thats not the case when this is served as HTTP.

"--port",
type=int,
default=os.getenv("PKG_EXPORTER_PORT", 8089),
help="Bind port",
Copy link
Owner

Choose a reason for hiding this comment

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

The help should display the default port

"--bind-addr",
type=str,
default=os.getenv("PKG_EXPORTER_ADDR", "0.0.0.0"),
help="Bind address",
Copy link
Owner

Choose a reason for hiding this comment

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

The help should display the default bind address.

"-a",
"--bind-addr",
type=str,
default=os.getenv("PKG_EXPORTER_ADDR", "0.0.0.0"),
Copy link
Owner

Choose a reason for hiding this comment

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

We should bind to a dualstack address, probably ::

exporter_file = os.getenv("PKG_EXPORTER_FILE", "/var/prometheus/pkg-exporter.prom")

def write_registry_to_file(registry, exporter_file=None):
if not exporter_file:
Copy link
Owner

Choose a reason for hiding this comment

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

I think this is duplicate, exporter_file is already filled with a default in line 87

default=os.getenv(
"PKG_EXPORTER_FILE",
"/var/prometheus/pkg-exporter.prom"),
help="File to export, if used the content will not be served",
Copy link
Owner

Choose a reason for hiding this comment

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

In my opinion, the default is "output to a file" anyway? The comment indicates that by default the HTTP Server is run.

def serve(addr, port, timewait, rootdir):
start_http_server(addr=addr, port=port)
while True:
sleep(timewait)
Copy link
Owner

Choose a reason for hiding this comment

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

Is there a more elegant way of solving this? I'm not a fan of a static sleep, especially since this does not include the time "populate_registry" takes.

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.

3 participants