Skip to content

Commit

Permalink
refactor: outlineMetrics implements prometheus.Collector (#201)
Browse files Browse the repository at this point in the history
* refactor: change `outlineMetrics` to implement the `prometheus.Collector` interface

* Address review comments.
  • Loading branch information
sbruens authored Aug 28, 2024
1 parent 72e9238 commit ce562d1
Show file tree
Hide file tree
Showing 4 changed files with 303 additions and 200 deletions.
12 changes: 7 additions & 5 deletions cmd/outline-ss-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type SSServer struct {
stopConfig func() error
lnManager service.ListenerManager
natTimeout time.Duration
m *outlineMetrics
m *outlineMetricsCollector
replayCache service.ReplayCache
}

Expand Down Expand Up @@ -243,7 +243,7 @@ func (s *SSServer) Stop() error {
}

// RunSSServer starts a shadowsocks server running, and returns the server or an error.
func RunSSServer(filename string, natTimeout time.Duration, sm *outlineMetrics, replayHistory int) (*SSServer, error) {
func RunSSServer(filename string, natTimeout time.Duration, sm *outlineMetricsCollector, replayHistory int) (*SSServer, error) {
server := &SSServer{
lnManager: service.NewListenerManager(),
natTimeout: natTimeout,
Expand Down Expand Up @@ -348,9 +348,11 @@ func main() {
}
defer ip2info.Close()

m := newPrometheusOutlineMetrics(ip2info, prometheus.DefaultRegisterer)
m.SetBuildInfo(version)
_, err = RunSSServer(flags.ConfigFile, flags.natTimeout, m, flags.replayHistory)
metrics := newPrometheusOutlineMetrics(ip2info)
metrics.SetBuildInfo(version)
r := prometheus.WrapRegistererWithPrefix("shadowsocks_", prometheus.DefaultRegisterer)
r.MustRegister(metrics)
_, err = RunSSServer(flags.ConfigFile, flags.natTimeout, metrics, flags.replayHistory)
if err != nil {
slog.Error("Server failed to start. Aborting.", "err", err)
}
Expand Down
Loading

0 comments on commit ce562d1

Please sign in to comment.