// Merge guest volume/block device configuration with any volumes found in // host container. func mergeVolumeConfig(volumeconfig []volumeConfig, guest *gabs.Container) (err error) { var mounts *gabs.Container if guest.ExistsP("mount") { mounts = guest.S("mount") } else { mounts, _ = guest.ObjectP("mount") } mmap, _ := mounts.ChildrenMap() for _, mount := range mmap { var source string var path string var ok bool if source, ok = mount.Path("source").Data().(string); !ok { continue } if path, ok = mount.Path("path").Data().(string); !ok { continue } if source == "blk" && strings.HasPrefix(path, "/dev/ld") { return fmt.Errorf("Guest configuration defines " + "/dev/ld* block devices, cannot merge with " + "host volumes") } } blkIndex := 0 for _, v := range volumeconfig { mp := "/" + v.name obj, _ := guest.Object("mount", mp) obj.Set("blk", "source") obj.Set(fmt.Sprintf("/dev/ld%va", blkIndex), "path") blkIndex += 1 } return }
func (e *Exporter) scrapeApps(json *gabs.Container, ch chan<- prometheus.Metric) { elements, _ := json.S("apps").Children() states := map[string]string{ "running": "tasksRunning", "staged": "tasksStaged", "healthy": "tasksHealthy", "unhealthy": "tasksUnhealthy", "cpus": "cpus", "mem_in_mb": "mem", "disk_in_mb": "disk", "gpus": "gpus", "avg_uptime": "taskStats.startedAfterLastScaling.stats.lifeTime.averageSeconds", } name := "app_instances" gauge, new := e.Gauges.Fetch(name, "Marathon app instance count", "app") if new { log.Infof("Added gauge %q\n", name) } gauge.Reset() for _, app := range elements { id := app.Path("id").Data().(string) data := app.Path("instances").Data() count, ok := data.(float64) if !ok { log.Debugf(fmt.Sprintf("Bad conversion! Unexpected value \"%v\" for number of app instances\n", data)) continue } gauge.WithLabelValues(id).Set(count) for key, value := range states { name := fmt.Sprintf("app_task_%s", key) gauge, new := e.Gauges.Fetch(name, fmt.Sprintf("Marathon app task %s count", key), "app") if new { log.Infof("Added gauge %q\n", name) } data := app.Path(value).Data() count, ok := data.(float64) if !ok { log.Debugf(fmt.Sprintf("Bad conversion! Unexpected value \"%v\" for number of \"%s\" tasks\n", data, key)) continue } gauge.WithLabelValues(id).Set(count) } } }
// TODO: Properly get commit count func PushEvent(data *gabs.Container) { repo, _ := data.S("repository", "full_name").Data().(string) user, _ := data.S("pusher", "name").Data().(string) gitio := GitioShort(data.S("head_commit", "url").Data().(string)) commits, _ := data.S("commits").Children() cobj, _ := data.S("commits").ChildrenMap() fmt.Printf("[!] Commit # %d\n", len(cobj)) commitlen := strconv.Itoa(len(cobj)) message <- "[" + repo + "] " + user + " pushed " + commitlen + " commits " + gitio for _, commit := range commits { hash := commit.S("id").Data().(string)[0:6] msg := commit.S("message").Data().(string) user := commit.S("author", "name").Data().(string) message <- "[" + repo + "] " + user + " " + hash + " - " + msg } }
func PullRequestEvent(data *gabs.Container) { action := data.S("action").Data().(string) repo, _ := data.S("repository", "full_name").Data().(string) user, _ := data.S("pull_request", "user", "login").Data().(string) title, _ := data.S("pull_request", "title").Data().(string) inum, _ := data.S("pull_request", "number").Data().(string) gitio := GitioShort(data.S("pull_request", "html_url").Data().(string)) switch action { case "opened": message <- "[" + repo + "] " + user + " opened pull request #" + inum + " \"" + title + "\" " + gitio case "closed": if data.S("pull_request", "merged").Data().(bool) { message <- "[" + repo + "] " + user + " merged pull request #" + inum + " \"" + title + "\" " + gitio } else { message <- "[" + repo + "] " + user + " closed pull request #" + inum + " \"" + title + "\" " + gitio } case "assigned": assignee, _ := data.S("pull_request", "assignee", "login").Data().(string) message <- "[" + repo + "] " + user + " assigned pull request #" + inum + " \"" + title + "\" to " + assignee + " " + gitio default: // Ignore it } }
func IssuesEvent(data *gabs.Container) { action := data.S("action").Data().(string) repo, _ := data.S("repository", "full_name").Data().(string) user, _ := data.S("issue", "user", "login").Data().(string) title, _ := data.S("issue", "title").Data().(string) inum, _ := data.S("issue", "id").Data().(string) gitio := GitioShort(data.S("issue", "html_url").Data().(string)) switch action { case "opened": message <- "[" + repo + "] " + user + " opened issue #" + inum + " \"" + title + "\" " + gitio case "closed": message <- "[" + repo + "] " + user + " closed issue #" + inum + " \"" + title + "\" " + gitio case "reopened": message <- "[" + repo + "] " + user + " reopened issue #" + inum + " \"" + title + "\" " + gitio case "assigned": assignee, _ := data.S("issue", "assignee", "login").Data().(string) message <- "[" + repo + "] " + user + " assigned issue #" + inum + " \"" + title + "\" to " + assignee + " " + gitio default: // Ignore it } }