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 unix socket support for prometheus #128

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

master-hax
Copy link

@master-hax master-hax commented Sep 4, 2024

this PR allows for listening on a Unix domain socket for prometheus metrics by prefixing the path with unix:

also open to alternative prefixes like unix/ (which is what caddy uses)

some of this approach can probably be reused for #112

example usage:

starting endlessh-go

./endlessh-go -alsologtostderr -enable_prometheus -prometheus_host unix:./coolmetricsocket.socket

getting metrics

curl -v --unix-socket ./coolmetricsocket.socket whateverhostnameyouwant/metrics

@master-hax
Copy link
Author

cc @shizunge do you mind taking a look?

@master-hax
Copy link
Author

cc @Bananz0 @JeDaYoshi do you mind taking a look?

@JeDaYoshi
Copy link

I'm not part of the project, so I can't act on it.

@master-hax
Copy link
Author

gotcha! appreciate the fast response.

i see you have contributed here before though - do you have any suggestions or criticisms for this change?

@master-hax
Copy link
Author

cc @olofvndrhr do you mind taking a look?

@shizunge
Copy link
Owner

I will take a look at this at Sept 19 or 20.

@@ -87,7 +89,24 @@ func InitPrometheus(prometheusHost, prometheusPort, prometheusEntry string) {
handler := promhttp.HandlerFor(promReg, promhttp.HandlerOpts{EnableOpenMetrics: true})
http.Handle("/"+prometheusEntry, handler)
go func() {
glog.Infof("Starting Prometheus on %v:%v, entry point is /%v", prometheusHost, prometheusPort, prometheusEntry)

if strings.HasPrefix(prometheusHost, "unix:") {
Copy link
Owner

Choose a reason for hiding this comment

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

Can you move this to a new function?

if strings.HasPrefix(prometheusHost, "unix:") {
socketPath := prometheusHost[5:]
glog.Infof("Starting Prometheus on Unix socket %v, entry point is /%v", socketPath, prometheusEntry)
os.Remove(socketPath) // allow failure
Copy link
Owner

Choose a reason for hiding this comment

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

_ := os.Remove(socketPath)

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