| 18 | ) |
| 19 | |
| 20 | func saveMetrics(addr, pathPrefix string, seconds uint32, metricTypes []string) { |
| 21 | u, err := url.Parse(addr) |
| 22 | if err != nil || (u.Host == "" && u.Scheme != "" && u.Scheme != "file") { |
| 23 | u, err = url.Parse("http://" + addr) |
| 24 | } |
| 25 | if err != nil || u.Host == "" { |
| 26 | glog.Errorf("error while parsing address %s: %s", addr, err) |
| 27 | return |
| 28 | } |
| 29 | |
| 30 | duration := time.Duration(seconds) * time.Second |
| 31 | |
| 32 | for _, metricType := range metricTypes { |
| 33 | source := u.String() + metricMap[metricType] |
| 34 | switch metricType { |
| 35 | case "cpu": |
| 36 | source += fmt.Sprintf("%s%d", "?seconds=", seconds) |
| 37 | case "trace": |
| 38 | source += fmt.Sprintf("%s%d", "?seconds=", seconds) |
| 39 | } |
| 40 | savePath := fmt.Sprintf("%s%s.gz", pathPrefix, metricType) |
| 41 | if err := saveDebug(source, savePath, duration); err != nil { |
| 42 | glog.Errorf("error while saving metric from %s: %s", source, err) |
| 43 | continue |
| 44 | } |
| 45 | |
| 46 | glog.Infof("saving %s metric in %s", metricType, savePath) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // saveDebug writes the debug info specified in the argument fetching it from the host |
| 51 | // provided in the configuration |