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
pagecount: 50
# 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
database:

View File

@ -36,6 +36,7 @@ service:
# The number of items which gets returned per page
pagecount: 50
# 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
database:

View File

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

View File

@ -21,6 +21,14 @@ func init() {
AllActiveUsers = []ActiveUser{}
// List count
//ListCount = make(chan int64)
ListCount = 0
ListCount = make(chan int64)
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
if viper.GetBool("service.emablemetrics") {
//metrics.RecordListCountMetrics()
// TODO: Implement metrics via redis
metrics.RecordListCountMetrics()
total, err := models.GetTotalListCount()
if err != nil {
log.Log.Fatal("Could not set initial list count", err)
}
//metrics.ListCount <- total
metrics.ListCount = total
go metrics.UpdateListCount(total)
//metrics.ListCountUpdate<- total
//metrics.ListCount<- total
//metrics.ListCount = total
a.GET("/metrics", echo.WrapHandler(promhttp.Handler()))
}