コード例 #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",
		})
	}
}
コード例 #2
0
ファイル: agent.go プロジェクト: benjaminbollen/eris-pm
//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
}
コード例 #3
0
ファイル: gc_metrics.go プロジェクト: benjaminbollen/eris-pm
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)
	}
}
コード例 #4
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)
}
コード例 #5
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)
}