Skip to content

Commit

Permalink
cmd/forwarder/run: register process metrics
Browse files Browse the repository at this point in the history
Since we are using a custom registry we need to add Go and process stats.
Unfortunately the process data is only available in Linux and Windows.
  • Loading branch information
mmatczuk committed Oct 17, 2023
1 parent 90cc806 commit 5fce40a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/forwarder/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/saucelabs/forwarder"
"github.com/saucelabs/forwarder/bind"
"github.com/saucelabs/forwarder/header"
Expand All @@ -28,6 +29,7 @@ import (
"github.com/saucelabs/forwarder/utils/osdns"
"github.com/spf13/cobra"
"go.uber.org/goleak"
"go.uber.org/multierr"
)

type command struct {
Expand Down Expand Up @@ -186,6 +188,10 @@ func (c *command) runE(cmd *cobra.Command, _ []string) (cmdErr error) {
}

if c.apiServerConfig.Addr != "" {
if err := c.registerProcMetrics(); err != nil {
return fmt.Errorf("register process metrics: %w", err)
}

ep := append([]forwarder.APIEndpoint{
{
Path: "/configz",
Expand Down Expand Up @@ -217,6 +223,15 @@ func (c *command) runE(cmd *cobra.Command, _ []string) (cmdErr error) {
return g.Run()
}

func (c *command) registerProcMetrics() error {
return multierr.Combine(
// Note that ProcessCollector is only available in Linux and Windows.
c.promReg.Register(collectors.NewProcessCollector(
collectors.ProcessCollectorOpts{})),
c.promReg.Register(collectors.NewGoCollector()),
)
}

func Command() *cobra.Command {
c := command{
promReg: prometheus.NewRegistry(),
Expand Down

0 comments on commit 5fce40a

Please sign in to comment.