-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgorelic.go
38 lines (29 loc) · 791 Bytes
/
gorelic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package gorelic
import (
"fmt"
"github.com/jrallison/go-workers"
metrics "github.com/yvasiyarov/go-metrics"
"github.com/yvasiyarov/gorelic"
"time"
)
var agent *gorelic.Agent
type GorelicMiddleware struct{}
func (r *GorelicMiddleware) Call(queue string, message *workers.Msg, next func() bool) (acknowledge bool) {
startTime := time.Now()
acknowledge = next()
agent.HTTPTimer.UpdateSince(startTime)
return
}
func InitNewrelicAgent(license string, appname string, verbose bool) 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
agent.Run()
return nil
}