prometheus handle metrics

This commit is contained in:
Sergey Cherepanov 2022-10-13 17:00:51 +03:00
parent 8970730ec9
commit e7602a164a
No known key found for this signature in database
GPG Key ID: 87F8EDE8FBDF637C
2 changed files with 3 additions and 2 deletions

View File

@ -38,7 +38,7 @@ var (
func main() {
flag.Parse()
rand.Seed(time.Now().UnixNano())
if *flagVersion {
fmt.Println(app.VersionDescription())
return

View File

@ -50,8 +50,9 @@ func (m *metric) Run(ctx context.Context) (err error) {
}
if m.config.Addr != "" {
var errCh = make(chan error)
http.Handle("/metrics", promhttp.HandlerFor(m.registry, promhttp.HandlerOpts{}))
go func() {
errCh <- http.ListenAndServe(m.config.Addr, promhttp.HandlerFor(m.registry, promhttp.HandlerOpts{}))
errCh <- http.ListenAndServe(m.config.Addr, nil)
}()
select {
case err = <-errCh: