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

simple sptp<-> prometheus metrics gw #313

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions cmd/sptp-exporter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright (c) Facebook, Inc. and its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"flag"
"net/http"
"time"

_ "net/http/pprof"

"github.com/facebook/time/ptp/sptp/stats"
log "github.com/sirupsen/logrus"
)

func main() {
var (
verboseFlag bool
exporterPortFlag int
sptpMonitoringPortFlag int
intervalFlag time.Duration
pprofFlag string
)

flag.BoolVar(&verboseFlag, "verbose", false, "verbose output")
flag.IntVar(&sptpMonitoringPortFlag, "monitoringport", 4269, "port sptp metrics http server is listening on")
flag.IntVar(&exporterPortFlag, "exporterport", 6942, "port prometheus metrics exporter is listening on")

flag.DurationVar(&intervalFlag, "interval", time.Second, "how often to fetch metrics from sptp")
flag.StringVar(&pprofFlag, "pprof", "", "Address to have the profiler listen on, disabled if empty.")

flag.Parse()

log.SetLevel(log.InfoLevel)
if verboseFlag {
log.SetLevel(log.DebugLevel)
}
if pprofFlag != "" {
go func() {
err := http.ListenAndServe(pprofFlag, nil)
if err != nil {
log.Errorf("Failed to start pprof. Err: %v", err)
}
}()
}
exporter := stats.NewPrometheusExporter(exporterPortFlag, sptpMonitoringPortFlag, intervalFlag)
exporter.Start()
}
13 changes: 11 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.18

require (
github.com/Knetic/govaluate v3.0.0+incompatible
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
github.com/davecgh/go-spew v1.1.1
github.com/eclesh/welford v0.0.0-20150116075914-eec62615b1f0
github.com/fatih/color v1.13.0
Expand All @@ -14,6 +15,7 @@ require (
github.com/jsimonetti/rtnetlink v1.2.0
github.com/olekukonko/tablewriter v0.0.5
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.14.0
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.4.0
Expand All @@ -22,29 +24,36 @@ require (
go.bug.st/serial v1.5.0
golang.org/x/exp v0.0.0-20220518171630-0b5c67f07fdf
golang.org/x/net v0.17.0
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29
golang.org/x/sync v0.5.0
golang.org/x/sys v0.13.0
golang.org/x/term v0.13.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/creack/goselect v0.1.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/josharian/native v1.0.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mdlayher/netlink v1.6.0 // indirect
github.com/mdlayher/socket v0.2.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
)
Loading