Skip to content

chenyangguang/bgprom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Beego project with prometheus monitor.

Install && import

  • Create a project with bee tool.
bee new bgprom 
  • Add promhttp
package main

import (
	_ "github.com/chenyangguang/bgprom/routers"
	"github.com/astaxie/beego"
    "github.com/prometheus/client_golang/prometheus/promhttp"
)

func main() {
    beego.Handler("/metrics", promhttp.Handler())
	beego.Run()
}

to the main.go.

Run

bee run 

Access http://localhost:8080/metrics in browser.

Add Counter for test

New a controller and import "github.com/prometheus/client_golang/prometheus" .

the test controller should look like this:

var (
	codeCounter = prometheus.NewCounter(
		prometheus.CounterOpts{
			Name: "http_request_total_code",
			Help: "total request code controller",
		},
	)
)
type CodeController struct {
	beego.Controller
}
func init() {
	prometheus.MustRegister(codeCounter)
}
func (c *CodeController) Get() {
	codeCounter.Inc()
	c.TplName = "code.tpl"
}
...
# HELP http_request_total_code total request code controller
# TYPE http_request_total_code counter
http_request_total_code 0
...

it means works!

...
# HELP http_request_total_code total request code controller
# TYPE http_request_total_code counter
http_request_total_code 1
...

Well done! Other types are similar(like Summary, Gauge, Histogram, SummaryVec and so on).

todo

  • Add base prometheus metric

About

beego project with prometheus motinor

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published