예제 #1
0
파일: main.go 프로젝트: bobrik/scrappy
func main() {
	u := flag.String("u", "", "mesos url (http://host:port)")
	s := flag.String("s", "host", "sort order for slaves: host, cpu, cpu_percent, mem, mem_percent, tasks")
	r := flag.Bool("r", false, "reverse order")
	f := flag.String("f", "", "role name to filter on")

	flag.Parse()

	if *u == "" {
		flag.PrintDefaults()
		os.Exit(1)
	}

	mesosUrl, err := url.Parse(*u)
	if err != nil {
		log.Fatal(err)
	}

	state, err := mesos.GetState(mesosUrl)
	if err != nil {
		log.Fatal(err)
	}

	rep := report.Generate(state, *f)
	report.SortSlaves(rep.Slaves, *s, *r)

	for i, slave := range rep.Slaves {
		fmt.Printf("%s: %s / %s (%v)\n", slave.Hostname, slave.AllocatedResources.String(), slave.AvailableResources.String(), slave.Attributes)

		fmt.Printf("  roles:\n")
		for _, role := range slave.Roles {
			fmt.Printf("    - %s: %s / %s\n", role.Name, role.AllocatedResources.String(), role.AvailableResources.String())
			fmt.Printf("      tasks: %d\n", len(role.Tasks))
			for _, task := range role.Tasks {
				fmt.Printf("        - %s: %s\n", task.Name, task.Resources.String())
			}
		}

		if i < len(rep.Slaves)-1 {
			fmt.Println()
		}
	}
}
예제 #2
0
파일: main.go 프로젝트: bobrik/scrappy
func main() {
	u := flag.String("u", "", "mesos url (http://host:port)")
	f := flag.String("f", "", "role name to filter on")

	flag.Parse()

	if *u == "" {
		flag.PrintDefaults()
		os.Exit(1)
	}

	mesosUrl, err := url.Parse(*u)
	if err != nil {
		log.Fatal(err)
	}

	state, err := mesos.GetState(mesosUrl)
	if err != nil {
		log.Fatal(err)
	}

	rep := report.Generate(state, *f)

	roles := map[string]*report.Role{}
	names := []string{}

	for _, slave := range rep.Slaves {
		for _, role := range slave.Roles {
			if _, ok := roles[role.Name]; !ok {
				roles[role.Name] = &report.Role{
					Name:               role.Name,
					AvailableResources: mesos.Resources{},
					AllocatedResources: mesos.Resources{},
				}

				names = append(names, role.Name)
			}

			roles[role.Name].AvailableResources.Add(role.AvailableResources)
			roles[role.Name].AllocatedResources.Add(role.AllocatedResources)
		}
	}

	sort.Strings(names)

	w := &tabwriter.Writer{}
	w.Init(os.Stdout, 10, 0, 1, ' ', tabwriter.AlignRight)

	w.Write([]byte("role\tCPUs used\tCPUs total\tCPU %\tRAM used\tRAM total\tRAM %\t\n"))

	for _, name := range names {
		role := roles[name]
		fmt.Fprintf(
			w,
			"%s\t%.2f\t%.2f\t%.2f%%\t%.2fGB\t%.2fGB\t%.2f%%\t\n",
			role.Name,
			role.AllocatedResources.CPUs,
			role.AvailableResources.CPUs,
			role.AllocatedResources.CPUs/role.AvailableResources.CPUs*100,
			role.AllocatedResources.Memory/1024,
			role.AvailableResources.Memory/1024,
			role.AllocatedResources.Memory/role.AvailableResources.Memory*100,
		)
	}

	w.Flush()
}