Example #1
0
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(),
	}
}
Example #2
0
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
}
Example #3
0
//Initialize global metrics.Timer object, used to collect HTTP metrics
func (agent *StandardAgent) initTimer() {
	if agent.HTTPTimer == nil {
		agent.HTTPTimer = metrics.NewTimer()
	}

	agent.CollectHTTPStat = true
}
Example #4
0
func NewHttp() *Http {
	return &Http{
		Txns:     util.NewBroadcast(),
		reqGauge: metrics.NewGauge(),
		reqMeter: metrics.NewMeter(),
		reqTimer: metrics.NewTimer(),
	}
}
Example #5
0
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
}
Example #6
0
func (s *stats) registerEndpoint(ep Endpoint) {
	s.mtx.Lock()
	defer s.mtx.Unlock()

	if _, ok := s.timers[ep]; ok {
		return
	}

	sTimer := metrics.NewTimer()
	eTimer := metrics.NewTimer()

	s.registry.Register(ep.GetName()+".success", sTimer)
	s.registry.Register(ep.GetName()+".error", eTimer)

	s.timers[ep] = endpointTimers{
		success: sTimer,
		errors:  eTimer,
	}
}
Example #7
0
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(),
	}
}
Example #8
0
func (smb standardBucket) Timer(name string) Timer {
	smb.Lock()
	defer smb.Unlock()

	timer, ok := smb.timers[name]
	if !ok {
		timer = gometrics.NewTimer()
		smb.timers[name] = timer
		smb.registry.Register(name, timer)
	}

	return timer
}
Example #9
0
// 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))
			}
		}
	}
}
Example #10
0
// SaveTiming indicates that we want to store an internal representation of all timings in this bucket so that we can
// query it (via GetTiming).
func (i *Instrumentation) SaveTiming(bucket string) error {
	i.mtx.Lock()
	defer i.mtx.Unlock()

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

	t := metrics.NewTimer()
	i.registry.Register(bucket, t)
	i.savedTimers[bucket] = t

	return nil
}
func NewUpstreamMetrics(upstreamId string) UpstreamMetrics {
	hm := NewHttpMetrics(fmt.Sprintf("vulcan.upstream.%s", upstreamId))
	um := UpstreamMetrics{
		Requests:  gmetrics.NewMeter(),
		Failovers: gmetrics.NewMeter(),
		Latency:   gmetrics.NewTimer(),
		Http:      &hm,
	}

	gmetrics.Register(fmt.Sprintf("vulcan.upstream.%s.requests", upstreamId), um.Requests)
	gmetrics.Register(fmt.Sprintf("vulcan.upstream.%s.latency", upstreamId), um.Failovers)
	gmetrics.Register(fmt.Sprintf("vulcan.upstream.%s.failovers", upstreamId), um.Failovers)

	return um
}
Example #12
0
func (m *Metrics) GetTimer(timerName string) gometrics.Timer {
	m.Lock()
	defer m.Unlock()

	prefixedTimerName := m.Prefix + "_" + timerName
	timer, exists := m.Timers[prefixedTimerName]
	if !exists {
		timer = gometrics.NewTimer()
		m.Registry.Register(prefixedTimerName, timer)

		m.Timers[prefixedTimerName] = timer
	}

	return m.Timers[prefixedTimerName]
}
Example #13
0
func TestHandler(t *testing.T) {
	gometrics.UseNilMetrics = true
	gometrics.Register("some.metric.key", gometrics.NewTimer())

	rw := httptest.NewRecorder()
	r, _ := http.NewRequest("GET", "http://example.com", nil)
	Default.ServeHTTP(rw, r)

	if rw.Code != http.StatusOK {
		t.Errorf("Metrics endpoint responded with wrong status code = %d", rw.Code)
	}

	if rw.Body.String() != testJSONMetrics {
		t.Errorf("Wrong metrics response. Want '%s', got '%s'", testJSONMetrics, rw.Body.String())
	}
}
Example #14
0
func (m *MeticsTimers) Measure(elapsed time.Duration, key string) {
	m.mu.RLock()
	t, ok := m.timers[key]
	m.mu.RUnlock()

	if !ok {
		m.mu.Lock()
		t, ok = m.timers[key]
		if !ok {
			t = mt.NewTimer()
			m.timers[key] = t
		}
		m.mu.Unlock()
	}

	t.Update(elapsed)
}
Example #15
0
func (m *timersDB) Measure(key string, start time.Time) {
	elapsed := time.Now().Sub(start)

	m.mu.RLock()
	t, ok := m.timers[key]
	m.mu.RUnlock()

	if !ok {
		m.mu.Lock()
		t, ok = m.timers[key]
		if !ok {
			t = mt.NewTimer()
			m.timers[key] = t
		}
		m.mu.Unlock()
	}

	t.Update(elapsed)
}
Example #16
0
func AddNegroniHttpMetrics(agent gonr.GonrAgent) negroni.HandlerFunc {
	responseTimer := metrics.NewTimer()

	nrmetrics.AddTimerMetric(agent.Plugin(), responseTimer, nrmetrics.MetricConfig{
		Name:        "HTTP/Response Time",
		Unit:        "requests",
		Duration:    time.Millisecond,
		Min:         true,
		Max:         true,
		Mean:        true,
		Percentiles: []float64{0.5, 0.75, 0.9, 0.99, 0.999},
		Rate1:       true,
		Rate5:       true,
		Rate15:      true,
	})

	return func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
		t := time.Now()

		next.ServeHTTP(rw, r)

		responseTimer.UpdateSince(t)
	}
}