Add prometheus endpoint for getting metrics #33

Merged
konrad merged 25 commits from feature/metrics into master 2018-12-12 22:50:36 +00:00
5 changed files with 37 additions and 16 deletions
Showing only changes of commit c374117b93 - Show all commits

View File

@ -10,6 +10,7 @@ service:
# The number of items which gets returned per page # The number of items which gets returned per page
pagecount: 50 pagecount: 50
# If set to true, enables a /metrics endpoint for prometheus to collect metrics about the system # If set to true, enables a /metrics endpoint for prometheus to collect metrics about the system
# You'll need to use redis for this in order to enable common metrics over multiple nodes
emablemetrics: false emablemetrics: false
database: database:

View File

@ -36,6 +36,7 @@ service:
# The number of items which gets returned per page # The number of items which gets returned per page
pagecount: 50 pagecount: 50
# If set to true, enables a /metrics endpoint for prometheus to collect metrics about the system # If set to true, enables a /metrics endpoint for prometheus to collect metrics about the system
# You'll need to use redis for this in order to enable common metrics over multiple nodes
emablemetrics: false emablemetrics: false
database: database:

View File

@ -22,30 +22,36 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/client_golang/prometheus/promauto"
) )
/*
func RecordListCountMetrics() { func RecordListCountMetrics() {
go func() { go func() {
for { for {
listCountMetric.Set(float64(ListCount)) listCountMetric.Set(float64(<-ListCount))
} }
}() }()
}*/ }
var ( var (
//ListCount chan int64 ListCount chan int64
ListCount int64 ListCountUpdate chan int64
//ListCount int64
listCountMetric = promauto.NewGaugeFunc(prometheus.GaugeOpts{ listCountMetric = promauto.NewGauge(prometheus.GaugeOpts{
Name: "vikunja_list_count",
Help: "The number of lists on this node",
})
/* listCountMetric = promauto.NewGaugeFunc(prometheus.GaugeOpts{
Name: "vikunja_list_count", Name: "vikunja_list_count",
Help: "The number of lists on this node", Help: "The number of lists on this node",
}, func() float64 { }, func() float64 {
return float64(ListCount) return float64(ListCount)
}) })*/
) )
func UpdateListCount(update int64) { func UpdateListCount(update int64) {
fmt.Println("updated ", update) //ListCount += update
ListCount += update ccnt := <-ListCountUpdate // Why does this block and does not give us the data?
//ccnt := <-ListCount // Why does this block and does not give us the data? fmt.Println(ccnt)
//ListCount<- ccnt + update ListCount <- ccnt + update
ListCountUpdate <- ccnt + update
} }

View File

@ -21,6 +21,14 @@ func init() {
AllActiveUsers = []ActiveUser{} AllActiveUsers = []ActiveUser{}
// List count // List count
//ListCount = make(chan int64) ListCount = make(chan int64)
ListCount = 0 ListCountUpdate = make(chan int64)
//ListCount = 0
/* More Metrics:
* Total Users
* Total Namespaces
* Total Tasks
* Total Shares?
*/
} }

View File

@ -117,13 +117,18 @@ func RegisterRoutes(e *echo.Echo) {
// Prometheus endpoint // Prometheus endpoint
if viper.GetBool("service.emablemetrics") { if viper.GetBool("service.emablemetrics") {
//metrics.RecordListCountMetrics()
// TODO: Implement metrics via redis
metrics.RecordListCountMetrics()
total, err := models.GetTotalListCount() total, err := models.GetTotalListCount()
if err != nil { if err != nil {
log.Log.Fatal("Could not set initial list count", err) log.Log.Fatal("Could not set initial list count", err)
} }
//metrics.ListCount <- total go metrics.UpdateListCount(total)
metrics.ListCount = total //metrics.ListCountUpdate<- total
//metrics.ListCount<- total
//metrics.ListCount = total
a.GET("/metrics", echo.WrapHandler(promhttp.Handler())) a.GET("/metrics", echo.WrapHandler(promhttp.Handler()))
} }