github.com/mundipagg/boleto-api@v0.0.0-20230620145841-3f9ec742599f/api/monitor.go (about)

     1  package api
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/gin-gonic/gin"
     7  	"github.com/mundipagg/boleto-api/config"
     8  	"github.com/mundipagg/boleto-api/metrics"
     9  	"github.com/newrelic/go-agent/v3/integrations/nrgin"
    10  	"github.com/newrelic/go-agent/v3/newrelic"
    11  )
    12  
    13  //Memory HealthCheck com relatório de memória
    14  func memory(c *gin.Context) {
    15  	unit := c.Param("unit")
    16  	c.JSON(200, metrics.GetMemoryReport(unit))
    17  }
    18  
    19  func useNewRelic(router *gin.Engine) {
    20  	if !config.Get().TelemetryEnabled {
    21  		return
    22  	}
    23  	app, _ := newrelic.NewApplication(
    24  		newrelic.ConfigAppName(config.Get().NewRelicAppName),
    25  		newrelic.ConfigLicense(config.Get().NewRelicLicence),
    26  		newrelic.ConfigDistributedTracerEnabled(true),
    27  	)
    28  	router.Use(nrgin.Middleware(app))
    29  }
    30  
    31  func timingMetrics() gin.HandlerFunc {
    32  	return func(c *gin.Context) {
    33  		start := time.Now()
    34  		c.Next()
    35  		end := time.Now()
    36  		total := end.Sub(start)
    37  		s := float64(total.Seconds())
    38  		metrics.PushTimingMetric("request-time", s)
    39  	}
    40  }