add debug server with status page

master
Serge Bazanski 2018-10-06 12:32:01 +01:00
parent 9c5eac6e8c
commit 4676508453
3 changed files with 82 additions and 14 deletions

56
Gopkg.lock generated
View File

@ -17,6 +17,14 @@
pruneopts = "UT"
revision = "de5bf2ad457846296e2031421a34e2568e304e35"
[[projects]]
digest = "1:e92f5581902c345eb4ceffdcd4a854fb8f73cf436d47d837d1ec98ef1fe0a214"
name = "github.com/StackExchange/wmi"
packages = ["."]
pruneopts = "UT"
revision = "5d049714c4a64225c3c79a7cf7d02f7fb5b96338"
version = "1.0.0"
[[projects]]
digest = "1:320e7ead93de9fd2b0e59b50fd92a4d50c1f8ab455d96bc2eb083267453a9709"
name = "github.com/asaskevich/govalidator"
@ -25,14 +33,6 @@
revision = "ccb8e960c48f04d6935e72476ae4a51028f9e22f"
version = "v9"
[[projects]]
digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec"
name = "github.com/davecgh/go-spew"
packages = ["spew"]
pruneopts = "UT"
revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73"
version = "v1.1.1"
[[projects]]
branch = "master"
digest = "1:08aeb20c1d146f9254126139f272865927b6db288145f88f0a3baacc24ddfa24"
@ -52,6 +52,17 @@
pruneopts = "UT"
revision = "29433ec527e78486ea0a5758817ab672d977f90e"
[[projects]]
digest = "1:64a5a67c69b70c2420e607a8545d674a23778ed9c3e80607bfd17b77c6c87f6a"
name = "github.com/go-ole/go-ole"
packages = [
".",
"oleutil",
]
pruneopts = "UT"
revision = "a41e3c4b706f6ae8dfbff342b06e40fa4d2d0506"
version = "v1.2.1"
[[projects]]
digest = "1:50d6bc4aa3e70803230bb98a4b0e0f1331fefc2eb324e087adf7e986b8da082e"
name = "github.com/go-openapi/analysis"
@ -186,6 +197,25 @@
revision = "3536a929edddb9a5b34bd6861dc4a9647cb459fe"
version = "v1.1.2"
[[projects]]
branch = "master"
digest = "1:a7cc4447e0c2432f217fd2bed937c100ec475272a7a9306477170c2934297357"
name = "github.com/q3k/statusz"
packages = ["."]
pruneopts = "UT"
revision = "924f04ea71149b75f5b10f426cc4c39d6d90f6f2"
[[projects]]
branch = "master"
digest = "1:8f042d4b4c48d38d7a1201096299bd26d044c97c032ab20ee171fe5b0d201d2e"
name = "github.com/shirou/gopsutil"
packages = [
"internal/common",
"load",
]
pruneopts = "UT"
revision = "a11c78ba2c13c5b1ee59c53296ba35f92f0ce658"
[[projects]]
branch = "master"
digest = "1:1ae047ded1ddcbe0eca8b0772e3ff2c10e354db4c42c65b96d0386883e63904d"
@ -205,9 +235,12 @@
[[projects]]
branch = "master"
digest = "1:c2789211d4035eb0843b85958ecf7cb4a5ea91c2d4decee652c94ce898e433cb"
digest = "1:850d28ab022512e2cd3cf511a77f363c29e22689b4031f2050871f5de47ae4a0"
name = "golang.org/x/sys"
packages = ["unix"]
packages = [
"unix",
"windows",
]
pruneopts = "UT"
revision = "4497e2df6f9e69048a54498c7affbbec3294ad47"
@ -301,12 +334,13 @@
analyzer-name = "dep"
analyzer-version = 1
input-imports = [
"github.com/davecgh/go-spew/spew",
"github.com/digitalocean/go-netbox/netbox",
"github.com/digitalocean/go-netbox/netbox/client",
"github.com/digitalocean/go-netbox/netbox/client/dcim",
"github.com/digitalocean/go-netbox/netbox/models",
"github.com/golang/glog",
"github.com/golang/protobuf/proto",
"github.com/q3k/statusz",
"golang.org/x/net/context",
"google.golang.org/grpc",
]

View File

@ -18,6 +18,7 @@ var (
flagConfigPath string
flagNetboxHost string
flagNetboxAPIKey string
flagDebugListen string
)
func init() {
@ -28,6 +29,7 @@ func main() {
flag.StringVar(&flagConfigPath, "config_path", "./topo.pb.text", "Text proto configuration of Topo (per config.proto)")
flag.StringVar(&flagNetboxHost, "netbox_host", "netbox.bgp.wtf", "Netbox host")
flag.StringVar(&flagNetboxAPIKey, "netbox_api_key", "", "Netbox API key")
flag.StringVar(&flagDebugListen, "debug_listen", "127.0.0.1:42001", "Debug HTTP listen address")
flag.Parse()
ctx := context.Background()
@ -52,4 +54,10 @@ func main() {
if err != nil {
glog.Exitf("Initial netbox feed failed: %v", err)
}
sconf := ServiceConfig{
DebugListen: flagDebugListen,
}
srv := NewService(gr, sconf)
srv.Run()
}

View File

@ -1,7 +1,33 @@
package main
import confpb "code.hackerspace.pl/q3k/topo/proto/config"
import (
"net/http"
type service struct {
config *confpb.Config
"code.hackerspace.pl/q3k/topo/graph"
"github.com/golang/glog"
_ "github.com/q3k/statusz"
)
type ServiceConfig struct {
DebugListen string
}
type Service struct {
gr *graph.Graph
config ServiceConfig
}
func NewService(gr *graph.Graph, c ServiceConfig) *Service {
return &Service{
gr: gr,
config: c,
}
}
func (s *Service) Run() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/debug/status", http.StatusSeeOther)
})
glog.Infof("Debug listening on %s....", s.config.DebugListen)
http.ListenAndServe(s.config.DebugListen, nil)
}