Esempio n. 1
0
// addHTTPStatusMetricsToComponent initializes counter metrics for all http statuses and adds them to the component.
func addHTTPStatusMetricsToComponent(component baidu_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",
		})
	}
}
Esempio n. 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")
	}

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

	// 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 = baidu_platform_go.NewNewrelicPlugin(agent.AgentVersion, agent.NewrelicLicense, agent.NewrelicPollInterval)
	agent.plugin.Client = agent.Client
	agent.plugin.Verbose = agent.Verbose

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

	// Start reporting!
	go agent.plugin.Run()
	return nil
}
Esempio n. 3
0
func addGCMericsToComponent(component baidu_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)
	}
}
Esempio n. 4
0
func addRuntimeMericsToComponent(component baidu_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)
	}
}
Esempio n. 5
0
func (transaction *TraceTransaction) addMetricsToComponent(component baidu_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)
}
Esempio n. 6
0
func addHTTPMericsToComponent(component baidu_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)
}
Esempio n. 7
0
func addMemoryMericsToComponent(component baidu_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})
	}
}