Fixed metrics endpoint not working
This commit is contained in:
parent
3d7fd9ca20
commit
de24fcc2f8
5 changed files with 41 additions and 23 deletions
|
@ -18,6 +18,11 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/config"
|
"code.vikunja.io/api/pkg/config"
|
||||||
|
"code.vikunja.io/api/pkg/log"
|
||||||
|
"code.vikunja.io/api/pkg/mail"
|
||||||
|
"code.vikunja.io/api/pkg/migration"
|
||||||
|
"code.vikunja.io/api/pkg/models"
|
||||||
|
"code.vikunja.io/api/pkg/red"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"os"
|
"os"
|
||||||
|
@ -27,7 +32,7 @@ import (
|
||||||
var Version = "0.1"
|
var Version = "0.1"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cobra.OnInitialize(config.InitConfig)
|
cobra.OnInitialize(initialize)
|
||||||
}
|
}
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
|
@ -52,3 +57,27 @@ func Execute() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initializes all kinds of things in the right order
|
||||||
|
func initialize() {
|
||||||
|
// Init the config
|
||||||
|
config.InitConfig()
|
||||||
|
|
||||||
|
// Init redis
|
||||||
|
red.InitRedis()
|
||||||
|
|
||||||
|
// Set logger
|
||||||
|
log.InitLogger()
|
||||||
|
|
||||||
|
// Run the migrations
|
||||||
|
migration.Migrate(nil)
|
||||||
|
|
||||||
|
// Set Engine
|
||||||
|
err := models.SetEngine()
|
||||||
|
if err != nil {
|
||||||
|
log.Log.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the mail daemon
|
||||||
|
mail.StartMailDaemon()
|
||||||
|
}
|
||||||
|
|
|
@ -18,9 +18,6 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/mail"
|
|
||||||
"code.vikunja.io/api/pkg/migration"
|
|
||||||
"code.vikunja.io/api/pkg/models"
|
|
||||||
"code.vikunja.io/api/pkg/routes"
|
"code.vikunja.io/api/pkg/routes"
|
||||||
"code.vikunja.io/api/pkg/swagger"
|
"code.vikunja.io/api/pkg/swagger"
|
||||||
"context"
|
"context"
|
||||||
|
@ -41,21 +38,6 @@ var webCmd = &cobra.Command{
|
||||||
Short: "Starts the rest api web server",
|
Short: "Starts the rest api web server",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
// Set logger
|
|
||||||
log.InitLogger()
|
|
||||||
|
|
||||||
// Run the migrations
|
|
||||||
migration.Migrate(nil)
|
|
||||||
|
|
||||||
// Set Engine
|
|
||||||
err := models.SetEngine()
|
|
||||||
if err != nil {
|
|
||||||
log.Log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start the mail daemon
|
|
||||||
mail.StartMailDaemon()
|
|
||||||
|
|
||||||
// Version notification
|
// Version notification
|
||||||
fmt.Printf("Vikunja version %s\n", Version)
|
fmt.Printf("Vikunja version %s\n", Version)
|
||||||
|
|
||||||
|
|
|
@ -19,12 +19,13 @@ package metrics
|
||||||
import (
|
import (
|
||||||
"code.vikunja.io/api/pkg/log"
|
"code.vikunja.io/api/pkg/log"
|
||||||
"code.vikunja.io/api/pkg/red"
|
"code.vikunja.io/api/pkg/red"
|
||||||
|
"github.com/go-redis/redis"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var r = red.GetRedis()
|
var r *redis.Client
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// ListCountKey is the name of the key in which we save the list count
|
// ListCountKey is the name of the key in which we save the list count
|
||||||
|
@ -43,7 +44,10 @@ const (
|
||||||
TeamCountKey = `teamcount`
|
TeamCountKey = `teamcount`
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
// InitMetrics Initializes the metrics
|
||||||
|
func InitMetrics() {
|
||||||
|
r = red.GetRedis()
|
||||||
|
|
||||||
// Register total list count metric
|
// Register total list count metric
|
||||||
promauto.NewGaugeFunc(prometheus.GaugeOpts{
|
promauto.NewGaugeFunc(prometheus.GaugeOpts{
|
||||||
Name: "vikunja_list_count",
|
Name: "vikunja_list_count",
|
||||||
|
|
|
@ -24,8 +24,8 @@ import (
|
||||||
|
|
||||||
var r *redis.Client
|
var r *redis.Client
|
||||||
|
|
||||||
// SetRedis initializes a redis connection
|
// InitRedis initializes a redis connection
|
||||||
func init() {
|
func InitRedis() {
|
||||||
if !viper.GetBool("redis.enabled") {
|
if !viper.GetBool("redis.enabled") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ func init() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Log.Fatal(err.Error())
|
log.Log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
log.Log.Debug("Redis initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRedis returns a pointer to a redis client
|
// GetRedis returns a pointer to a redis client
|
||||||
|
|
|
@ -138,6 +138,8 @@ func RegisterRoutes(e *echo.Echo) {
|
||||||
log.Log.Fatal("You have to enable redis in order to use metrics")
|
log.Log.Fatal("You have to enable redis in order to use metrics")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metrics.InitMetrics()
|
||||||
|
|
||||||
type countable struct {
|
type countable struct {
|
||||||
Rediskey string
|
Rediskey string
|
||||||
Type interface{}
|
Type interface{}
|
||||||
|
|
Loading…
Reference in a new issue