Merge pull request #5 from nightlyone/support_ssl_urls

hacked up support for https URLs
This commit is contained in:
Ivan Daniluk 2015-07-10 14:55:25 +03:00
commit 730bf52a5e
3 changed files with 23 additions and 0 deletions

View File

@ -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()

View File

@ -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 {

17
string_array.go Normal file
View File

@ -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, ",")
}