예제 #1
0
파일: metrics.go 프로젝트: jmcfarlane/apex
// Run command.
func run(c *cobra.Command, args []string) error {
	if err := root.Project.LoadFunctions(args...); err != nil {
		return err
	}

	config := metrics.Config{
		Service:   cloudwatch.New(root.Session),
		StartDate: time.Now().UTC().Add(-duration),
		EndDate:   time.Now().UTC(),
	}

	m := metrics.Metrics{
		Config: config,
	}

	for _, fn := range root.Project.Functions {
		m.FunctionNames = append(m.FunctionNames, fn.FunctionName)
	}

	aggregated := m.Collect()

	fmt.Println()
	for _, fn := range root.Project.Functions {
		fnMetrics := aggregated[fn.FunctionName]

		fmt.Printf("  \033[%dm%s\033[0m\n", colors.Blue, fn.Name)
		fmt.Printf("    invocations: %v\n", fnMetrics.Invocations)
		fmt.Printf("    duration: %vms\n", fnMetrics.Duration)
		fmt.Printf("    throttles: %v\n", fnMetrics.Throttles)
		fmt.Printf("    error: %v\n", fnMetrics.Errors)
		fmt.Println()
	}

	return nil
}
예제 #2
0
파일: metrics.go 프로젝트: Robh081956/apex
// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Metrics", map[string]interface{}{
		"since": duration,
	})

	if err := root.Project.LoadFunctions(args...); err != nil {
		return err
	}

	service := lambda.New(root.Session)

	config := metrics.Config{
		Service:   cloudwatch.New(root.Session),
		StartDate: time.Now().UTC().Add(-duration),
		EndDate:   time.Now().UTC(),
	}

	m := metrics.Metrics{
		Config: config,
	}

	for _, fn := range root.Project.Functions {
		m.FunctionNames = append(m.FunctionNames, fn.FunctionName)
	}

	aggregated := m.Collect()

	fmt.Println()
	for _, fn := range root.Project.Functions {
		m := aggregated[fn.FunctionName]

		conf, err := service.GetFunctionConfiguration(&lambda.GetFunctionConfigurationInput{FunctionName: &fn.FunctionName})
		if err != nil {
			return err
		}

		memory := int(*conf.MemorySize)
		costTotal := humanize.FormatFloat("", cost.Cost(m.Invocations, m.Duration, memory))
		costDuration := humanize.FormatFloat("", cost.DurationCost(m.Duration, memory))
		costInvocations := humanize.FormatFloat("", cost.RequestCost(m.Invocations))

		fmt.Printf("  \033[%dm%s\033[0m\n", colors.Blue, fn.Name)
		fmt.Printf("    total cost: $%s\n", costTotal)
		fmt.Printf("    invocations: %s ($%s)\n", humanize.Comma(int64(m.Invocations)), costInvocations)
		fmt.Printf("    duration: %s ($%s)\n", time.Millisecond*time.Duration(m.Duration), costDuration)
		fmt.Printf("    throttles: %v\n", m.Throttles)
		fmt.Printf("    errors: %s\n", humanize.Comma(int64(m.Errors)))
		fmt.Printf("    memory: %d\n", memory)
		fmt.Println()
	}

	return nil
}