From dbe57b21e5e9bb46129d471537eee85ef117c730 Mon Sep 17 00:00:00 2001 From: Ingo Oeser Date: Wed, 8 Jul 2015 10:35:49 +0200 Subject: [PATCH] hacked up support for https URLs since many real life services are behind SSL only --- main.go | 3 +++ service.go | 3 +++ string_array.go | 17 +++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 string_array.go diff --git a/main.go b/main.go index bdf9503..0d0595e 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,7 @@ import ( ) var ( + urls = &StringArray{} interval = flag.Duration("i", 5*time.Second, "Polling interval") portsArg = flag.String("ports", "", "Ports for accessing services expvars (start-end,port2,port3)") varsArg = flag.String("vars", "mem:memstats.Alloc,mem:memstats.Sys,mem:memstats.HeapAlloc,mem:memstats.HeapInuse,memstats.EnableGC,memstats.NumGC,duration:memstats.PauseTotalNs", "Vars to monitor (comma-separated)") @@ -20,6 +21,7 @@ var ( ) func main() { + flag.Var(urls, "url", "urls to poll for expvars") flag.Usage = Usage flag.Parse() @@ -31,6 +33,7 @@ func main() { ports = append(ports, port) } } + ports = append(ports, *urls...) if len(ports) == 0 { fmt.Fprintln(os.Stderr, "no ports specified. Use -ports arg to specify ports of Go apps to monitor") Usage() diff --git a/service.go b/service.go index ca5420a..a7681f7 100644 --- a/service.go +++ b/service.go @@ -112,6 +112,9 @@ func guessValue(value *jason.Value) interface{} { // // If host is not specified, 'localhost' is used. func (s Service) Addr() string { + if strings.HasPrefix(s.Port, "https://") { + return fmt.Sprintf("%s%s", s.Port, ExpvarsURL) + } // Try as port only _, err := strconv.Atoi(s.Port) if err == nil { diff --git a/string_array.go b/string_array.go new file mode 100644 index 0000000..666789c --- /dev/null +++ b/string_array.go @@ -0,0 +1,17 @@ +package main + +import ( + "strings" +) + +type StringArray []string + +func (a *StringArray) Set(s string) error { + s = strings.TrimSuffix(s, "/debug/vars") + *a = append(*a, s) + return nil +} + +func (a *StringArray) String() string { + return strings.Join(*a, ",") +}