当前位置: 首页>>代码示例>>Golang>>正文


Golang stats.Track函数代码示例

本文整理汇总了Golang中github.com/apex/apex/stats.Track函数的典型用法代码示例。如果您正苦于以下问题:Golang Track函数的具体用法?Golang Track怎么用?Golang Track使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Track函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Logs", map[string]interface{}{
		"has_filter": filter != "",
		"since":      duration,
		"follow":     follow,
	})

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

	config := logs.Config{
		Service:       cloudwatchlogs.New(root.Session),
		StartTime:     time.Now().Add(-duration).UTC(),
		PollInterval:  5 * time.Second,
		Follow:        follow,
		FilterPattern: filter,
	}

	l := &logs.Logs{
		Config: config,
	}

	for _, fn := range root.Project.Functions {
		l.GroupNames = append(l.GroupNames, fn.GroupName())
	}

	for event := range l.Start() {
		fmt.Printf("\033[34m%s\033[0m %s", event.GroupName, event.Message)
	}

	return l.Err()
}
开发者ID:DavidTPate,项目名称:apex,代码行数:34,代码来源:logs.go

示例2: run

// Run command.
func run(c *cobra.Command, args []string) (err error) {
	stats.Track("Docs", nil)

	var w io.WriteCloser = os.Stdout

	if isatty.IsTerminal(os.Stdout.Fd()) {
		cmd := exec.Command("less", "-R")
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr

		defer cmd.Wait()

		w, err = cmd.StdinPipe()
		if err != nil {
			return err
		}
		defer w.Close()

		if err := cmd.Start(); err != nil {
			return err
		}
	}

	_, err = io.Copy(w, doc.Reader())
	return err
}
开发者ID:DavidTPate,项目名称:apex,代码行数:27,代码来源:docs.go

示例3: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Deploy", map[string]interface{}{
		"concurrency": concurrency,
		"has_alias":   alias != "",
		"env":         len(env),
		"args":        len(args),
	})

	root.Project.Concurrency = concurrency
	root.Project.Alias = alias

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

	for _, fn := range root.Project.Functions {
		stats.Track("Deploy Function", map[string]interface{}{
			"runtime":      fn.Runtime,
			"has_alias":    alias != "",
			"has_env_file": envFile != "",
			"env":          len(env),
		})
	}

	if envFile != "" {
		if err := root.Project.LoadEnvFromFile(envFile); err != nil {
			return fmt.Errorf("reading env file %q: %s", envFile, err)
		}
	}

	vars, err := utils.ParseEnv(env)
	if err != nil {
		return err
	}

	for k, v := range vars {
		root.Project.Setenv(k, v)
	}

	return root.Project.DeployAndClean()
}
开发者ID:DavidTPate,项目名称:apex,代码行数:42,代码来源:deploy.go

示例4: run

// 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
}
开发者ID:Robh081956,项目名称:apex,代码行数:54,代码来源:metrics.go

示例5: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Init", nil)

	if err := root.Prepare(c, args); err != nil {
		return err
	}

	region := root.Config.Region
	if region == nil {
		return errors.New("AWS region missing, are your credentials set up? Visit http://apex.run/#aws-credentials for more details")
	}

	return boot.All(*region)
}
开发者ID:Robh081956,项目名称:apex,代码行数:15,代码来源:init.go

示例6: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Invoke", map[string]interface{}{
		"has_alias": alias != "",
		"has_logs":  includeLogs,
	})

	dec := json.NewDecoder(input())

	root.Project.Alias = alias

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

	fn := root.Project.Functions[0]

	for {
		var v map[string]interface{}
		err := dec.Decode(&v)

		if err == io.EOF {
			break
		}

		if err != nil {
			return fmt.Errorf("parsing response: %s", err)
		}

		var reply, logs io.Reader

		if e, ok := v["event"].(map[string]interface{}); ok {
			reply, logs, err = fn.Invoke(e, v["context"])
		} else {
			reply, logs, err = fn.Invoke(v, nil)
		}

		if includeLogs {
			io.Copy(os.Stderr, logs)
		}

		if err != nil {
			return fmt.Errorf("function response: %s", err)
		}

		io.Copy(os.Stdout, reply)
		fmt.Fprintf(os.Stdout, "\n")
	}

	return nil
}
开发者ID:Robh081956,项目名称:apex,代码行数:51,代码来源:invoke.go

示例7: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Deploy", map[string]interface{}{
		"concurrency": concurrency,
		"has_alias":   alias != "",
		"env":         len(env),
		"args":        len(args),
	})

	root.Project.Concurrency = concurrency
	root.Project.Alias = alias

	c.Root().PersistentFlags().Lookup("name string")

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

	for _, fn := range root.Project.Functions {
		stats.Track("Deploy Function", map[string]interface{}{
			"runtime":   fn.Runtime,
			"has_alias": alias != "",
			"env":       len(env),
		})
	}

	for _, s := range env {
		parts := strings.SplitN(s, "=", 2)
		if len(parts) == 2 {
			root.Project.Setenv(parts[0], parts[1])
		} else {
			return fmt.Errorf("environment variable %s needs a value", parts[0])
		}
	}

	return root.Project.DeployAndClean()
}
开发者ID:Robh081956,项目名称:apex,代码行数:37,代码来源:deploy.go

示例8: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("List", map[string]interface{}{
		"tfvars": tfvars,
	})

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

	if tfvars {
		outputTFvars()
	} else {
		outputList()
	}

	return nil
}
开发者ID:tobyjoe,项目名称:apex,代码行数:18,代码来源:list.go

示例9: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Rollback", map[string]interface{}{
		"has_alias":   alias != "",
		"has_version": version != "",
	})

	root.Project.Alias = alias

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

	if version == "" {
		return root.Project.Rollback()
	}

	return root.Project.RollbackVersion(version)
}
开发者ID:DavidTPate,项目名称:apex,代码行数:19,代码来源:rollback.go

示例10: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Init", nil)

	if err := root.Prepare(c, args); err != nil {
		return err
	}

	region := root.Config.Region
	if region == nil {
		return errors.New(credentialsError)
	}

	b := boot.Bootstrapper{
		IAM:    iam.New(root.Session),
		Region: *region,
	}

	return b.Boot()
}
开发者ID:DavidTPate,项目名称:apex,代码行数:20,代码来源:init.go

示例11: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Infra", nil)

	err := root.Project.LoadFunctions()

	// Hack to prevent initial `apex infra apply` from failing,
	// as we load functions to expose their ARNs.
	if err != nil {
		if !strings.Contains(err.Error(), "Role: zero value") {
			return err
		}
	}

	p := &infra.Proxy{
		Functions:   root.Project.Functions,
		Region:      *root.Session.Config.Region,
		Environment: root.Project.Environment,
	}

	return p.Run(args...)
}
开发者ID:Robh081956,项目名称:apex,代码行数:22,代码来源:infra.go

示例12: run

// Run command.
func run(c *cobra.Command, args []string) error {
	if err := root.Project.LoadFunctions(name); err != nil {
		return err
	}

	fn := root.Project.Functions[0]

	stats.Track("Build", map[string]interface{}{
		"runtime":      fn.Runtime,
		"env":          len(env),
		"has_env_file": envFile != "",
	})

	if envFile != "" {
		if err := root.Project.LoadEnvFromFile(envFile); err != nil {
			return fmt.Errorf("reading env file %q: %s", envFile, err)
		}
	}

	vars, err := utils.ParseEnv(env)
	if err != nil {
		return err
	}

	for k, v := range vars {
		root.Project.Setenv(k, v)
	}

	zip, err := fn.Build()
	if err != nil {
		return err
	}

	if err := fn.Clean(); err != nil {
		return err
	}

	_, err = io.Copy(os.Stdout, zip)
	return err
}
开发者ID:coderhaoxin,项目名称:apex,代码行数:41,代码来源:build.go

示例13: run

// Run command.
func run(c *cobra.Command, args []string) error {
	if err := root.Project.LoadFunctions(name); err != nil {
		return err
	}

	fn := root.Project.Functions[0]

	stats.Track("Build", map[string]interface{}{
		"runtime": fn.Runtime,
	})

	zip, err := fn.Build()
	if err != nil {
		return err
	}

	if err := fn.Clean(); err != nil {
		return err
	}

	_, err = io.Copy(os.Stdout, zip)
	return err
}
开发者ID:Robh081956,项目名称:apex,代码行数:24,代码来源:build.go

示例14: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Delete", map[string]interface{}{
		"force": force,
		"args":  len(args),
	})

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

	if !force && len(root.Project.Functions) > 1 {
		fmt.Printf("The following will be deleted:\n\n")
		for _, fn := range root.Project.Functions {
			fmt.Printf("  - %s\n", fn.Name)
		}
		fmt.Printf("\n")
	}

	if !force && !prompt.Confirm("Are you sure? (yes/no) ") {
		return nil
	}

	return root.Project.Delete()
}
开发者ID:Robh081956,项目名称:apex,代码行数:25,代码来源:delete.go

示例15: run

// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Upgrade", nil)
	return upgrade.Upgrade(version.Version)
}
开发者ID:DavidTPate,项目名称:apex,代码行数:5,代码来源:upgrade.go


注:本文中的github.com/apex/apex/stats.Track函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。