mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
cmd/printmetric: add start of tool to dump usermetrics to JSON
Updates tailscale/corp#22075 Change-Id: I5b539fcb4aca1b93406cf139c719a5e3c64ff7f7 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
ae5bc88ebe
commit
decf89f402
39
cmd/printmetric/printmetric.go
Normal file
39
cmd/printmetric/printmetric.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// The printmetric command prints out JSON of the usermetric definitions.
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"tailscale.com/ipn/store/mem"
|
||||||
|
"tailscale.com/tsnet"
|
||||||
|
"tailscale.com/tstest/integration/testcontrol"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var control testcontrol.Server
|
||||||
|
ts := httptest.NewServer(&control)
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
td, err := ioutil.TempDir("", "testcontrol")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(td)
|
||||||
|
|
||||||
|
tsn := &tsnet.Server{
|
||||||
|
Dir: td,
|
||||||
|
Store: new(mem.Store),
|
||||||
|
UserLogf: log.Printf,
|
||||||
|
Ephemeral: true,
|
||||||
|
ControlURL: ts.URL,
|
||||||
|
}
|
||||||
|
if err := tsn.Start(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
tsn.Sys().UserMetricsRegistry().Handler(rec, httptest.NewRequest("GET", "/unused", nil))
|
||||||
|
os.Stdout.Write(rec.Body.Bytes())
|
||||||
|
}
|
@ -126,6 +126,7 @@ type Server struct {
|
|||||||
initOnce sync.Once
|
initOnce sync.Once
|
||||||
initErr error
|
initErr error
|
||||||
lb *ipnlocal.LocalBackend
|
lb *ipnlocal.LocalBackend
|
||||||
|
sys *tsd.System
|
||||||
netstack *netstack.Impl
|
netstack *netstack.Impl
|
||||||
netMon *netmon.Monitor
|
netMon *netmon.Monitor
|
||||||
rootPath string // the state directory
|
rootPath string // the state directory
|
||||||
@ -518,6 +519,7 @@ func (s *Server) start() (reterr error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sys := new(tsd.System)
|
sys := new(tsd.System)
|
||||||
|
s.sys = sys
|
||||||
if err := s.startLogger(&closePool, sys.HealthTracker(), tsLogf); err != nil {
|
if err := s.startLogger(&closePool, sys.HealthTracker(), tsLogf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1227,6 +1229,13 @@ func (s *Server) CapturePcap(ctx context.Context, pcapFile string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sys returns a handle to the Tailscale subsystems of this node.
|
||||||
|
//
|
||||||
|
// This is not a stable API, nor are the APIs of the returned subsystems.
|
||||||
|
func (s *Server) Sys() *tsd.System {
|
||||||
|
return s.sys
|
||||||
|
}
|
||||||
|
|
||||||
type listenKey struct {
|
type listenKey struct {
|
||||||
network string
|
network string
|
||||||
host netip.Addr // or zero value for unspecified
|
host netip.Addr // or zero value for unspecified
|
||||||
|
Loading…
Reference in New Issue
Block a user