metrics

package
v2.0.0-snapshot...-58e3a78 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2017 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CPUSubCmd = models.Command{
	Name:      "cpu",
	ShortHelp: "Print service and environment CPU metrics in your local time zone",
	LongHelp: "`metrics cpu` prints out CPU metrics for your environment or individual services. " +
		"You can print out metrics in csv, json, plain text, or spark lines format. " +
		"If you want plain text format, simply omit the `--json`, `--csv`, and `--spark` flags. " +
		"You can only stream metrics using plain text or spark lines formats. " +
		"To print out metrics for every service in your environment, omit the `SERVICE_NAME` argument. " +
		"Otherwise you may choose a service, such as an app service, to retrieve metrics for. " +
		"Here are some sample commands\n\n" +
		"```\ncatalyze -E \"<your_env_alias>\" metrics cpu\n" +
		"catalyze -E \"<your_env_alias>\" metrics cpu app01 --stream\n" +
		"catalyze -E \"<your_env_alias>\" metrics cpu --json\n" +
		"catalyze -E \"<your_env_alias>\" metrics cpu db01 --csv -m 60\n```",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(subCmd *cli.Cmd) {
			serviceName := subCmd.StringArg("SERVICE_NAME", "", "The name of the service to print metrics for")
			json := subCmd.BoolOpt("json", false, "Output the data as json")
			csv := subCmd.BoolOpt("csv", false, "Output the data as csv")
			text := subCmd.BoolOpt("text", true, "Output the data in plain text")
			spark := subCmd.BoolOpt("spark", false, "Output the data using spark lines")
			stream := subCmd.BoolOpt("stream", false, "Repeat calls once per minute until this process is interrupted.")
			mins := subCmd.IntOpt("m mins", 1, "How many minutes worth of metrics to retrieve.")
			subCmd.Action = func() {
				if _, err := auth.New(settings, prompts.New()).Signin(); err != nil {
					logrus.Fatal(err.Error())
				}
				if err := config.CheckRequiredAssociation(true, true, settings); err != nil {
					logrus.Fatal(err.Error())
				}
				err := CmdMetrics(*serviceName, CPU, *json, *csv, *text, *spark, *stream, *mins, New(settings), services.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			subCmd.Spec = "[SERVICE_NAME] [(--json | --csv | --text | --spark)] [--stream] [-m]"
		}
	},
}
View Source
var Cmd = models.Command{
	Name:      "metrics",
	ShortHelp: "Print service and environment metrics in your local time zone",
	LongHelp: "The `metrics` command gives access to environment metrics or individual service metrics through a variety of formats. " +
		"This is useful for checking on the status and performance of your application or environment as a whole. " +
		"The metrics command cannot be run directly but has sub commands.",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(cmd *cli.Cmd) {
			cmd.CommandLong(CPUSubCmd.Name, CPUSubCmd.ShortHelp, CPUSubCmd.LongHelp, CPUSubCmd.CmdFunc(settings))
			cmd.CommandLong(MemorySubCmd.Name, MemorySubCmd.ShortHelp, MemorySubCmd.LongHelp, MemorySubCmd.CmdFunc(settings))
			cmd.CommandLong(NetworkInSubCmd.Name, NetworkInSubCmd.ShortHelp, NetworkInSubCmd.LongHelp, NetworkInSubCmd.CmdFunc(settings))
			cmd.CommandLong(NetworkOutSubCmd.Name, NetworkOutSubCmd.ShortHelp, NetworkOutSubCmd.LongHelp, NetworkOutSubCmd.CmdFunc(settings))
		}
	},
}

Cmd is the contract between the user and the CLI. This specifies the command name, arguments, and required/optional arguments and flags for the command.

View Source
var MemorySubCmd = models.Command{
	Name:      "memory",
	ShortHelp: "Print service and environment memory metrics in your local time zone",
	LongHelp: "`metrics memory` prints out memory metrics for your environment or individual services. " +
		"You can print out metrics in csv, json, plain text, or spark lines format. " +
		"If you want plain text format, simply omit the `--json`, `--csv`, and `--spark` flags. " +
		"You can only stream metrics using plain text or spark lines formats. " +
		"To print out metrics for every service in your environment, omit the `SERVICE_NAME` argument. " +
		"Otherwise you may choose a service, such as an app service, to retrieve metrics for. " +
		"Here are some sample commands\n\n" +
		"```\ncatalyze -E \"<your_env_alias>\" metrics memory\n" +
		"catalyze -E \"<your_env_alias>\" metrics memory app01 --stream\n" +
		"catalyze -E \"<your_env_alias>\" metrics memory --json\n" +
		"catalyze -E \"<your_env_alias>\" metrics memory db01 --csv -m 60\n```",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(subCmd *cli.Cmd) {
			serviceName := subCmd.StringArg("SERVICE_NAME", "", "The name of the service to print metrics for")
			json := subCmd.BoolOpt("json", false, "Output the data as json")
			csv := subCmd.BoolOpt("csv", false, "Output the data as csv")
			text := subCmd.BoolOpt("text", true, "Output the data in plain text")
			spark := subCmd.BoolOpt("spark", false, "Output the data using spark lines")
			stream := subCmd.BoolOpt("stream", false, "Repeat calls once per minute until this process is interrupted.")
			mins := subCmd.IntOpt("m mins", 1, "How many minutes worth of metrics to retrieve.")
			subCmd.Action = func() {
				if _, err := auth.New(settings, prompts.New()).Signin(); err != nil {
					logrus.Fatal(err.Error())
				}
				if err := config.CheckRequiredAssociation(true, true, settings); err != nil {
					logrus.Fatal(err.Error())
				}
				err := CmdMetrics(*serviceName, Memory, *json, *csv, *text, *spark, *stream, *mins, New(settings), services.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			subCmd.Spec = "[SERVICE_NAME] [(--json | --csv | --text | --spark)] [--stream] [-m]"
		}
	},
}
View Source
var NetworkInSubCmd = models.Command{
	Name:      "network-in",
	ShortHelp: "Print service and environment received network data metrics in your local time zone",
	LongHelp: "`metrics network-in` prints out received network metrics for your environment or individual services. " +
		"You can print out metrics in csv, json, plain text, or spark lines format. " +
		"If you want plain text format, simply omit the `--json`, `--csv`, and `--spark` flags. " +
		"You can only stream metrics using plain text or spark lines formats. " +
		"To print out metrics for every service in your environment, omit the `SERVICE_NAME` argument. " +
		"Otherwise you may choose a service, such as an app service, to retrieve metrics for. Here are some sample commands\n\n" +
		"```\ncatalyze -E \"<your_env_alias>\" metrics network-in\n" +
		"catalyze -E \"<your_env_alias>\" metrics network-in app01 --stream\n" +
		"catalyze -E \"<your_env_alias>\" metrics network-in --json\n" +
		"catalyze -E \"<your_env_alias>\" metrics network-in db01 --csv -m 60\n```",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(subCmd *cli.Cmd) {
			serviceName := subCmd.StringArg("SERVICE_NAME", "", "The name of the service to print metrics for")
			json := subCmd.BoolOpt("json", false, "Output the data as json")
			csv := subCmd.BoolOpt("csv", false, "Output the data as csv")
			text := subCmd.BoolOpt("text", true, "Output the data in plain text")
			spark := subCmd.BoolOpt("spark", false, "Output the data using spark lines")
			stream := subCmd.BoolOpt("stream", false, "Repeat calls once per minute until this process is interrupted.")
			mins := subCmd.IntOpt("m mins", 1, "How many minutes worth of metrics to retrieve.")
			subCmd.Action = func() {
				if _, err := auth.New(settings, prompts.New()).Signin(); err != nil {
					logrus.Fatal(err.Error())
				}
				if err := config.CheckRequiredAssociation(true, true, settings); err != nil {
					logrus.Fatal(err.Error())
				}
				err := CmdMetrics(*serviceName, NetworkIn, *json, *csv, *text, *spark, *stream, *mins, New(settings), services.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			subCmd.Spec = "[SERVICE_NAME] [(--json | --csv | --text | --spark)] [--stream] [-m]"
		}
	},
}
View Source
var NetworkOutSubCmd = models.Command{
	Name:      "network-out",
	ShortHelp: "Print service and environment transmitted network data metrics in your local time zone",
	LongHelp: "`metrics network-out` prints out transmitted network metrics for your environment or individual services. " +
		"You can print out metrics in csv, json, plain text, or spark lines format. " +
		"If you want plain text format, simply omit the `--json`, `--csv`, and `--spark` flags. " +
		"You can only stream metrics using plain text or spark lines formats. " +
		"To print out metrics for every service in your environment, omit the `SERVICE_NAME` argument. " +
		"Otherwise you may choose a service, such as an app service, to retrieve metrics for. " +
		"Here are some sample commands\n\n" +
		"```\ncatalyze -E \"<your_env_alias>\" metrics network-out\n" +
		"catalyze -E \"<your_env_alias>\" metrics network-out app01 --stream\n" +
		"catalyze -E \"<your_env_alias>\" metrics network-out --json\n" +
		"catalyze -E \"<your_env_alias>\" metrics network-out db01 --csv -m 60\n```",
	CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) {
		return func(subCmd *cli.Cmd) {
			serviceName := subCmd.StringArg("SERVICE_NAME", "", "The name of the service to print metrics for")
			json := subCmd.BoolOpt("json", false, "Output the data as json")
			csv := subCmd.BoolOpt("csv", false, "Output the data as csv")
			text := subCmd.BoolOpt("text", true, "Output the data in plain text")
			spark := subCmd.BoolOpt("spark", false, "Output the data using spark lines")
			stream := subCmd.BoolOpt("stream", false, "Repeat calls once per minute until this process is interrupted.")
			mins := subCmd.IntOpt("m mins", 1, "How many minutes worth of metrics to retrieve.")
			subCmd.Action = func() {
				if _, err := auth.New(settings, prompts.New()).Signin(); err != nil {
					logrus.Fatal(err.Error())
				}
				if err := config.CheckRequiredAssociation(true, true, settings); err != nil {
					logrus.Fatal(err.Error())
				}
				err := CmdMetrics(*serviceName, NetworkOut, *json, *csv, *text, *spark, *stream, *mins, New(settings), services.New(settings))
				if err != nil {
					logrus.Fatal(err.Error())
				}
			}
			subCmd.Spec = "[SERVICE_NAME] [(--json | --csv | --text | --spark)] [--stream] [-m]"
		}
	},
}

Functions

func CmdEnvironmentMetrics

func CmdEnvironmentMetrics(metricType MetricType, stream, sparkLines bool, mins int, t Transformer, im IMetrics) error

func CmdMetrics

func CmdMetrics(svcName string, metricType MetricType, jsonFlag, csvFlag, textFlag, sparkFlag, streamFlag bool, mins int, im IMetrics, is services.IServices) error

CmdMetrics prints out metrics for a given service or if the service is not specified, metrics for the entire environment are printed.

func CmdServiceMetrics

func CmdServiceMetrics(metricType MetricType, stream, sparkLines bool, mins int, service *models.Service, t Transformer, im IMetrics) error

Types

type CSVTransformer

type CSVTransformer struct {
	HeadersWritten bool
	GroupMode      bool
	Buffer         *bytes.Buffer
	Writer         *csv.Writer
}

CSVTransformer is a concrete implementation of Transformer transforming data into CSV format.

func (*CSVTransformer) TransformGroupCPU

func (csv *CSVTransformer) TransformGroupCPU(metrics *[]models.Metrics)

TransformGroupCPU transforms an entire environment's cpu data into csv format. This outputs TransformSingleCPU for each service in the environment.

func (*CSVTransformer) TransformGroupMemory

func (csv *CSVTransformer) TransformGroupMemory(metrics *[]models.Metrics)

TransformGroupMemory transforms an entire environment's memory data into csv format. This outputs TransformSingleMemory for each service in the environment.

func (*CSVTransformer) TransformGroupNetworkIn

func (csv *CSVTransformer) TransformGroupNetworkIn(metrics *[]models.Metrics)

TransformGroupNetworkIn transforms an entire environment's received network data into csv format. This outputs TransformSingleNetworkIn for each service in the environment.

func (*CSVTransformer) TransformGroupNetworkOut

func (csv *CSVTransformer) TransformGroupNetworkOut(metrics *[]models.Metrics)

TransformGroupNetworkOut transforms an entire environment's transmitted network data into csv format. This outputs TransformSingleNetworkOut for each service in the environment.

func (*CSVTransformer) TransformSingleCPU

func (csv *CSVTransformer) TransformSingleCPU(metric *models.Metrics)

TransformSingleCPU transforms a single service's CPU data into csv format.

func (*CSVTransformer) TransformSingleMemory

func (csv *CSVTransformer) TransformSingleMemory(metric *models.Metrics)

TransformSingleMemory transforms a single service's memory data into csv format.

func (*CSVTransformer) TransformSingleNetworkIn

func (csv *CSVTransformer) TransformSingleNetworkIn(metric *models.Metrics)

TransformSingleNetworkIn transforms a single service's received network data into csv format.

func (*CSVTransformer) TransformSingleNetworkOut

func (csv *CSVTransformer) TransformSingleNetworkOut(metric *models.Metrics)

TransformSingleNetworkOut transforms a single service's transmitted network data into csv format.

func (*CSVTransformer) WriteHeadersCPU

func (csv *CSVTransformer) WriteHeadersCPU()

WriteHeadersCPU outputs the csv headers needed for cpu data. If GroupMode is enabled, the service name is the first header.

func (*CSVTransformer) WriteHeadersMemory

func (csv *CSVTransformer) WriteHeadersMemory()

WriteHeadersMemory outputs the csv headers needed for memory data. If GroupMode is enabled, the service name is the first header.

func (*CSVTransformer) WriteHeadersNetworkIn

func (csv *CSVTransformer) WriteHeadersNetworkIn()

WriteHeadersNetworkIn outputs the csv headers needed for received network data. If GroupMode is enabled, the service name is the first header.

func (*CSVTransformer) WriteHeadersNetworkOut

func (csv *CSVTransformer) WriteHeadersNetworkOut()

WriteHeadersNetworkOut outputs the csv headers needed for transmitted network data. If GroupMode is enabled, the service name is the first header.

type IMetrics

type IMetrics interface {
	RetrieveEnvironmentMetrics(mins int) (*[]models.Metrics, error)
	RetrieveServiceMetrics(mins int, svcID string) (*models.Metrics, error)
}

IMetrics

func New

func New(settings *models.Settings) IMetrics

New returns an instance of IMetrics

type JSONTransformer

type JSONTransformer struct{}

JSONTransformer is a concrete implementation of Transformer transforming data into pretty printed JSON format.

func (*JSONTransformer) TransformGroupCPU

func (j *JSONTransformer) TransformGroupCPU(metrics *[]models.Metrics)

TransformGroupCPU transforms an entire environment's cpu data into json format. This outputs TransformSingleCPU for every service in the environment.

func (*JSONTransformer) TransformGroupMemory

func (j *JSONTransformer) TransformGroupMemory(metrics *[]models.Metrics)

TransformGroupMemory transforms an entire environment's memory data into json format. This outputs TransformSingleMemory for every service in the environment.

func (*JSONTransformer) TransformGroupNetworkIn

func (j *JSONTransformer) TransformGroupNetworkIn(metrics *[]models.Metrics)

TransformGroupNetworkIn transforms an entire environment's received network data into json format. This outputs TransformSingleNetworkIn for every service in the environment.

func (*JSONTransformer) TransformGroupNetworkOut

func (j *JSONTransformer) TransformGroupNetworkOut(metrics *[]models.Metrics)

TransformGroupNetworkOut transforms an entire environment's transmitted network data into json format. This outputs TransformSingleNetworkOut for every service in the environment.

func (*JSONTransformer) TransformSingleCPU

func (j *JSONTransformer) TransformSingleCPU(metric *models.Metrics)

TransformSingleCPU transforms a single service's cpu data into json format.

func (*JSONTransformer) TransformSingleMemory

func (j *JSONTransformer) TransformSingleMemory(metric *models.Metrics)

TransformSingleMemory transforms a single service's memory data into json format.

func (*JSONTransformer) TransformSingleNetworkIn

func (j *JSONTransformer) TransformSingleNetworkIn(metric *models.Metrics)

TransformSingleNetworkIn transforms a single service's received network data into json format.

func (*JSONTransformer) TransformSingleNetworkOut

func (j *JSONTransformer) TransformSingleNetworkOut(metric *models.Metrics)

TransformSingleNetworkOut transforms a single service's transmitted network data into json format.

type MetricType

type MetricType uint8
const (
	CPU MetricType = iota
	Memory
	NetworkIn
	NetworkOut
)

type SMetrics

type SMetrics struct {
	Settings *models.Settings
}

SMetrics is a concrete implementation of IMetrics

func (*SMetrics) RetrieveEnvironmentMetrics

func (m *SMetrics) RetrieveEnvironmentMetrics(mins int) (*[]models.Metrics, error)

RetrieveEnvironmentMetrics retrieves metrics data for all services in the associated environment.

func (*SMetrics) RetrieveServiceMetrics

func (m *SMetrics) RetrieveServiceMetrics(mins int, svcID string) (*models.Metrics, error)

RetrieveServiceMetrics retrieves metrics data for the given service.

type SparkTransformer

type SparkTransformer struct {
	SparkLines map[string]*ui.Sparklines
}

SparkTransformer is a concrete implementation of Transformer transforming data into spark lines.

func (*SparkTransformer) TransformGroupCPU

func (spark *SparkTransformer) TransformGroupCPU(metrics *[]models.Metrics)

TransformGroupCPU transforms an entire environment's cpu data into spark lines. This outputs TransformSingleCPU for every service in the environment.

func (*SparkTransformer) TransformGroupMemory

func (spark *SparkTransformer) TransformGroupMemory(metrics *[]models.Metrics)

TransformGroupMemory transforms an entire environment's memory data into spark lines. This outputs TransformSingleMemory for every service in the environment.

func (*SparkTransformer) TransformGroupNetworkIn

func (spark *SparkTransformer) TransformGroupNetworkIn(metrics *[]models.Metrics)

TransformGroupNetworkIn transforms an entire environment's received network data into spark lines. This outputs TransformSingleNetworkIn for every service in the environment.

func (*SparkTransformer) TransformGroupNetworkOut

func (spark *SparkTransformer) TransformGroupNetworkOut(metrics *[]models.Metrics)

TransformGroupNetworkOut transforms an entire environment's transmitted network data into spark lines. This outputs TransformSingleNetworkOut for every service in the environment.

func (*SparkTransformer) TransformSingleCPU

func (spark *SparkTransformer) TransformSingleCPU(metric *models.Metrics)

TransformSingleCPU transforms a single service's cpu data into spark lines.

func (*SparkTransformer) TransformSingleMemory

func (spark *SparkTransformer) TransformSingleMemory(metric *models.Metrics)

TransformSingleMemory transforms a single service's memory data into spark lines.

func (*SparkTransformer) TransformSingleNetworkIn

func (spark *SparkTransformer) TransformSingleNetworkIn(metric *models.Metrics)

TransformSingleNetworkIn transforms a single service's received network data into spark lines.

func (*SparkTransformer) TransformSingleNetworkOut

func (spark *SparkTransformer) TransformSingleNetworkOut(metric *models.Metrics)

TransformSingleNetworkOut transforms a single service's transmitted network data into spark lines.

type TextTransformer

type TextTransformer struct{}

TextTransformer is a concrete implementation of Transformer transforming data into plain text.

func (*TextTransformer) TransformGroupCPU

func (text *TextTransformer) TransformGroupCPU(metrics *[]models.Metrics)

TransformGroupCPU transforms an entire environment's cpu data into text format. This outputs TransformSingleCPU for every service in the environment.

func (*TextTransformer) TransformGroupMemory

func (text *TextTransformer) TransformGroupMemory(metrics *[]models.Metrics)

TransformGroupMemory transforms an entire environment's memory data into text format. This outputs TransformSingleMemory for every service in the environment.

func (*TextTransformer) TransformGroupNetworkIn

func (text *TextTransformer) TransformGroupNetworkIn(metrics *[]models.Metrics)

TransformGroupNetworkIn transforms an entire environment's received network data into text format. This outputs TransformSingleNetworkIn for every service in the environment.

func (*TextTransformer) TransformGroupNetworkOut

func (text *TextTransformer) TransformGroupNetworkOut(metrics *[]models.Metrics)

TransformGroupNetworkOut transforms an entire environment's transmitted network data into text format. This outputs TransformSingleNetworkOut for every service in the environment.

func (*TextTransformer) TransformSingleCPU

func (text *TextTransformer) TransformSingleCPU(metric *models.Metrics)

TransformSingleCPU transforms a single service's cpu data into text format.

func (*TextTransformer) TransformSingleMemory

func (text *TextTransformer) TransformSingleMemory(metric *models.Metrics)

TransformSingleMemory transforms a single service's memory data into text format.

func (*TextTransformer) TransformSingleNetworkIn

func (text *TextTransformer) TransformSingleNetworkIn(metric *models.Metrics)

TransformSingleNetworkIn transforms a single service's received network data into text format.

func (*TextTransformer) TransformSingleNetworkOut

func (text *TextTransformer) TransformSingleNetworkOut(metric *models.Metrics)

TransformSingleNetworkOut transforms a single service's transmitted network data into text format.

type Transformer

type Transformer interface {
	TransformGroupCPU(*[]models.Metrics)
	TransformGroupMemory(*[]models.Metrics)
	TransformGroupNetworkIn(*[]models.Metrics)
	TransformGroupNetworkOut(*[]models.Metrics)
	TransformSingleCPU(*models.Metrics)
	TransformSingleMemory(*models.Metrics)
	TransformSingleNetworkIn(*models.Metrics)
	TransformSingleNetworkOut(*models.Metrics)
}

Transformer specifies that all concrete implementations should be able to transform an entire environments metrics data (group) or a single service metrics data (single).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL