Exemplo n.º 1
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
}
Exemplo n.º 2
0
//Run initialize Agent instance and start harvest go routine
func (agent *StandardAgent) 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)
	component := newrelic_platform_go.NewPluginComponent(agent.NewrelicName, agent.AgentGUID)
	agent.plugin.AddComponent(component)

	addRuntimeMericsToComponent(component)

	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."))
	}

	agent.plugin.Verbose = agent.Verbose
	go agent.plugin.Run()
	return nil
}
func main() {
	config := HandleUserOptions()

	hostName, err := os.Hostname()
	if err != nil {
		log.Fatal(err)
	}

	plugin := platform.NewNewrelicPlugin("0.0.1", config.newRelicKey, config.interval*60)

	plugin.AddComponent(InitSingleSamplesComponent(hostName, config.verbose))
	plugin.AddComponent(InitDynamicSamplesComponent(hostName, config.verbose))

	plugin.Verbose = config.verbose
	plugin.Run()
}
Exemplo n.º 4
0
func main() {
	plugin := newrelic_platform_go.NewNewrelicPlugin("0.0.1", "7bceac019c7dcafae1ef95be3e3a3ff8866de246", 60)
	component := newrelic_platform_go.NewPluginComponent("Wave component", "com.exmaple.plugin.gowave")
	plugin.AddComponent(component)

	m := &WaveMetrica{
		sawtoothMax:     10,
		sawtoothCounter: 5,
	}
	component.AddMetrica(m)

	m1 := &SquareWaveMetrica{
		squarewaveMax:     4,
		squarewaveCounter: 1,
	}
	component.AddMetrica(m1)

	plugin.Verbose = true
	plugin.Run()
}
Exemplo n.º 5
0
func main() {
	config := HandleUserOptions()

	db, err := OpenDatabaseConnection(config.database, config.user)
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	hostName, err := os.Hostname()
	if err != nil {
		log.Fatal(err)
	}

	plugin := platform.NewNewrelicPlugin("0.0.1", config.newRelicKey, config.interval*60)
	plugin.AddComponent(InitTupleComponent(db, hostName, config.verbose))
	plugin.AddComponent(InitTupleSummaryComponent(db, hostName, config.verbose))
	plugin.AddComponent(InitTableSizeComponent(db, hostName, config.verbose))

	plugin.Verbose = config.verbose
	plugin.Run()
}
Exemplo n.º 6
0
// TODO: drop appname
func InitNewrelicAgent(license string, appname string, verbose bool, obs Observable) error {

	if license == "" {
		return fmt.Errorf("Please specify NewRelic license")
	}

	plugin := newrelic_platform_go.NewNewrelicPlugin(CurrentAgentVersion, license, PollInterval)
	component := newrelic_platform_go.NewPluginComponent(DefaultAgentName, DefaultAgentGuid)
	plugin.AddComponent(component)

	m := &MembersMetrica{obs}

	component.AddMetrica(m)

	f := &FailuresMetrica{obs}

	component.AddMetrica(f)

	plugin.Verbose = verbose
	go plugin.Run()
	return nil
}
Exemplo n.º 7
0
// Run initialize Agent instance and start harvest go routine
func (agent *Agent) Run() error {

	if agent.NewrelicLicense == "" {
		return errors.New("Cannot start NewRelic agent, pass a valid license key")
	}

	agent.plugin = newrelic_platform_go.NewNewrelicPlugin(agent.AgentVersion, agent.NewrelicLicense, agent.NewrelicPollInterval)
	component := newrelic_platform_go.NewPluginComponent(agent.NewrelicName, agent.AgentGUID)
	agent.plugin.AddComponent(component)
	registry := metrics.DefaultRegistry
	registry.Each(func(name string, i interface{}) {
		switch metric := i.(type) {
		case metrics.Timer:
			addTimerMericsToComponent(component, metric, name)
		case metrics.Counter:
			addCounterMericsToComponent(component, metric, name)
		}
	})

	agent.plugin.Verbose = agent.Verbose
	go agent.plugin.Run()
	return nil
}