Skip to content

Commit

Permalink
Server metrics on the main http server instance
Browse files Browse the repository at this point in the history
  • Loading branch information
anbsky committed Mar 2, 2020
1 parent 9e19c10 commit 2b5d982
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 35 deletions.
4 changes: 3 additions & 1 deletion api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"github.com/lbryio/lbrytv/app/player"
"github.com/lbryio/lbrytv/app/proxy"
"github.com/lbryio/lbrytv/app/publish"
"github.com/lbryio/lbrytv/app/users"
"github.com/lbryio/lbrytv/app/status"
"github.com/lbryio/lbrytv/app/users"
"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/gorilla/mux"
)
Expand All @@ -20,6 +21,7 @@ func InstallRoutes(proxyService *proxy.ProxyService, r *mux.Router) {
}

r.HandleFunc("/", Index)
r.Handle("/internal/metrics", promhttp.Handler())

v1Router := r.PathPrefix("/api/v1").Subrouter()
v1Router.HandleFunc("/proxy", proxyHandler.HandleOptions).Methods("OPTIONS")
Expand Down
4 changes: 0 additions & 4 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/lbryio/lbrytv/app/proxy"
"github.com/lbryio/lbrytv/app/router"
"github.com/lbryio/lbrytv/config"
"github.com/lbryio/lbrytv/internal/metrics"
"github.com/lbryio/lbrytv/server"

"github.com/spf13/cobra"
Expand All @@ -27,9 +26,6 @@ var rootCmd = &cobra.Command{
log.Fatal(err)
}

ms := metrics.NewServer(config.MetricsAddress(), config.MetricsPath())
ms.Serve()

// ServeUntilShutdown is blocking, should be last
s.ServeUntilShutdown()
},
Expand Down
27 changes: 0 additions & 27 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
package metrics

import (
"net/http"
"sync"

"github.com/lbryio/lbrytv/internal/monitor"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

var once sync.Once

type Server struct {
monitor.ModuleLogger

Address string
Path string
}

func NewServer(address string, path string) *Server {
return &Server{monitor.NewModuleLogger("metrics"), address, path}
}

func (s *Server) Serve() {
go func() {
http.Handle(s.Path, promhttp.Handler())
http.ListenAndServe(s.Address, nil)
}()
s.Log().Infof("metrics server listening on %v%v", s.Address, s.Path)
}

const (
nsPlayer = "player"
nsIAPI = "iapi"
Expand Down
3 changes: 0 additions & 3 deletions lbrytv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ Database:
DBName: lbrytv
Options: sslmode=disable

MetricsAddress: :2112
MetricsPath: /metrics

PublishSourceDir: /storage/published
BlobFilesDir: /storage/lbrynet/blobfiles

Expand Down

0 comments on commit 2b5d982

Please sign in to comment.