Example #1
0
func printHosts(lastApiResponse *healthd.ApiResponseHosts, status *healthdStatus) {
	goterm.Clear() // Clear current screen
	goterm.MoveCursor(1, 1)
	defer goterm.Flush()
	goterm.Println("Current Time:", status.FmtNow(), "   Status:", status.FmtStatus())

	//
	if lastApiResponse == nil {
		goterm.Println("no data yet")
		return
	}

	columns := []string{
		"Host:Port",
		"Status",
		"Last Checked",
		"Last Response Time",
	}

	for i, s := range columns {
		columns[i] = goterm.Bold(goterm.Color(s, goterm.BLACK))
	}

	table := goterm.NewTable(0, goterm.Width()-1, 5, ' ', 0)
	fmt.Fprintf(table, "%s\n", strings.Join(columns, "\t"))

	for _, host := range lastApiResponse.Hosts {
		printHost(table, host)
	}

	goterm.Println(table)
}
Example #2
0
func (appInfo AppInfo) Run(c CommandConfigs) (bool, string) {
	var resp *http.Response
	var bodyStr string
	resp = c.Run()
	defer resp.Body.Close()
	body, _ := ioutil.ReadAll(resp.Body)
	if resp.Status == "200 OK" {
		bodyStr = string(body)
		var errorFormat formats.ErrorFormat
		err := json.Unmarshal([]byte(bodyStr), &errorFormat)
		if err == nil {
			//<TODO> Make these error checking functionality common
			if errorFormat.ErrorCode == http.StatusUnauthorized {
				fmt.Println("Your session has expired.Please login and try again!")
			}
			println("has error")
		}
		var app formats.AppFormat
		err = json.Unmarshal([]byte(bodyStr), &app)
		if err == nil {
			fmt.Println("\nDetails of application are as follows.\n")
			totals := tm.NewTable(0, 10, 5, ' ', 0)
			fmt.Fprintf(totals, "Name\tKey\tType\tRepositoryType\tOwner\n")
			fmt.Fprintf(totals, "-------\t------\t-----\t---------\t----------------\n")
			fmt.Fprintf(totals, "%s\t%s\t%s\t%s\t%s\n", app.Name, app.Key, app.Type, app.RepositoryType, app.Owner)
			tm.Println(totals)
			tm.Flush()
		}

	}
	return true, c.Cookie
}
Example #3
0
/* Run calls the Run function of CommandConfigs and verifies the response from that call.*/
func (appInfo AppInfo) Run(configs CommandConfigs) (bool, string) {
	resp := configs.Run()
	//if request did not fail
	if resp != nil {
		defer resp.Body.Close()
	} else {
		//exit the cli
		return true, ""
	}
	body, _ := ioutil.ReadAll(resp.Body)
	if resp.StatusCode == http.StatusOK {
		bodyString := string(body)
		var errorFormat formats.ErrorFormat
		err := json.Unmarshal([]byte(bodyString), &errorFormat)
		if err == nil {
			if errorFormat.ErrorCode == http.StatusUnauthorized {
				fmt.Println("Your session has expired.Please login and try again!")
				return false, configs.Cookie
			}
		}
		var app formats.App
		err = json.Unmarshal([]byte(bodyString), &app)
		if err == nil {
			// Display application details in tabular format
			fmt.Println("\nDetails of application are as follows.\n")
			totals := tableManagement.NewTable(0, 10, 5, ' ', 0)
			fmt.Fprintf(totals, "Name\tKey\tType\tRepositoryType\tOwner\n")
			fmt.Fprintf(totals, "-------\t------\t-----\t---------\t----------------\n")
			fmt.Fprintf(totals, "%s\t%s\t%s\t%s\t%s\n", app.Name, app.Key, app.Type, app.RepositoryType, app.Owner)
			tableManagement.Println(totals)
			tableManagement.Flush()
		}
	}
	return true, configs.Cookie
}
Example #4
0
func (applist AppList) Run(c CommandConfigs) (bool, string) {
	var resp *http.Response
	var bodyStr string
	resp = c.Run()
	defer resp.Body.Close()
	body, _ := ioutil.ReadAll(resp.Body)
	if resp.Status == "200 OK" {
		bodyStr = string(body)
		var errorFormat formats.ErrorFormat
		err := json.Unmarshal([]byte(bodyStr), &errorFormat)
		if err == nil {
			//<TODO> Make these error checking functionality common
			if errorFormat.ErrorCode == http.StatusUnauthorized {
				fmt.Println("Your session has expired.Please login and try again!")
			}
		} else {
			var apps []formats.AppFormat
			err := json.Unmarshal([]byte(bodyStr), &apps)
			if err == nil {
				fmt.Println("You have ", len(apps), " applications. Details of applications are as follows.\n")
				totals := tm.NewTable(0, 10, 5, ' ', 0)
				fmt.Fprintf(totals, "Name\tKey\tType\tDescription\n")
				fmt.Fprintf(totals, "----\t---\t----\t-----------\n")
				for _, app := range apps {
					fmt.Fprintf(totals, "%s\t%s\t%s\t%s\n", app.Name, app.Key, app.Type, app.Description)
				}
				tm.Println(totals)
				tm.Flush()
			}

		}
	}
	return true, c.Cookie
}
Example #5
0
func printJobs(lastApiResponse *healthd.ApiResponseJobs, status *healthdStatus) {
	goterm.Clear() // Clear current screen
	goterm.MoveCursor(1, 1)
	defer goterm.Flush()
	goterm.Println("Current Time:", status.FmtNow(), "   Status:", status.FmtStatus())

	if lastApiResponse == nil {
		goterm.Println("no data yet")
		return
	}

	columns := []string{
		"Job",
		//		"Jobs/Second", //minute? flag?
		"Total Count",
		"Success",
		"ValidationError",
		"Panic",
		"Error",
		"Junk",
		"Avg Response Time",
		"Stddev",
		"Min",
		"Max",
		"Total",
	}

	for i, s := range columns {
		columns[i] = goterm.Bold(goterm.Color(s, goterm.BLACK))
	}

	table := goterm.NewTable(0, goterm.Width()-1, 5, ' ', 0)
	fmt.Fprintf(table, "%s\n", strings.Join(columns, "\t"))

	for _, job := range lastApiResponse.Jobs {
		printJob(table, job)
	}

	goterm.Println(table)
}
Example #6
0
func alertsCmd(cmd *cobra.Command, args []string) {
	createClient()

	params := wavefront.QueryParams{}

	if customerTag != "" {
		params["customerTag"] = customerTag
	}

	if userTag != "" {
		params["userTag"] = userTag
	}

	// parse the args to ascertain which function to use
	var f func(*wavefront.QueryParams) ([]*wavefront.Alert, error)
	if len(args) == 0 || args[0] == "all" {
		f = client.Alerts.All
	} else {
		switch args[0] {
		case "all":
			f = client.Alerts.All
		case "snoozed":
			f = client.Alerts.Snoozed
		case "firing":
			f = client.Alerts.Active
		case "invalid":
			f = client.Alerts.Invalid
		case "affected_by_maintenance":
			f = client.Alerts.AffectedByMaintenance
		default:
			log.Fatal("Please provide a valid alert type.")
		}
	}

	alerts, err := f(&params)
	if err != nil {
		log.Fatal(err)
	}

	if rawResponse == true {
		prettyPrint(&client.Alerts.RawResponse)
	} else {

		table := goterm.NewTable(0, 10, 5, ' ', 0)
		fmt.Fprintf(table, "Name\tSeverity\n")
		for _, a := range alerts {
			fmt.Fprintf(table, "%s\t%s\n", a.Name, a.Severity)
		}
		goterm.Println(table)
		goterm.Flush()
	}
}
Example #7
0
func main() {
	tm.Clear() // Clear current screen
	started := 100
	finished := 250

	// Based on http://golang.org/pkg/text/tabwriter
	totals := tm.NewTable(0, 10, 5, ' ', 0)
	fmt.Fprintf(totals, "Time\tStarted\tActive\tFinished\n")
	fmt.Fprintf(totals, "%s\t%d\t%d\t%d\n", "All", started, started-finished, finished)
	tm.Println(totals)

	tm.Flush()
}
Example #8
0
func ToolHelp(factory command.CommandFactory) {
	fmt.Println("\n" + Bold("NAME") + " : appfac\n")
	fmt.Println(Bold("USAGE") + " : CLI Tool for WSO2 Appfactory\n")
	fmt.Println(Bold("VERSION") + " : 1.0.0\n")
	fmt.Println(Bold("COMMANDS") + " :\n")

	commands := tablemanagement.NewTable(0, 10, 5, ' ', 0)
	fmt.Fprintf(commands, "%s\t%s\t%s\n", "help", "h", "Shows help for appfac CLI tool")
	for _, command := range factory.CmdsByName {
		metadata := command.Metadata()
		fmt.Fprintf(commands, "%s\t%s\t%s\n", metadata.Name, metadata.ShortName, metadata.Description)
	}
	fmt.Fprintf(commands, "%s\t%s\t%s\n", command.SetBaseUrlCommand, command.SetBaseUrlCommand, "Sets base url for the tool")
	tablemanagement.Println(commands)
	tablemanagement.Flush()
}
Example #9
0
func main() {
	tm.Clear()
	tm.MoveCursor(0, 0)

	chart := tm.NewLineChart(100, 20)
	data := new(tm.DataTable)
	data.AddColumn("Time")
	data.AddColumn("Sin(x)")
	data.AddColumn("Cos(x+1)")

	for i := 0.1; i < 10; i += 0.1 {
		data.AddRow(i, math.Sin(i), math.Cos(i+1))
	}

	tm.Println(chart.Draw(data))
	tm.Flush()
}
Example #10
0
func HelpTemplate(metadata command.CommandMetadata) {
	commandHelp := tablemanagement.NewTable(0, 10, 5, ' ', 0)
	fmt.Fprintf(commandHelp, "%s\t%s\n", Bold("COMMAND"), metadata.Name)
	fmt.Fprintf(commandHelp, "%s\t%s\n", Bold("SHORTNAME"), metadata.ShortName)
	fmt.Fprintf(commandHelp, "%s\t%s\n", Bold("USAGE"), metadata.Usage)
	fmt.Fprintf(commandHelp, "%s\n", Bold("FLAGS"))
	for n := 0; n < len(metadata.Flags); n++ {
		if flag, ok := metadata.Flags[n].(cli.StringFlag); ok {
			if flag.Name != "-u" && flag.Name != "-c" {
				fmt.Fprintf(commandHelp, "\t%s\t%s\n", flag.Name, flag.Usage)
			}
		}
	}
	tablemanagement.Println(commandHelp)
	tablemanagement.Flush()

}
Example #11
0
/* Run calls the Run function of CommandConfigs and verifies the response from that call.*/
func (versionsList VersionsList) Run(configs CommandConfigs) (bool, string) {
	resp := configs.Run()
	//if request did not fail
	if resp != nil {
		defer resp.Body.Close()
	} else {
		//exit the cli
		return true, ""
	}
	body, _ := ioutil.ReadAll(resp.Body)

	if resp.StatusCode == http.StatusOK {
		bodyString := string(body)
		var errorFormat formats.ErrorFormat
		err := json.Unmarshal([]byte(bodyString), &errorFormat)
		if err == nil {
			if errorFormat.ErrorCode == http.StatusUnauthorized {
				fmt.Println("Your session has expired.Please login and try again!")
				return false, configs.Cookie
			}
		} else {
			var appVersions []formats.AppVersion
			err := json.Unmarshal([]byte(bodyString), &appVersions)
			if err == nil {
				fmt.Println("\nApplication has ", len(appVersions[0].Versions), " versions. Details of versions are as follows.\n")
				for _, appVersion := range appVersions {
					versions := appVersion.Versions
					totals := tm.NewTable(0, 10, 5, ' ', 0)
					fmt.Fprintf(totals, "Version\tAutoDeploy\tStage\tRepoURL\n")
					fmt.Fprintf(totals, "-------\t---------\t-----\t-----------\n")

					for _, version := range versions {
						fmt.Fprintf(totals, "%s\t%s\t%s\t%s\n", version.Version, version.AutoDeployment, version.Stage, version.RepoURL)
					}
					tm.Println(totals)
					tm.Flush()
				}
			}
		}
	}
	return true, configs.Cookie
}
Example #12
0
func (versionsList VersionsList) Run(c CommandConfigs) (bool, string) {
	var resp *http.Response
	var bodyStr string
	resp = c.Run()
	defer resp.Body.Close()
	body, _ := ioutil.ReadAll(resp.Body)

	if resp.Status == "200 OK" {

		bodyStr = string(body)
		var errorFormat formats.ErrorFormat
		err := json.Unmarshal([]byte(bodyStr), &errorFormat)

		if err == nil {
			//<TODO> Make these error checking functionality common
			if errorFormat.ErrorCode == http.StatusUnauthorized {
				fmt.Println("Your session has expired.Please login and try again!")
			}
		} else {
			var appVersions []formats.AppVersionFormat
			err := json.Unmarshal([]byte(bodyStr), &appVersions)
			if err == nil {
				fmt.Println("Application has ", len(appVersions[0].Versions), " versions. Details of versions are as follows.\n")
				for _, appVersion := range appVersions {
					versions := appVersion.Versions
					totals := tm.NewTable(0, 10, 5, ' ', 0)
					fmt.Fprintf(totals, "Version\tAutoDeploy\tStage\tRepoURL\n")
					fmt.Fprintf(totals, "-------\t---------\t-----\t-----------\n")

					for _, version := range versions {
						fmt.Fprintf(totals, "%s\t%s\t%s\t%s\n", version.Version, version.AutoDeployment, version.Stage, version.RepoURL)
					}
					tm.Println(totals)
					tm.Flush()
				}
			}

		}
	}
	return true, c.Cookie
}
Example #13
0
/* Run calls the Run function of CommandConfigs and verifies the response from that call.*/
func (applist AppList) Run(configs CommandConfigs) (bool, string) {
	resp := configs.Run()
	//if request did not fail
	if resp != nil {
		defer resp.Body.Close()
	} else {
		//exit the cli
		return true, ""
	}
	body, _ := ioutil.ReadAll(resp.Body)
	if resp.StatusCode == http.StatusOK {
		bodyString := string(body)
		var errorFormat formats.ErrorFormat
		err := json.Unmarshal([]byte(bodyString), &errorFormat)
		if err == nil {
			if errorFormat.ErrorCode == http.StatusUnauthorized {
				fmt.Println(errorFormat.ErrorMessage)
				fmt.Println("Your session has expired.Please login and try again!")
				return false, configs.Cookie
			}
		} else {
			var apps []formats.App
			err := json.Unmarshal([]byte(bodyString), &apps)
			if err == nil {
				fmt.Println("\nYou have ", len(apps), " applications. Details of applications are as follows.\n")
				totals := tm.NewTable(0, 10, 5, ' ', 0)
				fmt.Fprintf(totals, "Name\tKey\tType\n")
				fmt.Fprintf(totals, "-------\t------\t-----\n")
				for _, app := range apps {
					fmt.Fprintf(totals, "%s\t%s\t%s\n", app.Name, app.Key, app.Type)
				}
				tm.Println(totals)
				tm.Flush()
			}
		}
	}
	return true, configs.Cookie
}
Example #14
0
func StatQueue(writeQ bool) error {

	var myresults results
	var wg sync.WaitGroup
	for id, sl := range record.RecordByThread {
		wg.Add(1)
		go func(tid string, rs []*record.Record) {

			defer wg.Done()

			for _, r := range rs {

				if !window.InCurrentWindow(r.Time) {
					continue
				}

				if len(r.Raw) < 151 {
					continue
				}
				txt := strings.Split(r.Raw[60:150], ">")
				if len(txt) < 2 {
					continue
				}
				tokens := strings.Split(txt[1], " ") // 60:140 to limit the scope of search, with reasonable margins
				if len(tokens) < 3 {
					continue
				}

				if writeQ {
					if ((tokens[1] == "Queue") && (tokens[2] == "command")) ||
						((tokens[1] == "Dequeue") && (tokens[2] == "and") && (tokens[3] == "execute")) {
						//2015/08/04 15:19:59.904847 magap302 masterag-11298 MDW INFO <SEI_MAAdminSequence.cpp#223 TID#13> Queue command 0x2aacbf979400 [Command#14015: kSEIBELibLoaded : BE->MAG:Notify the Master Agent that a lib has been loaded (version 1)^@] (from BENT0UCL4VXODY to masterag); Command sequence queue size: 0
						backToken := strings.Split(r.Raw[len(r.Raw)-40:len(r.Raw)], " ")
						last := len(backToken) - 1
						txt1 := strings.Join(backToken[last-2:last], " ")
						if txt1 == "queue size:" {
							if s, err := strconv.Atoi(backToken[last]); err == nil {
								myresults.Lock()
								myresults.HasRecords = append(myresults.HasRecords, &result{qSize: s, tid: tid, r: r})
								myresults.Unlock()
							}
						}
					}
				} else {
					if (tokens[1] == "Scheduling") && (tokens[3] == "command") && (tokens[6] == "Read-only") {
						//2015/12/03 05:07:12.577382 magap302 masterag-32357 MDW INFO <SEI_MAAdminSequence.cpp#196 TID#13> Scheduling the command in the Read-only command sequencer pool. Pool queue size: 393
						backToken := strings.Split(r.Raw[len(r.Raw)-40:len(r.Raw)], " ")
						last := len(backToken) - 1
						txt1 := strings.Join(backToken[last-2:last], " ")
						if txt1 == "queue size:" {
							if s, err := strconv.Atoi(backToken[last]); err == nil {
								myresults.Lock()
								myresults.HasRecords = append(myresults.HasRecords, &result{qSize: s, tid: tid, r: r})
								myresults.Unlock()
							}
						}
					}
				}
			}
		}(id, sl)
	}

	wg.Wait()
	sort.Sort(record.ByHasRecordTime{myresults.HasRecords})

	// Build chart
	chart := tm.NewLineChart(tm.Width()-10, tm.Height()-10)

	data := new(tm.DataTable)
	data.AddColumn("Seconds")
	data.AddColumn("QMax")
	data.AddColumn("QMin")

	type prec struct {
		max int
		min int
	}

	t0 := myresults.HasRecords[0].(*result).r.Time
	tmax := myresults.HasRecords[len(myresults.HasRecords)-1].(*result).r.Time
	indexMax := int(tmax.Sub(t0).Seconds())

	qmaxTime := time.Unix(0, 0)
	qmax := 0

	m := make(map[int]prec)
	for _, v := range myresults.HasRecords {
		r := v.(*result)
		d := int(r.r.Time.Sub(t0).Seconds())
		p, ok := m[d]
		if !ok {
			p = prec{r.qSize, r.qSize}
		} else {
			if p.max < r.qSize {
				p.max = r.qSize
			}
			if p.min > r.qSize {
				p.min = r.qSize
			}
		}
		m[d] = p

		if p.max > qmax {
			qmax = p.max
			qmaxTime = r.GetRecord().Time
		}
	}

	for t := 0; t <= int(indexMax); t++ {
		data.AddRow(float64(t), float64(m[t].max), float64(m[t].min))
	}

	tm.Println(chart.Draw(data))
	tm.Flush()

	fmt.Printf("Qmax=%d  at %s\n", qmax, qmaxTime.Format(utils.DateFormat))

	return nil
}
Example #15
0
//Display the distribution for a given command
func StatCmdDistribution(cmdName string) {

	for _, ss := range buildStats() {
		if ss.cmd == cmdName {
			// Build chart
			chart := tm.NewLineChart(tm.Width()-10, tm.Height()-33)

			data := new(tm.DataTable)
			data.AddColumn("CmdCount")
			data.AddColumn("Duration")

			for i, rec := range ss.records {
				if d, err := rec.GetCmdDuration(); err != nil {
					data.AddRow(float64(i), -1.)
				} else {
					data.AddRow(float64(i), float64(d.Nanoseconds()/1000000))
				}
			}

			tm.Println(chart.Draw(data))
			tm.Flush()

			// Statistics for that particular command
			{
				w := new(tabwriter.Writer)
				w.Init(os.Stdout, 20, 0, 2, ' ', tabwriter.AlignRight)

				fmt.Fprintln(w, "Command\tcount\tmiss\tmin (ms)\tmax (ms)\tavg (ms)\t95% (ms)\t")
				c := int64(len(ss.records) - ss.incomplete)
				i95 := c * 95 / 100

				if c == 0 {
					c = 1
				}
				percentile95 := int64(-1)
				if d95, err := ss.records[i95].GetCmdDuration(); err == nil {
					percentile95 = d95.Nanoseconds()
				}

				fmt.Fprintf(w, "%s\t%d\t%d\t%d\t%d\t%d\t%d\t\n", ss.cmd, len(ss.records), ss.incomplete, ss.min.Nanoseconds()/1000000, ss.max.Nanoseconds()/1000000, ss.sum.Nanoseconds()/1000000/c, percentile95/1000000)

				fmt.Fprintln(w)
				w.Flush()

			}
			// The 10 slowest occurence
			{
				w := new(tabwriter.Writer)
				w.Init(os.Stdout, 5, 0, 2, ' ', tabwriter.TabIndent)
				fmt.Fprintln(w, "Duration(ms)\tcmd\t")

				min := 10
				if len(ss.records) < 10 {
					min = len(ss.records)
				}
				for i := 1; i <= min; i++ {
					rec := ss.records[len(ss.records)-i]
					if d, err := rec.GetCmdDuration(); err != nil {
						fmt.Fprintf(w, "-\t%s\t\n", rec.Raw)
					} else {
						fmt.Fprintf(w, "%d\t%s\t\n", d.Nanoseconds()/1000000, rec.Raw)
					}

				}

				fmt.Fprintln(w)
				w.Flush()
			}
			return
		}
	}

}