-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update comment in OpenCensus example
Signed-off-by: Xabier Larrakoetxea <[email protected]>
- Loading branch information
Showing
2 changed files
with
61 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
prommiddleware "github.com/slok/go-prometheus-middleware" | ||
promgin "github.com/slok/go-prometheus-middleware/gin" | ||
) | ||
|
||
const ( | ||
srvAddr = ":8080" | ||
metricsAddr = ":8081" | ||
) | ||
|
||
func main() { | ||
// Create our middleware. | ||
mdlw := prommiddleware.NewDefault() | ||
|
||
// Create our gin instance. | ||
r := gin.New() | ||
|
||
// Add the middlewares to all gin routes. | ||
r.Use( | ||
promgin.Handler("", mdlw), | ||
gin.Logger(), | ||
) | ||
|
||
// Add our handler | ||
r.GET("/", func(c *gin.Context) { | ||
c.String(http.StatusOK, "Hello world!") | ||
}) | ||
|
||
// Serve our handler. | ||
go func() { | ||
log.Printf("server listening at %s", srvAddr) | ||
if err := r.Run(srvAddr); err != nil { | ||
log.Panicf("error while serving: %s", err) | ||
} | ||
}() | ||
|
||
// Serve our metrics. | ||
go func() { | ||
log.Printf("metrics listening at %s", metricsAddr) | ||
if err := http.ListenAndServe(metricsAddr, promhttp.Handler()); err != nil { | ||
log.Panicf("error while serving metrics: %s", err) | ||
} | ||
}() | ||
|
||
// Wait until some signal is captured. | ||
sigC := make(chan os.Signal, 1) | ||
signal.Notify(sigC, syscall.SIGTERM, syscall.SIGINT) | ||
<-sigC | ||
} |
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