コード例 #1
0
ファイル: histogram.go プロジェクト: neocortical/nrmetrics
// AddHistogramMetric Adds various metrics based on a Histogram, according to the supplied
// MetricConfig
func AddHistogramMetric(plugin *newrelic.Plugin, histo metrics.Histogram, config MetricConfig) {
	durString := parseDuration(config.Duration)
	unitSingular := singularize(config.Unit)
	units := durString + "/" + unitSingular
	if config.Count {
		plugin.AddMetric(newrelic.NewMetric(config.Name+"/Totals/Count", config.Unit, func() (float64, error) { return float64(histo.Snapshot().Count()), nil }))
	}
	if config.Min {
		plugin.AddMetric(newrelic.NewMetric(config.Name+"/Stats/Min", durString, func() (float64, error) { return float64(histo.Snapshot().Min() / int64(config.Duration)), nil }))
	}
	if config.Max {
		plugin.AddMetric(newrelic.NewMetric(config.Name+"/Stats/Max", durString, func() (float64, error) { return float64(histo.Snapshot().Max() / int64(config.Duration)), nil }))
	}
	if config.Mean {
		plugin.AddMetric(newrelic.NewMetric(config.Name+"/Rate/Mean", units, func() (float64, error) { return histo.Snapshot().Mean() / float64(config.Duration), nil }))
	}
	for _, pct := range config.Percentiles {
		if pct == 0.5 {
			localPct := pct
			plugin.AddMetric(newrelic.NewMetric(config.Name+"/Rate/Median", units, func() (float64, error) { return histo.Snapshot().Percentile(localPct) / float64(config.Duration), nil }))
		} else {
			localPct := pct
			plugin.AddMetric(newrelic.NewMetric(config.Name+"/Rate/"+pctToA(pct), units, func() (float64, error) { return histo.Snapshot().Percentile(localPct) / float64(config.Duration), nil }))
		}
	}
	if config.StdDev {
		plugin.AddMetric(newrelic.NewMetric(config.Name+"/Stats/Std Dev", durString, func() (float64, error) { return histo.Snapshot().StdDev() / float64(config.Duration), nil }))
	}
	if config.Sum {
		plugin.AddMetric(newrelic.NewMetric(config.Name+"/Totals/Sum", durString, func() (float64, error) { return float64(histo.Snapshot().Sum() / int64(config.Duration)), nil }))
	}
	if config.Variance {
		plugin.AddMetric(newrelic.NewMetric(config.Name+"/Stats/Variance", durString, func() (float64, error) { return histo.Snapshot().Variance() / float64(config.Duration), nil }))
	}
}
コード例 #2
0
ファイル: meter.go プロジェクト: neocortical/nrmetrics
// AddMeterMetric Adds various metrics based on a Meter, according to the supplied
// MetricConfig
func AddMeterMetric(plugin *newrelic.Plugin, meter metrics.Meter, config MetricConfig) {
	if config.Count {
		plugin.AddMetric(newrelic.NewMetric(config.Name+"/Totals/Count", config.Unit, func() (float64, error) { return float64(meter.Snapshot().Count()), nil }))
	}
	if config.Rate1 {
		plugin.AddMetric(newrelic.NewMetric(config.Name+"/Rate/1 Min. Rate", config.Unit+"/second", func() (float64, error) { return meter.Snapshot().Rate1(), nil }))
	}
	if config.Rate5 {
		plugin.AddMetric(newrelic.NewMetric(config.Name+"/Rate/5 Min. Rate", config.Unit+"/second", func() (float64, error) { return meter.Snapshot().Rate5(), nil }))
	}
	if config.Rate15 {
		plugin.AddMetric(newrelic.NewMetric(config.Name+"/Rate/15 Min. Rate", config.Unit+"/second", func() (float64, error) { return meter.Snapshot().Rate15(), nil }))
	}
	if config.RateMean {
		plugin.AddMetric(newrelic.NewMetric(config.Name+"/Rate/Mean Rate", config.Unit+"/second", func() (float64, error) { return meter.Snapshot().RateMean(), nil }))
	}
}
コード例 #3
0
ファイル: runtime.go プロジェクト: neocortical/gonr
func addRuntimeMetrics(p *newrelic.Plugin) {
	p.AddMetric(newrelic.NewMetric("Runtime/Events/Goroutines", "goroutines", func() (float64, error) { return float64(runtime.NumGoroutine()), nil }))

	var lastNumCgoCall int64
	p.AddMetric(newrelic.NewMetric("Runtime/Events/CGO Calls", "calls", func() (float64, error) {
		currentNumCgoCall := runtime.NumCgoCall()
		result := float64(currentNumCgoCall - lastNumCgoCall)
		lastNumCgoCall = currentNumCgoCall
		return result, nil
	}))

	threads := metrics.NewGauge()
	fdsize := metrics.NewGauge()
	vmpeak := metrics.NewGauge()
	vmsize := metrics.NewGauge()
	rsspeak := metrics.NewGauge()
	rsssize := metrics.NewGauge()
	pr := &procReader{
		sampleRate: time.Second * 5,
		procMap:    make(map[string]string),
		threads:    threads,
		fdsize:     fdsize,
		vmpeak:     vmpeak,
		vmsize:     vmsize,
		rsspeak:    rsspeak,
		rsssize:    rsssize,
	}
	pr.Run()

	nrmetrics.AddGaugeMetric(p, threads, nrmetrics.MetricConfig{Name: "Runtime/Threads", Unit: "threads", Count: true})
	nrmetrics.AddGaugeMetric(p, fdsize, nrmetrics.MetricConfig{Name: "Runtime/FD Size", Unit: "file descriptor slots", Count: true})
	nrmetrics.AddGaugeMetric(p, vmpeak, nrmetrics.MetricConfig{Name: "Runtime/Peak Virt Mem", Unit: "bytes", Count: true})
	nrmetrics.AddGaugeMetric(p, vmsize, nrmetrics.MetricConfig{Name: "Runtime/Virt Mem", Unit: "bytes", Count: true})
	nrmetrics.AddGaugeMetric(p, rsspeak, nrmetrics.MetricConfig{Name: "Runtime/RSS Peak", Unit: "bytes", Count: true})
	nrmetrics.AddGaugeMetric(p, rsssize, nrmetrics.MetricConfig{Name: "Runtime/RSS Size", Unit: "bytes", Count: true})
}
コード例 #4
0
ファイル: gauge.go プロジェクト: neocortical/nrmetrics
// AddGaugeMetric Adds various metrics based on a Gauge, according to the supplied
// MetricConfig.
func AddGaugeMetric(plugin *newrelic.Plugin, gauge metrics.Gauge, config MetricConfig) {
	if config.Value {
		plugin.AddMetric(newrelic.NewMetric(config.Name+"/Value", config.Unit, func() (float64, error) { return float64(gauge.Snapshot().Value()), nil }))
	}
}
コード例 #5
0
ファイル: counter.go プロジェクト: neocortical/nrmetrics
// AddCounterMetric Adds various metrics based on a Counter, according to the supplied
// MetricConfig
func AddCounterMetric(plugin *newrelic.Plugin, counter metrics.Counter, config MetricConfig) {
	if config.Count {
		plugin.AddMetric(newrelic.NewMetric(config.Name+"/Count", config.Unit, func() (float64, error) { return float64(counter.Snapshot().Count()), nil }))
	}
}