// InitNewRelicAgent initializes a new gorelic agent for usage in Handler func InitNewRelicAgent(license string, appname string, verbose bool) (*gorelic.Agent, error) { if license == "" { return gorelic.NewAgent(), fmt.Errorf("Please specify a NewRelic license") } agent = gorelic.NewAgent() agent.NewrelicLicense = license agent.NewrelicName = appname agent.HTTPTimer = metrics.NewTimer() agent.CollectHTTPStat = true agent.Verbose = verbose agent.Run() return agent, nil }
// NewrelicAgentMiddleware inits gorelic's NewRelic object and returns handler function func NewrelicAgentMiddleware(license string, appname string, verbose bool) gin.HandlerFunc { var agent *gorelic.Agent if license == "" { return nil } agent = gorelic.NewAgent() agent.NewrelicLicense = license agent.HTTPTimer = metrics.NewTimer() agent.CollectHTTPStat = true agent.Verbose = verbose agent.NewrelicName = appname agent.Run() return func(c *gin.Context) { startTime := time.Now() c.Next() if agent != nil { agent.HTTPTimer.UpdateSince(startTime) } } }
//Initialize global metrics.Timer object, used to collect HTTP metrics func (agent *Agent) initTimer() { if agent.HTTPTimer == nil { agent.HTTPTimer = metrics.NewTimer() } agent.CollectHTTPStat = true }
func (t *Tracer) BeginTrace(name string) *Trace { tracerName := "Trace/" + name m := t.metrics[tracerName] if m == nil { t.metrics[tracerName] = &TraceTransaction{tracerName, metrics.NewTimer()} m = t.metrics[tracerName] m.addMetricsToComponent(t.component) } return &Trace{m, time.Now()} }
func NewRelic(license string, appname string, verbose bool) gin.HandlerFunc { agent = gorelic.NewAgent() agent.NewrelicLicense = license agent.HTTPTimer = metrics.NewTimer() agent.CollectHTTPStat = true agent.Verbose = verbose agent.NewrelicName = appname agent.Run() return func(c *gin.Context) { startTime := time.Now() c.Next() agent.HTTPTimer.UpdateSince(startTime) } }
func InitNewrelicAgent(license string, appname string, verbose bool) error { if license == "" { return fmt.Errorf("Please specify baidu license") } agent = gobaidu.NewAgent() agent.NewrelicLicense = license agent.HTTPTimer = metrics.NewTimer() agent.CollectHTTPStat = true agent.Verbose = verbose agent.NewrelicName = appname agent.Run() return nil }
// InitNewrelicAgent creates the new relic agent func InitNewrelicAgent(license string, appname string, verbose bool, customCounters map[string]string) error { if license == "" { return fmt.Errorf("Please specify NewRelic license") } agent = gorelic.NewAgent() agent.NewrelicLicense = license agent.HTTPTimer = metrics.NewTimer() agent.CollectHTTPStat = true agent.Verbose = verbose agent.NewrelicName = appname for k, v := range customCounters { simpleCountersMap[k] = &SimpleCounter{name: k, units: v} agent.AddCustomMetric(simpleCountersMap[k]) } agent.Run() return nil }
func InitNewrelicAgent() { license := beego.AppConfig.String("NewrelicLicense") if license == "" { beego.Warn("Please specify NewRelic license in the application config: NewrelicLicense=7bceac019c7dcafae1ef95be3e3a3ff8866de245") return } agent = gorelic.NewAgent() agent.NewrelicLicense = license agent.HTTPTimer = metrics.NewTimer() agent.CollectHTTPStat = true if beego.RunMode == "dev" { agent.Verbose = true } if verbose, err := beego.AppConfig.Bool("NewrelicVerbose"); err == nil { agent.Verbose = verbose } nameParts := []string{beego.AppConfig.String("appname")} switch strings.ToLower(beego.AppConfig.String("NewrelicAppnameRunmode")) { case "append": nameParts = append(nameParts, beego.RunMode) case "prepend": nameParts = append([]string{beego.RunMode}, nameParts...) } agent.NewrelicName = strings.Join(nameParts, SEPARATOR) agent.Run() beego.InsertFilter("*", beego.BeforeRouter, InitNewRelicTimer, false) beego.InsertFilter("*", beego.FinishRouter, ReportMetricsToNewrelic, false) beego.Info("NewRelic agent started") }
//Initialize global metrics.Timer object, used to collect HTTP metrics func (agent *Agent) initTimer() { if agent.HTTPTimer == nil { agent.HTTPTimer = metrics.NewTimer() } }