Ejemplo n.º 1
0
Archivo: ps.go Proyecto: 2opremio/cli
func processList(app string) {
	data, err := ConvoxGet(fmt.Sprintf("/apps/%s/processes", app))

	if err != nil {
		stdcli.Error(err)
		return
	}

	var processes *Processes
	err = json.Unmarshal(data, &processes)

	if err != nil {
		stdcli.Error(err)
		return
	}

	longest := 7

	for _, ps := range *processes {
		if len(ps.Name) > longest {
			longest = len(ps.Name)
		}
	}

	t := stdcli.NewTable("ID", "PROCESS", "RELEASE", "MEM", "COMMAND")

	for _, ps := range *processes {
		t.AddRow(ps.Id, ps.Name, ps.Release, fmt.Sprintf("%d", ps.Memory), ps.Command)
	}

	t.Print()
}
Ejemplo n.º 2
0
func cmdReleases(c *cli.Context) {
	_, app, err := stdcli.DirApp(c, ".")

	if err != nil {
		stdcli.Error(err)
		return
	}

	data, err := ConvoxGet("/apps/" + app)

	if err != nil {
		stdcli.Error(err)
		return
	}

	var a *App
	err = json.Unmarshal(data, &a)

	data, err = ConvoxGet(fmt.Sprintf("/apps/%s/releases", a.Name))

	if err != nil {
		stdcli.Error(err)
		return
	}

	var releases *Releases
	err = json.Unmarshal(data, &releases)

	if err != nil {
		stdcli.Error(err)
		return
	}

	t := stdcli.NewTable("ID", "CREATED", "ACTIVE")

	for _, r := range *releases {
		active := ""
		if a.Parameters["Release"] == r.Id {
			active = "yes"
		}

		t.AddRow(r.Id, humanize.Time(r.Created), active)
	}

	t.Print()
}
Ejemplo n.º 3
0
Archivo: top.go Proyecto: 2opremio/cli
func cmdTop(c *cli.Context) {
	metrics := []string{"CPUUtilization", "MemoryUtilization"}
	labels := []string{"CPU", "MEM"}

	t := stdcli.NewTable("", "MIN", "AVG", "MAX", "UPDATED")

	for i := 0; i < len(metrics); i++ {
		dp, err := getMetrics(metrics[i])

		if err != nil {
			stdcli.Error(err)
			return
		}

		t.AddRow(labels[i], fmt.Sprintf("%.1f%%", dp.Minimum), fmt.Sprintf("%.1f%%", dp.Average), fmt.Sprintf("%.1f%%", dp.Maximum), humanize.Time(dp.Timestamp))
	}

	t.Print()
}
Ejemplo n.º 4
0
Archivo: apps.go Proyecto: 2opremio/cli
func cmdApps(c *cli.Context) {
	apps := getApps()

	longest := 3

	for _, app := range *apps {
		if len(app.Name) > longest {
			longest = len(app.Name)
		}
	}

	t := stdcli.NewTable("APP", "STATUS")

	for _, app := range *apps {
		t.AddRow(app.Name, app.Status)
	}

	t.Print()
}
Ejemplo n.º 5
0
func cmdScale(c *cli.Context) {
	_, app, err := stdcli.DirApp(c, ".")

	if err != nil {
		stdcli.Error(err)
		return
	}

	v := url.Values{}

	if c.IsSet("count") {
		v.Set("count", c.String("count"))
	}

	if c.IsSet("memory") {
		v.Set("mem", c.String("memory"))
	}

	if len(v) > 0 {
		v.Set("process", c.Args()[0])

		_, err = ConvoxPostForm("/apps/"+app, v)

		if err != nil {
			stdcli.Error(err)
			return
		}
	}

	data, err := ConvoxGet("/apps/" + app)

	if err != nil {
		stdcli.Error(err)
		return
	}

	var a *App
	err = json.Unmarshal(data, &a)

	if err != nil {
		stdcli.Error(err)
		return
	}

	processes := map[string]Process{}
	names := []string{}

	for k, v := range a.Parameters {
		if !strings.HasSuffix(k, "DesiredCount") {
			continue
		}

		ps := strings.Replace(k, "DesiredCount", "", 1)
		p := strings.ToLower(ps)

		i, err := strconv.ParseInt(v, 10, 64)

		if err != nil {
			stdcli.Error(err)
			return
		}

		m, err := strconv.ParseInt(a.Parameters[ps+"Memory"], 10, 64)

		if err != nil {
			stdcli.Error(err)
			return
		}

		processes[p] = Process{Name: p, Count: i, Memory: m}
		names = append(names, p)
	}

	sort.Strings(names)

	t := stdcli.NewTable("PROCESS", "COUNT", "MEM")

	for _, name := range names {
		ps := processes[name]
		t.AddRow(ps.Name, fmt.Sprintf("%d", ps.Count), fmt.Sprintf("%d", ps.Memory))
	}

	t.Print()
}