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


Golang go-metrics.NewCounter函数代码示例

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


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

示例1: NewSubjectPrefixMatchFilter

func NewSubjectPrefixMatchFilter(next Filter, subjectPrefixes []string) *SubjectPrefixMatchFilter {
	total := metrics.NewCounter()
	matched := metrics.NewCounter()
	metrics.Register("SubjectPrefixMatchFilter-Total", total)
	metrics.Register("SubjectPrefixMatchFilter-Matched", matched)
	return &SubjectPrefixMatchFilter{next, subjectPrefixes, total, matched}
}
开发者ID:postfix,项目名称:spamdefender,代码行数:7,代码来源:subjectprefixmatchfilter.go

示例2: NewRelayOnlyFilter

func NewRelayOnlyFilter(next Filter, localDomain string) *RelayOnlyFilter {
	total := metrics.NewCounter()
	numOfRelay := metrics.NewCounter()
	metrics.Register("RelayOnlyFilter-Total", total)
	metrics.Register("RelayOnlyFilter-Relay", numOfRelay)
	return &RelayOnlyFilter{next, localDomain, total, numOfRelay}
}
开发者ID:postfix,项目名称:spamdefender,代码行数:7,代码来源:relayonlyfilter.go

示例3: NewContentInspectionUpdater

func NewContentInspectionUpdater(anlz analyzer.Analyzer, class string) *ContentInspectionUpdater {
	total := metrics.NewCounter()
	malformed := metrics.NewCounter()
	metrics.Register("ContentInspectionUpdater-Total", total)
	metrics.Register("ContentInspectionUpdater-Malformed", malformed)

	return &ContentInspectionUpdater{anlz, class, total, malformed}
}
开发者ID:postfix,项目名称:spamdefender,代码行数:8,代码来源:contentinspectionupdater.go

示例4: NewClientMetrics

func NewClientMetrics() *ClientMetrics {
	return &ClientMetrics{
		connGauge:       metrics.NewGauge(),
		connMeter:       metrics.NewMeter(),
		connTimer:       metrics.NewTimer(),
		proxySetupTimer: metrics.NewTimer(),
		bytesIn:         metrics.NewHistogram(metrics.NewExpDecaySample(sampleSize, sampleAlpha)),
		bytesOut:        metrics.NewHistogram(metrics.NewExpDecaySample(sampleSize, sampleAlpha)),
		bytesInCount:    metrics.NewCounter(),
		bytesOutCount:   metrics.NewCounter(),
	}
}
开发者ID:0x19,项目名称:ngrok,代码行数:12,代码来源:metrics.go

示例5: NewDeliverFilter

func NewDeliverFilter(next Filter, paths map[Result]string) *DeliverFilter {
	total := metrics.NewCounter()
	metrics.Register("DeliverFilter-Total", total)

	counters := make(map[Result]metrics.Counter)
	for result, path := range paths {
		counter := metrics.NewCounter()
		counters[result] = counter
		metrics.Register("DeliverFilter-"+path, counter)
	}
	return &DeliverFilter{next, paths, total, counters}
}
开发者ID:postfix,项目名称:spamdefender,代码行数:12,代码来源:deliverfilter.go

示例6: NewContentInspectionFilter

func NewContentInspectionFilter(next Filter, allPass bool, anlz analyzer.Analyzer) *ContentInspectionFilter {
	total := metrics.NewCounter()
	metrics.Register("ContentInspectionFilter-Total", total)
	counters := make(map[string]metrics.Counter)
	for _, class := range []string{analyzer.Good, analyzer.Bad, analyzer.Neutral} {
		counter := metrics.NewCounter()
		counters[class] = counter
		metrics.Register("ContentInspectionFilter-"+class, counter)
	}
	malformed := metrics.NewCounter()
	metrics.Register("ContentInspectionFilter-Malformed", malformed)

	return &ContentInspectionFilter{next, allPass, anlz, total, malformed, counters}
}
开发者ID:postfix,项目名称:spamdefender,代码行数:14,代码来源:contentinspectionfilter.go

示例7: NewFileHandlerAdapter

func NewFileHandlerAdapter(updater Updater, factory mailfile.MailFileFactory) *FileHandlerAdapter {
	total := metrics.NewCounter()
	meter := metrics.NewMeter()
	metrics.Register("FileHandlerAdapter-Total", total)
	metrics.Register("FileHandlerAdapter-Size", meter)
	return &FileHandlerAdapter{updater, factory, total, meter}
}
开发者ID:postfix,项目名称:spamdefender,代码行数:7,代码来源:filehandleradapter.go

示例8: TestCounter

func TestCounter(t *testing.T) {
	c := mt.NewCounter()
	if c.Count() != 0 {
		t.Errorf("counter.count: expected %d, got %d", 0, c.Count())
	}

	c.Inc(1)
	if c.Count() != 1 {
		t.Errorf("counter.Inc: expected %d, got %d", 1, c.Count())
	}

	c.Inc(-2)
	if c.Count() != -1 {
		t.Errorf("counter.Inc: expected %d, got %d", -1, c.Count())
	}

	c.Dec(1)
	if c.Count() != -2 {
		t.Errorf("counter.Dec: expected %d, got %d", -2, c.Count())
	}

	c.Dec(-3)
	if c.Count() != 1 {
		t.Errorf("counter.Dec: expected %d, got %d", 1, c.Count())
	}

	c.Clear()
	if c.Count() != 0 {
		t.Errorf("counter.Clear: expected %d, got %d", 0, c.Count())
	}
}
开发者ID:najeira,项目名称:sql,代码行数:31,代码来源:counter_test.go

示例9: NewPointInPolygonMetrics

func NewPointInPolygonMetrics() *WOFPointInPolygonMetrics {

	registry := metrics.NewRegistry()

	cnt_lookups := metrics.NewCounter()
	cnt_unmarshal := metrics.NewCounter()
	cnt_cache_hit := metrics.NewCounter()
	cnt_cache_miss := metrics.NewCounter()
	cnt_cache_set := metrics.NewCounter()

	tm_unmarshal := metrics.NewTimer()
	tm_intersect := metrics.NewTimer()
	tm_inflate := metrics.NewTimer()
	tm_contain := metrics.NewTimer()
	tm_process := metrics.NewTimer()

	registry.Register("pip.reversegeo.lookups", cnt_lookups)
	registry.Register("pip.geojson.unmarshaled", cnt_unmarshal)
	registry.Register("pip.cache.hit", cnt_cache_hit)
	registry.Register("pip.cache.miss", cnt_cache_miss)
	registry.Register("pip.cache.set", cnt_cache_set)
	registry.Register("pip.timer.reversegeo", tm_process)
	registry.Register("pip.timer.unmarshal", tm_unmarshal)
	// registry.Register("time-to-intersect", tm_intersect)
	// registry.Register("time-to-inflate", tm_inflate)
	registry.Register("pip.timer.containment", tm_contain)

	m := WOFPointInPolygonMetrics{
		Registry:        &registry,
		CountLookups:    &cnt_lookups,
		CountUnmarshal:  &cnt_unmarshal,
		CountCacheHit:   &cnt_cache_hit,
		CountCacheMiss:  &cnt_cache_miss,
		CountCacheSet:   &cnt_cache_set,
		TimeToUnmarshal: &tm_unmarshal,
		TimeToIntersect: &tm_intersect,
		TimeToInflate:   &tm_inflate,
		TimeToContain:   &tm_contain,
		TimeToProcess:   &tm_process,
	}

	metrics.RegisterRuntimeMemStats(registry)
	go metrics.CaptureRuntimeMemStats(registry, 10e9)

	return &m
}
开发者ID:missinglink,项目名称:go-whosonfirst-pip,代码行数:46,代码来源:pip.go

示例10: NewCachingProxy

func NewCachingProxy(target Filter, size int) *CachingProxy {
	_, ok := target.(CacheKey)
	if !ok {
		log.Fatalf("%s should implement CacheKey interface\n", target)
		return nil
	}

	total := metrics.NewCounter()
	hit := metrics.NewCounter()
	cached := metrics.NewGauge()

	targetName := fmt.Sprintf("%s", target)

	metrics.Register("CachingProxy("+targetName+")-Total", total)
	metrics.Register("CachingProxy("+targetName+")-Hit", hit)
	metrics.Register("CachingProxy("+targetName+")-Cached", cached)
	return &CachingProxy{target, &sync.RWMutex{}, list.New(), size, total, hit, cached}
}
开发者ID:postfix,项目名称:spamdefender,代码行数:18,代码来源:cachingfilter.go

示例11: NewMetricsHttp

func NewMetricsHttp() *MetricsHttp {
	return &MetricsHttp{
		clients:        mt.NewHistogram(mt.NewExpDecaySample(1028, 0.015)),
		clientsCounter: mt.NewCounter(),
		requests:       mt.NewTimer(),
		status2xx:      mt.NewMeter(),
		status3xx:      mt.NewMeter(),
		status4xx:      mt.NewMeter(),
		status5xx:      mt.NewMeter(),
	}
}
开发者ID:najeira,项目名称:goutils,代码行数:11,代码来源:metrics.go

示例12: NewLocalMetrics

func NewLocalMetrics(reportInterval time.Duration) *LocalMetrics {
	metrics := LocalMetrics{
		Logger:         log.NewPrefixLogger("metrics"),
		reportInterval: reportInterval,
		windowsCounter: gometrics.NewCounter(),
		linuxCounter:   gometrics.NewCounter(),
		osxCounter:     gometrics.NewCounter(),
		otherCounter:   gometrics.NewCounter(),

		tunnelMeter:        gometrics.NewMeter(),
		tcpTunnelMeter:     gometrics.NewMeter(),
		httpTunnelMeter:    gometrics.NewMeter(),
		connMeter:          gometrics.NewMeter(),
		lostHeartbeatMeter: gometrics.NewMeter(),

		connTimer: gometrics.NewTimer(),

		bytesInCount:  gometrics.NewCounter(),
		bytesOutCount: gometrics.NewCounter(),

		/*
		   metrics.tunnelGauge = gometrics.NewGauge(),
		   metrics.tcpTunnelGauge = gometrics.NewGauge(),
		   metrics.connGauge = gometrics.NewGauge(),
		*/
	}

	go metrics.Report()

	return &metrics
}
开发者ID:0x19,项目名称:ngrok,代码行数:31,代码来源:metrics.go

示例13: initializeFieldTagPath

// initializeFieldTagPath traverses the given struct trying to initialize
// metric values.  The "metric" struct tag is used to determine the name of the
// metrics for each struct field. If there is no "metric" struct tag, the
// lowercased struct field name is used for the metric name. The name is
// prefixed with tags from previous struct fields if any, separated by a dot.
// For example:
//
//     	Messages struct {
//          Smtp struct {
//              Latency metrics.Timer `metric:"latency"`
//          } `metric:"smtp"`
//          Http struct {
//              Latency metrics.Timer `metric:"latency"`
//          } `metric:"http"`
//      } `metric:"messages"`
//
// yields timers with names "messages.smtp.latency" and "messages.http.latency"
// respectively.
//
// If there is no metric tag for a field it is skipped and assumed it is used
// for other purposes such as configuration.
func (m *MetricTags) initializeFieldTagPath(fieldType reflect.Value, prefix string) {
	for i := 0; i < fieldType.NumField(); i++ {
		val := fieldType.Field(i)
		field := fieldType.Type().Field(i)

		tag := field.Tag.Get("metric")
		if tag == "" {
			// If tag isn't found, derive tag from the lower case name of
			// the field.
			tag = strings.ToLower(field.Name)
		}
		if prefix != "" {
			tag = prefix + m.separator + tag
		}

		if field.Type.Kind() == reflect.Struct {
			// Recursively traverse an embedded struct
			m.initializeFieldTagPath(val, tag)
		} else if field.Type.Kind() == reflect.Map && field.Type.Key().Kind() == reflect.String {
			// If this is a map[string]Something, then use the string key as bucket name and recursively generate the metrics below
			for _, k := range val.MapKeys() {
				m.initializeFieldTagPath(val.MapIndex(k).Elem(), tag+m.separator+k.String())
			}
		} else {
			// Found a field, initialize
			switch field.Type.String() {
			case "metrics.Counter":
				c := metrics.NewCounter()
				metrics.Register(tag, c)
				val.Set(reflect.ValueOf(c))
			case "metrics.Timer":
				t := metrics.NewTimer()
				metrics.Register(tag, t)
				val.Set(reflect.ValueOf(t))
			case "metrics.Meter":
				m := metrics.NewMeter()
				metrics.Register(tag, m)
				val.Set(reflect.ValueOf(m))
			case "metrics.Gauge":
				g := metrics.NewGauge()
				metrics.Register(tag, g)
				val.Set(reflect.ValueOf(g))
			case "metrics.Histogram":
				s := metrics.NewUniformSample(1028)
				h := metrics.NewHistogram(s)
				metrics.Register(tag, h)
				val.Set(reflect.ValueOf(h))
			}
		}
	}
}
开发者ID:sendgrid,项目名称:tagtrics,代码行数:72,代码来源:tagtrics.go

示例14: SaveCounter

// SaveCounter indicates that we want to store an internal representation of the counts in this bucket so that we can
// query it (via GetCounter).
func (i *Instrumentation) SaveCounter(bucket string) error {
	i.mtx.Lock()
	defer i.mtx.Unlock()

	if _, exists := i.savedCounters[bucket]; exists {
		return fmt.Errorf("Counter bucket %s already registered", bucket)
	}

	c := metrics.NewCounter()
	i.registry.Register(bucket, c)
	i.savedCounters[bucket] = c

	return nil
}
开发者ID:armada-io,项目名称:h2,代码行数:16,代码来源:instrumentation.go

示例15: NewHttpMetric

func NewHttpMetric() *HttpMetric {
	x := &HttpMetric{
		Requests: metrics.NewCounter(),
		Rate:     metrics.NewMeter(),

		Responses2xx: metrics.NewCounter(),
		Responses3xx: metrics.NewCounter(),
		Responses4xx: metrics.NewCounter(),
		Responses5xx: metrics.NewCounter(),
		ResponsesXxx: metrics.NewCounter(),
		Latency:      metrics.NewHistogram(metrics.NewExpDecaySample(1028, 0.015)),
	}
	return x
}
开发者ID:hanjinze,项目名称:gorouter,代码行数:14,代码来源:varz.go


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