This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Metrics handler collects status metrics. | |
func StatusMetrics() gin.HandlerFunc { | |
return func(c *gin.Context) { | |
statusCode := c.Writer.Status() | |
metrics.GetOrRegisterMeter("call."+getHandlerName(c)+".Status."+strconv.Itoa(statusCode), nil).Mark(1) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router := gin.New() | |
router.Use(StatusMetrics()) // now we will collect metric for number of reples for a status | |
if logFile != nil { | |
router.Use(gin.LoggerWithWriter(logFile)) | |
router.Use(gin.RecoveryWithWriter(logFile)) | |
} else { | |
router.Use(gin.Logger()) | |
router.Use(gin.Recovery()) | |
} | |
router.Use(Metrics()) // now we will publish metrics for each API call |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create router and register basic handlers | |
router := gin.New() | |
if logFile != nil { | |
router.Use(gin.LoggerWithWriter(logFile)) | |
router.Use(gin.RecoveryWithWriter(logFile)) | |
} else { | |
router.Use(gin.Logger()) | |
router.Use(gin.Recovery()) | |
} | |
router.Use(Metrics()) // now we will publish metrics for each API call |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Metrics handler collects metrics about registered handlers: | |
// latency, requests count, request and response size etc. | |
func Metrics() gin.HandlerFunc { | |
return func(c *gin.Context) { | |
path := getHandlerName(c) | |
timerMetric := metrics.GetOrRegisterTimer("call."+path+".Latency", nil) | |
start := time.Now() | |
c.Next() | |
timerMetric.UpdateSince(start) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create router and register basic handlers | |
router := gin.New() | |
if logFile != nil { | |
router.Use(gin.LoggerWithWriter(logFile)) | |
router.Use(gin.RecoveryWithWriter(logFile)) | |
} else { | |
router.Use(gin.Logger()) | |
router.Use(gin.Recovery()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create router and register basic handlers | |
router := gin.New() | |
if logFile != nil { | |
router.Use(gin.LoggerWithWriter(logFile)) | |
router.Use(gin.RecoveryWithWriter(logFile)) | |
} else { | |
router.Use(gin.Logger()) | |
router.Use(gin.Recovery()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// publish metrics every minute to graphite at 'graphite.mycompany.com:2003' | |
// 'application_name' is a prefix for this application metrics | |
addr, _ := net.ResolveTCPAddr("tcp", "graphite.mycompany.com:2003") | |
go graphite.Graphite(metrics.DefaultRegistry, 1*time.Minute, "application_name", addr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final AggregatedLogData logData = new AggregatedLogData(); | |
logData.setLevel(AggregatedLogLevel.FULL); | |
boolean error = false; | |
try { | |
// .. execute code here | |
} catch (Exception e) { | |
logData.collectException("Failed to process rules", e); | |
error = true; | |
} finally { | |
if (error) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final AggregatedLogData logData = new AggregatedLogData(); | |
logData.setLevel(AggregatedLogLevel.FULL); | |
try { | |
// .. execute code here | |
} catch (Exception e) { | |
log.error("Failed to process rules", e); | |
} finally { | |
log.info(logData.toJsonString()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
2017-01-01 02:23:01 [Req#123] [INFO] [TrafficLightIsGreenRule] trafficLightState=green | |
... | |
2017-01-01 02:23:01 [Req#123] [INFO] [TrafficLightIsRedRule] trafficLightState=green | |
... |
NewerOlder