• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang graphite.NewParserWithOptions函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestApplyTemplateSpecific

// Test that most specific template is chosen
func TestApplyTemplateSpecific(t *testing.T) {
	o := graphite.Options{
		Separator: "_",
		Templates: []string{
			"current.* measurement.measurement",
			"current.*.* measurement.measurement.service",
		},
	}
	p, err := graphite.NewParserWithOptions(o)
	if err != nil {
		t.Fatalf("unexpected error creating parser, got %v", err)
	}

	measurement, tags := p.ApplyTemplate("current.users.facebook")
	if measurement != "current_users" {
		t.Errorf("Parser.ApplyTemplate unexpected result. got %s, exp %s",
			measurement, "current_users")
	}
	service, ok := tags["service"]
	if !ok {
		t.Error("Expected for template to apply a 'service' tag, but not found")
	}
	if service != "facebook" {
		t.Errorf("Expected service='facebook' tag, got service='%s'", service)
	}
}
开发者ID:roobert,项目名称:influxdb,代码行数:27,代码来源:parser_test.go


示例2: parseName

// parseName parses the given bucket name with the list of bucket maps in the
// config file. If there is a match, it will parse the name of the metric and
// map of tags.
// Return values are (<name>, <tags>)
func (s *Statsd) parseName(bucket string) (string, map[string]string) {
	tags := make(map[string]string)

	bucketparts := strings.Split(bucket, ",")
	// Parse out any tags in the bucket
	if len(bucketparts) > 1 {
		for _, btag := range bucketparts[1:] {
			k, v := parseKeyValue(btag)
			if k != "" {
				tags[k] = v
			}
		}
	}

	o := graphite.Options{
		Separator:   "_",
		Templates:   s.Templates,
		DefaultTags: tags,
	}

	name := bucketparts[0]
	p, err := graphite.NewParserWithOptions(o)
	if err == nil {
		name, tags, _, _ = p.ApplyTemplate(name)
	}
	if s.ConvertNames {
		name = strings.Replace(name, ".", "_", -1)
		name = strings.Replace(name, "-", "__", -1)
	}

	return name, tags
}
开发者ID:skwong2,项目名称:telegraf,代码行数:36,代码来源:statsd.go


示例3: TestApplyTemplateNoMatch

// Test basic functionality of ApplyTemplate
func TestApplyTemplateNoMatch(t *testing.T) {
	o := graphite.Options{
		Separator: "_",
		Templates: []string{"foo.bar measurement.measurement"},
	}
	p, err := graphite.NewParserWithOptions(o)
	if err != nil {
		t.Fatalf("unexpected error creating parser, got %v", err)
	}

	measurement, _ := p.ApplyTemplate("current.users")
	if measurement != "current.users" {
		t.Errorf("Parser.ApplyTemplate unexpected result. got %s, exp %s",
			measurement, "current.users")
	}
}
开发者ID:roobert,项目名称:influxdb,代码行数:17,代码来源:parser_test.go


示例4: TestApplyTemplateFieldError

func TestApplyTemplateFieldError(t *testing.T) {
	o := graphite.Options{
		Separator: "_",
		Templates: []string{"current.* measurement.field.field"},
	}
	p, err := graphite.NewParserWithOptions(o)
	if err != nil {
		t.Fatalf("unexpected error creating parser, got %v", err)
	}

	_, _, _, err = p.ApplyTemplate("current.users.logged_in")
	if err == nil {
		t.Errorf("Parser.ApplyTemplate unexpected result. got %s, exp %s", err,
			"'field' can only be used once in each template: current.users.logged_in")
	}
}
开发者ID:rhyolight,项目名称:influxdb,代码行数:16,代码来源:parser_test.go


示例5: TestApplyTemplateSpecificIsNA

// Test that most specific template is N/A
func TestApplyTemplateSpecificIsNA(t *testing.T) {
	o := graphite.Options{
		Separator: "_",
		Templates: []string{
			"current.* measurement.service",
			"current.*.*.test measurement.measurement.service",
		},
	}
	p, err := graphite.NewParserWithOptions(o)
	if err != nil {
		t.Fatalf("unexpected error creating parser, got %v", err)
	}

	measurement, _, _, _ := p.ApplyTemplate("current.users.facebook")
	if measurement != "current" {
		t.Errorf("Parser.ApplyTemplate unexpected result. got %s, exp %s",
			measurement, "current")
	}
}
开发者ID:flisky,项目名称:influxdb,代码行数:20,代码来源:parser_test.go


示例6: TestApplyTemplateField

func TestApplyTemplateField(t *testing.T) {
	o := graphite.Options{
		Separator: "_",
		Templates: []string{"current.* measurement.measurement.field"},
	}
	p, err := graphite.NewParserWithOptions(o)
	if err != nil {
		t.Fatalf("unexpected error creating parser, got %v", err)
	}

	measurement, _, field, err := p.ApplyTemplate("current.users.logged_in")

	if measurement != "current_users" {
		t.Errorf("Parser.ApplyTemplate unexpected result. got %s, exp %s",
			measurement, "current_users")
	}

	if field != "logged_in" {
		t.Errorf("Parser.ApplyTemplate unexpected result. got %s, exp %s",
			field, "logged_in")
	}
}
开发者ID:rhyolight,项目名称:influxdb,代码行数:22,代码来源:parser_test.go


示例7: TestFilterMatchMultipleMeasurementSeparator

func TestFilterMatchMultipleMeasurementSeparator(t *testing.T) {
	p, err := graphite.NewParserWithOptions(graphite.Options{
		Templates: []string{"servers.localhost .host.measurement.measurement*"},
		Separator: "_",
	})
	if err != nil {
		t.Fatalf("unexpected error creating parser, got %v", err)
	}

	exp := tsdb.NewPoint("cpu_cpu_load_10",
		tsdb.Tags{"host": "localhost"},
		tsdb.Fields{"value": float64(11)},
		time.Unix(1435077219, 0))

	pt, err := p.Parse("servers.localhost.cpu.cpu_load.10 11 1435077219")
	if err != nil {
		t.Fatalf("parse error: %v", err)
	}

	if exp.String() != pt.String() {
		t.Errorf("parse mismatch: got %v, exp %v", pt.String(), exp.String())
	}
}
开发者ID:tcompart,项目名称:influxdb,代码行数:23,代码来源:parser_test.go


示例8: TestApplyTemplateTags

func TestApplyTemplateTags(t *testing.T) {
	o := graphite.Options{
		Separator: "_",
		Templates: []string{"current.* measurement.measurement region=us-west"},
	}
	p, err := graphite.NewParserWithOptions(o)
	if err != nil {
		t.Fatalf("unexpected error creating parser, got %v", err)
	}

	measurement, tags := p.ApplyTemplate("current.users")
	if measurement != "current_users" {
		t.Errorf("Parser.ApplyTemplate unexpected result. got %s, exp %s",
			measurement, "current_users")
	}

	region, ok := tags["region"]
	if !ok {
		t.Error("Expected for template to apply a 'region' tag, but not found")
	}
	if region != "us-west" {
		t.Errorf("Expected region='us-west' tag, got region='%s'", region)
	}
}
开发者ID:roobert,项目名称:influxdb,代码行数:24,代码来源:parser_test.go


示例9: TestFilterMatchEnquos


//.........这里部分代码省略.........
		{
			"enquos.counters.celery.w1.composite.chargify_subscription_cache.miss.count 11 1435077219",
			"chargify_subscription_cache,agg=count,category=app,discr=miss,env=celery,host=w1 value=11 1435077219000000000",
		},
		{
			"enquos.counters.mobile.a1.composite.groupfinder.hit.rate 11 1435077219",
			"groupfinder,agg=rate,category=app,discr=hit,env=mobile,host=a1 value=11 1435077219000000000",
		},
		{
			"enquos.counters.web.a2.composite.cron_task_fired.check_all_tokens.rate 11 1435077219",
			"cron_task_fired,agg=rate,category=app,discr=check_all_tokens,env=web,host=a2 value=11 1435077219000000000",
		},
		{
			"enquos.counters.web.a1.composite.request_status.resp200.count 11 1435077219",
			"request_status,agg=count,category=app,discr=resp200,env=web,host=a1 value=11 1435077219000000000",
		},
		{
			"enquos.counters.web.a1.composite.registration.init.count 11 1435077219",
			"registration,agg=count,category=app,discr=init,env=web,host=a1 value=11 1435077219000000000",
		},
		{
			"enquos.counters.web.a1.composite.password.strength_failure.rate 11 1435077219",
			"password,agg=rate,category=app,discr=strength_failure,env=web,host=a1 value=11 1435077219000000000",
		},
		{
			"enquos.counters.web.a1.composite.nutrition_favorite.added.count 11 1435077219",
			"nutrition_favorite,agg=count,category=app,discr=added,env=web,host=a1 value=11 1435077219000000000",
		},
		{
			"enquos.counters.web.a1.composite.login.success.count 11 1435077219",
			"login,agg=count,category=app,discr=success,env=web,host=a1 value=11 1435077219000000000",
		},
		{
			"enquos.counters.web.a1.composite.password_reset.init.count 11 1435077219",
			"password_reset,agg=count,category=app,discr=init,env=web,host=a1 value=11 1435077219000000000",
		},
		{
			"enquos.counters.mobile.a1.composite.nutrition_delta.miss.count 11 1435077219",
			"nutrition_delta,agg=count,category=app,discr=miss,env=mobile,host=a1 value=11 1435077219000000000",
		},
		{
			"enquos.counters.web.a1.composite.about_dev.attempt.count 11 1435077219",
			"about_dev,agg=count,category=app,discr=attempt,env=web,host=a1 value=11 1435077219000000000",
		},
		{
			"enquos.counters.web.a1.composite.chargify_webhook.statement_settled.count 11 1435077219",
			"chargify_webhook,agg=count,category=app,discr=statement_settled,env=web,host=a1 value=11 1435077219000000000",
		},
		{
			"enquos.counters.web.a1.ratelimit_redis_error.count 11 1435077219",
			"ratelimit_redis_error,agg=count,category=app,env=web,host=a1 value=11 1435077219000000000",
		},
		{
			"enquos.counters.celery.w1.validic.imported.fitbit.routine.count  11 1435077219",
			"validic_imported,agg=count,category=app,env=celery,host=w1,kind=routine,source=fitbit value=11 1435077219000000000",
		},
		// Timers
		{
			"enquos.timers.web.a3.request_duration.mean_99 11 1435077219",
			"request_duration,agg=mean_99,category=app,env=web,host=a3 value=11 1435077219000000000",
		},
		{
			"enquos.timers.mobile.a1.health_check.upper 11 1435077219",
			"health_check,agg=upper,category=app,env=mobile,host=a1 value=11 1435077219000000000",
		},
		{
			"enquos.timers.web.a2.groupfinder.total.mean 11 1435077219",
			"groupfinder,agg=mean,category=app,env=web,host=a2 value=11 1435077219000000000",
		},
		// Cassandra driver
		{
			"enquos.scales.web.a3.cassandra.request_timer.99percentile 11 1435077219",
			"cassandra_request_timer,agg=99percentile,category=app,env=web,host=a3 value=11 1435077219000000000",
		},
		{
			"enquos.scales.celery.w2.cassandra.read_timeouts 11 1435077219",
			"cassandra_read_timeouts,category=app,env=celery,host=w2 value=11 1435077219000000000",
		},
	}

	p, err := graphite.NewParserWithOptions(graphite.Options{
		Templates: templates,
		Separator: "_",
	})

	if err != nil {
		t.Fatalf("unexpected error creating parser, got %v", err)
	}

	for _, tc := range test_cases {
		pt, err := p.Parse(tc.metric)
		if err != nil {
			t.Fatalf("parse error: %v", err)
		}
		if pt.String() != tc.expected {
			t.Errorf("parse mismatch: got %v, exp %v", pt.String(), tc.expected)
		}
	}

}
开发者ID:enquos,项目名称:influxdb,代码行数:101,代码来源:parser_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang graphite.NewService函数代码示例发布时间:2022-05-23
下一篇:
Golang graphite.NewParser函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap