Example #1
0
// addHTTPStatusMetricsToComponent initializes counter metrics for all http statuses and adds them to the component.
func addHTTPStatusMetricsToComponent(component newrelic_platform_go.IComponent, statusCounters map[int]metrics.Counter) {
	for statusCode, counter := range statusCounters {
		component.AddMetrica(&counterByStatusMetrica{
			counter: counter,
			name:    fmt.Sprintf("http/status/%d", statusCode),
			units:   "count",
		})
	}
}
Example #2
0
//Run initialize Agent instance and start harvest go routine
func (agent *Agent) Run() error {
	if agent.NewrelicLicense == "" {
		return errors.New("please, pass a valid newrelic license key")
	}

	agent.plugin = newrelic_platform_go.NewNewrelicPlugin(agent.AgentVersion, agent.NewrelicLicense, agent.NewrelicPollInterval)
	agent.plugin.Client = agent.Client

	var component newrelic_platform_go.IComponent
	component = newrelic_platform_go.NewPluginComponent(agent.NewrelicName, agent.AgentGUID)

	// Add default metrics and tracer.
	addRuntimeMericsToComponent(component)
	agent.Tracer = newTracer(component)

	// Check agent flags and add relevant metrics.
	if agent.CollectGcStat {
		addGCMericsToComponent(component, agent.GCPollInterval)
		agent.debug(fmt.Sprintf("Init GC metrics collection. Poll interval %d seconds.", agent.GCPollInterval))
	}

	if agent.CollectMemoryStat {
		addMemoryMericsToComponent(component, agent.MemoryAllocatorPollInterval)
		agent.debug(fmt.Sprintf("Init memory allocator metrics collection. Poll interval %d seconds.", agent.MemoryAllocatorPollInterval))
	}

	if agent.CollectHTTPStat {
		agent.initTimer()
		addHTTPMericsToComponent(component, agent.HTTPTimer)
		agent.debug(fmt.Sprintf("Init HTTP metrics collection."))
	}

	for _, metric := range agent.CustomMetrics {
		component.AddMetrica(metric)
		agent.debug(fmt.Sprintf("Init %s metric collection.", metric.GetName()))
	}

	if agent.CollectHTTPStatuses {
		agent.initStatusCounters()
		component = &resettableComponent{component, agent.HTTPStatusCounters}
		addHTTPStatusMetricsToComponent(component, agent.HTTPStatusCounters)
		agent.debug(fmt.Sprintf("Init HTTP status metrics collection."))
	}

	// Init newrelic reporting plugin.
	agent.plugin = newrelic_platform_go.NewNewrelicPlugin(agent.AgentVersion, agent.NewrelicLicense, agent.NewrelicPollInterval)
	agent.plugin.Verbose = agent.Verbose

	// Add our metrics component to the plugin.
	agent.plugin.AddComponent(component)

	// Start reporting!
	go agent.plugin.Run()
	return nil
}
Example #3
0
func addGCMericsToComponent(component newrelic_platform_go.IComponent, pollInterval int) {
	metrics := []*BaseGoMetrica{
		&BaseGoMetrica{
			name:          "NumberOfGCCalls",
			units:         "calls",
			dataSourceKey: "debug.GCStats.NumGC",
		},
		&BaseGoMetrica{
			name:          "PauseTotalTime",
			units:         "nanoseconds",
			dataSourceKey: "debug.GCStats.PauseTotal",
		},
	}

	ds := NewGCMetricaDataSource(pollInterval)
	for _, m := range metrics {
		m.basePath = "Runtime/GC/"
		m.dataSource = ds
		component.AddMetrica(&GaugeMetrica{m})
	}

	histogramMetrics := []*HistogramMetrica{
		&HistogramMetrica{
			statFunction:  HISTOGRAM_MAX,
			BaseGoMetrica: &BaseGoMetrica{name: "Max"},
		},
		&HistogramMetrica{
			statFunction:  HISTOGRAM_MIN,
			BaseGoMetrica: &BaseGoMetrica{name: "Min"},
		},
		&HistogramMetrica{
			statFunction:  HISTOGRAM_MEAN,
			BaseGoMetrica: &BaseGoMetrica{name: "Mean"},
		},
		&HistogramMetrica{
			statFunction:    HISTOGRAM_PERCENTILE,
			percentileValue: 0.95,
			BaseGoMetrica:   &BaseGoMetrica{name: "Percentile95"},
		},
	}
	for _, m := range histogramMetrics {
		m.BaseGoMetrica.units = "nanoseconds"
		m.BaseGoMetrica.dataSourceKey = "debug.GCStats.Pause"
		m.BaseGoMetrica.basePath = "Runtime/GC/GCTime/"
		m.BaseGoMetrica.dataSource = ds

		component.AddMetrica(m)
	}
}
Example #4
0
func addGCMericsToComponent(component newrelic_platform_go.IComponent, pollInterval int) {
	metrics := []*baseGoMetrica{
		&baseGoMetrica{
			name:          "NumberOfGCCalls",
			units:         "calls",
			dataSourceKey: "debug.GCStats.NumGC",
		},
		&baseGoMetrica{
			name:          "PauseTotalTime",
			units:         "nanoseconds",
			dataSourceKey: "debug.GCStats.PauseTotal",
		},
	}

	ds := newGCMetricaDataSource(pollInterval)
	for _, m := range metrics {
		m.basePath = "Runtime/GC/"
		m.dataSource = ds
		component.AddMetrica(&gaugeMetrica{m})
	}

	histogramMetrics := []*histogramMetrica{
		&histogramMetrica{
			statFunction:  histogramMax,
			baseGoMetrica: &baseGoMetrica{name: "Max"},
		},
		&histogramMetrica{
			statFunction:  histogramMin,
			baseGoMetrica: &baseGoMetrica{name: "Min"},
		},
		&histogramMetrica{
			statFunction:  histogramMean,
			baseGoMetrica: &baseGoMetrica{name: "Mean"},
		},
		&histogramMetrica{
			statFunction:    histogramPercentile,
			percentileValue: 0.95,
			baseGoMetrica:   &baseGoMetrica{name: "Percentile95"},
		},
	}
	for _, m := range histogramMetrics {
		m.baseGoMetrica.units = "nanoseconds"
		m.baseGoMetrica.dataSourceKey = "debug.GCStats.Pause"
		m.baseGoMetrica.basePath = "Runtime/GC/GCTime/"
		m.baseGoMetrica.dataSource = ds

		component.AddMetrica(m)
	}
}
// Helper func to add all our counter metrics to the plugin component
func addCounterMericsToComponent(component newrelic_platform_go.IComponent, counter metrics.Counter, counterName string) {

	// with CountedByStatus sampling, counterName looks like <prefix>-<status>
	// where prefix is the actual counter name, status is http status code
	strParts := strings.Split(counterName, "-")
	realCounterName := strParts[0]
	statusCode := strParts[1] // WARN: will panic on Counted sampling

	ctr := &statusCounterMetrica{
		baseCounterMetrica: &baseCounterMetrica{
			dataSource: counter,
			name:       realCounterName + "/http/status/" + statusCode,
			units:      "Count",
		},
	}
	component.AddMetrica(ctr)

}
Example #6
0
func addRuntimeMericsToComponent(component newrelic_platform_go.IComponent) {
	component.AddMetrica(&NOGoroutinesMetrica{})
	component.AddMetrica(&NOCgoCallsMetrica{})

	ds := NewSystemMetricaDataSource()
	metrics := []*SystemMetrica{
		&SystemMetrica{
			sourceKey:    "Threads",
			units:        "Threads",
			newrelicName: "Runtime/System/Threads",
		},
		&SystemMetrica{
			sourceKey:    "FDSize",
			units:        "fd",
			newrelicName: "Runtime/System/FDSize",
		},
		// Peak virtual memory size
		&SystemMetrica{
			sourceKey:    "VmPeak",
			units:        "bytes",
			newrelicName: "Runtime/System/Memory/VmPeakSize",
		},
		//Virtual memory size
		&SystemMetrica{
			sourceKey:    "VmSize",
			units:        "bytes",
			newrelicName: "Runtime/System/Memory/VmCurrent",
		},
		//Peak resident set size
		&SystemMetrica{
			sourceKey:    "VmHWM",
			units:        "bytes",
			newrelicName: "Runtime/System/Memory/RssPeak",
		},
		//Resident set size
		&SystemMetrica{
			sourceKey:    "VmRSS",
			units:        "bytes",
			newrelicName: "Runtime/System/Memory/RssCurrent",
		},
	}
	for _, m := range metrics {
		m.dataSource = ds
		component.AddMetrica(m)
	}
}
Example #7
0
func addHTTPMericsToComponent(component newrelic_platform_go.IComponent, timer metrics.Timer) {
	rate1 := &timerRate1Metrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       "http/throughput/1minute",
			units:      "rps",
			dataSource: timer,
		},
	}
	component.AddMetrica(rate1)

	rateMean := &timerRateMeanMetrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       "http/throughput/rateMean",
			units:      "rps",
			dataSource: timer,
		},
	}
	component.AddMetrica(rateMean)

	responseTimeMean := &timerMeanMetrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       "http/responseTime/mean",
			units:      "ms",
			dataSource: timer,
		},
	}
	component.AddMetrica(responseTimeMean)

	responseTimeMax := &timerMaxMetrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       "http/responseTime/max",
			units:      "ms",
			dataSource: timer,
		},
	}
	component.AddMetrica(responseTimeMax)

	responseTimeMin := &timerMinMetrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       "http/responseTime/min",
			units:      "ms",
			dataSource: timer,
		},
	}
	component.AddMetrica(responseTimeMin)

	responseTimePercentile75 := &timerPercentile75Metrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       "http/responseTime/percentile75",
			units:      "ms",
			dataSource: timer,
		},
	}
	component.AddMetrica(responseTimePercentile75)

	responseTimePercentile90 := &timerPercentile90Metrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       "http/responseTime/percentile90",
			units:      "ms",
			dataSource: timer,
		},
	}
	component.AddMetrica(responseTimePercentile90)

	responseTimePercentile95 := &timerPercentile95Metrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       "http/responseTime/percentile95",
			units:      "ms",
			dataSource: timer,
		},
	}
	component.AddMetrica(responseTimePercentile95)
}
Example #8
0
func addMemoryMericsToComponent(component newrelic_platform_go.IComponent, pollInterval int) {
	gaugeMetrics := []*baseGoMetrica{
		//Memory in use metrics
		&baseGoMetrica{
			name:          "InUse/Total",
			units:         "bytes",
			dataSourceKey: "runtime.MemStats.Alloc",
		},
		&baseGoMetrica{
			name:          "InUse/Heap",
			units:         "bytes",
			dataSourceKey: "runtime.MemStats.HeapAlloc",
		},
		&baseGoMetrica{
			name:          "InUse/Stack",
			units:         "bytes",
			dataSourceKey: "runtime.MemStats.StackInuse",
		},
		&baseGoMetrica{
			name:          "InUse/MSpanInuse",
			units:         "bytes",
			dataSourceKey: "runtime.MemStats.MSpanInuse",
		},
		&baseGoMetrica{
			name:          "InUse/MCacheInuse",
			units:         "bytes",
			dataSourceKey: "runtime.MemStats.MCacheInuse",
		},
	}
	ds := newMemoryMetricaDataSource(pollInterval)
	for _, m := range gaugeMetrics {
		m.basePath = "Runtime/Memory/"
		m.dataSource = ds
		component.AddMetrica(&gaugeMetrica{m})
	}

	gaugeIncMetrics := []*baseGoMetrica{
		//NO operations graph
		&baseGoMetrica{
			name:          "Operations/NoPointerLookups",
			units:         "lookups",
			dataSourceKey: "runtime.MemStats.Lookups",
		},
		&baseGoMetrica{
			name:          "Operations/NoMallocs",
			units:         "mallocs",
			dataSourceKey: "runtime.MemStats.Mallocs",
		},
		&baseGoMetrica{
			name:          "Operations/NoFrees",
			units:         "frees",
			dataSourceKey: "runtime.MemStats.Frees",
		},

		// Sytem memory allocations
		&baseGoMetrica{
			name:          "SysMem/Total",
			units:         "bytes",
			dataSourceKey: "runtime.MemStats.Sys",
		},
		&baseGoMetrica{
			name:          "SysMem/Heap",
			units:         "bytes",
			dataSourceKey: "runtime.MemStats.HeapSys",
		},
		&baseGoMetrica{
			name:          "SysMem/Stack",
			units:         "bytes",
			dataSourceKey: "runtime.MemStats.StackSys",
		},
		&baseGoMetrica{
			name:          "SysMem/MSpan",
			units:         "bytes",
			dataSourceKey: "runtime.MemStats.MSpanSys",
		},
		&baseGoMetrica{
			name:          "SysMem/MCache",
			units:         "bytes",
			dataSourceKey: "runtime.MemStats.MCacheSys",
		},
		&baseGoMetrica{
			name:          "SysMem/BuckHash",
			units:         "bytes",
			dataSourceKey: "runtime.MemStats.BuckHashSys",
		},
	}

	for _, m := range gaugeIncMetrics {
		m.basePath = "Runtime/Memory/"
		m.dataSource = ds
		component.AddMetrica(&gaugeIncMetrica{baseGoMetrica: m})
	}
}
Example #9
0
func (transaction *TraceTransaction) addMetricsToComponent(component newrelic_platform_go.IComponent) {

	rate1 := &timerRate1Metrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       transaction.name + "/throughput/1minute",
			units:      "rps",
			dataSource: transaction.timer,
		},
	}
	component.AddMetrica(rate1)

	rateMean := &timerRateMeanMetrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       transaction.name + "/throughput/rateMean",
			units:      "rps",
			dataSource: transaction.timer,
		},
	}
	component.AddMetrica(rateMean)

	tracerMean := &timerMeanMetrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       transaction.name + "/responseTime/mean",
			units:      "ms",
			dataSource: transaction.timer,
		},
	}
	component.AddMetrica(tracerMean)

	tracerMax := &timerMaxMetrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       transaction.name + "/responseTime/max",
			units:      "ms",
			dataSource: transaction.timer,
		},
	}
	component.AddMetrica(tracerMax)

	tracerMin := &timerMinMetrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       transaction.name + "/responseTime/min",
			units:      "ms",
			dataSource: transaction.timer,
		},
	}
	component.AddMetrica(tracerMin)

	tracer75 := &timerPercentile75Metrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       transaction.name + "/responseTime/percentile75",
			units:      "ms",
			dataSource: transaction.timer,
		},
	}
	component.AddMetrica(tracer75)

	tracer90 := &timerPercentile90Metrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       transaction.name + "/responseTime/percentile90",
			units:      "ms",
			dataSource: transaction.timer,
		},
	}
	component.AddMetrica(tracer90)

	tracer95 := &timerPercentile95Metrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       transaction.name + "/responseTime/percentile95",
			units:      "ms",
			dataSource: transaction.timer,
		},
	}
	component.AddMetrica(tracer95)

	tracer99 := &timerPercentile99Metrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       transaction.name + "/responseTime/percentile99",
			units:      "ms",
			dataSource: transaction.timer,
		},
	}
	component.AddMetrica(tracer99)
}
Example #10
0
func (transaction *TraceTransaction) addMetricsToComponent(component newrelic_platform_go.IComponent) {
	tracerMean := &timerMeanMetrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       transaction.name + "/mean",
			units:      "ms",
			dataSource: transaction.timer,
		},
	}
	component.AddMetrica(tracerMean)

	tracerMax := &timerMaxMetrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       transaction.name + "/max",
			units:      "ms",
			dataSource: transaction.timer,
		},
	}
	component.AddMetrica(tracerMax)

	tracerMin := &timerMinMetrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       transaction.name + "/min",
			units:      "ms",
			dataSource: transaction.timer,
		},
	}
	component.AddMetrica(tracerMin)

	tracer75 := &timerPercentile75Metrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       transaction.name + "/percentile75",
			units:      "ms",
			dataSource: transaction.timer,
		},
	}
	component.AddMetrica(tracer75)

	tracer90 := &timerPercentile90Metrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       transaction.name + "/percentile90",
			units:      "ms",
			dataSource: transaction.timer,
		},
	}
	component.AddMetrica(tracer90)

	tracer95 := &timerPercentile95Metrica{
		baseTimerMetrica: &baseTimerMetrica{
			name:       transaction.name + "/percentile95",
			units:      "ms",
			dataSource: transaction.timer,
		},
	}
	component.AddMetrica(tracer95)
}