This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a prometheus HTTP server per ignite-spawn process in an unix socket
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package prometheus | ||
|
||
import ( | ||
"net/http" | ||
"net" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
) | ||
|
||
func ServeMetrics(socketPath string) error { | ||
// Create a registry to register metrics into | ||
registry := prometheus.NewRegistry() | ||
// Register the default collectors with this registry | ||
registry.MustRegister(prometheus.NewBuildInfoCollector()) | ||
registry.MustRegister(prometheus.NewGoCollector()) | ||
registry.MustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{})) | ||
|
||
// Create a HTTP server to handle metrics requests | ||
server := http.Server{ | ||
Handler: promhttp.HandlerFor(registry, promhttp.HandlerOpts{}), | ||
} | ||
|
||
// Listen on the unix socket and serve the web server | ||
unixListener, err := net.Listen("unix", socketPath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return server.Serve(unixListener) | ||
} |