Add prometheus endpoint for getting metrics #33
|
@ -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:
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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?
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user