Add prometheus endpoint for getting metrics #33
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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?
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
go metrics.UpdateListCount(total)
|
||||
//metrics.ListCountUpdate<- total
|
||||
//metrics.ListCount<- total
|
||||
metrics.ListCount = total
|
||||
//metrics.ListCount = total
|
||||
|
||||
a.GET("/metrics", echo.WrapHandler(promhttp.Handler()))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user