feat(metrics): add metrics server (#1930)

* feat(metrics): add metrics server

* chore: update license headers

* feat(metrics): add optional basic auth

* feat(metrics): add go and process collectors

---------

Co-authored-by: ze0s <43699394+zze0s@users.noreply.github.com>
Co-authored-by: ze0s <ze0s@riseup.net>
This commit is contained in:
Antoine 2025-01-25 17:58:18 +01:00 committed by GitHub
parent 0d5902c8f6
commit 3f8bc0140c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 1191 additions and 83 deletions

View file

@ -126,7 +126,29 @@ sessionSecret = "{{ .sessionSecret }}"
# OIDC Redirect URL (e.g. http://localhost:7474/api/auth/oidc/callback)
#oidc_redirect_url = ""
# Metrics
#
# Enable metrics endpoint
#metricsEnabled = true
#
# Metrics server host
#
#metricsHost = "127.0.0.1"
#
# Metrics server port
#
#metricsPort = 9074
#
# Metrics basic auth
#
# Comma separate list of user:password. Password must be htpasswd bcrypt hashed. Use autobrrctl to generate.
# Only enabled if correctly set with user:pass.
#
#metricsBasicAuthUsers = ""
# Custom definitions
#
#customDefinitions = "test/definitions"
`
func (c *AppConfig) writeConfig(configPath string, configFile string) error {
@ -242,30 +264,34 @@ func New(configPath string, version string) *AppConfig {
func (c *AppConfig) defaults() {
c.Config = &domain.Config{
Version: "dev",
Host: "localhost",
Port: 7474,
LogLevel: "TRACE",
LogPath: "",
LogMaxSize: 50,
LogMaxBackups: 3,
DatabaseMaxBackups: 5,
BaseURL: "/",
BaseURLModeLegacy: true,
SessionSecret: api.GenerateSecureToken(16),
CustomDefinitions: "",
CheckForUpdates: true,
DatabaseType: "sqlite",
PostgresHost: "",
PostgresPort: 0,
PostgresDatabase: "",
PostgresUser: "",
PostgresPass: "",
PostgresSSLMode: "disable",
PostgresExtraParams: "",
ProfilingEnabled: false,
ProfilingHost: "127.0.0.1",
ProfilingPort: 6060,
Version: "dev",
Host: "localhost",
Port: 7474,
LogLevel: "TRACE",
LogPath: "",
LogMaxSize: 50,
LogMaxBackups: 3,
DatabaseMaxBackups: 5,
BaseURL: "/",
BaseURLModeLegacy: true,
SessionSecret: api.GenerateSecureToken(16),
CustomDefinitions: "",
CheckForUpdates: true,
DatabaseType: "sqlite",
PostgresHost: "",
PostgresPort: 0,
PostgresDatabase: "",
PostgresUser: "",
PostgresPass: "",
PostgresSSLMode: "disable",
PostgresExtraParams: "",
ProfilingEnabled: false,
ProfilingHost: "127.0.0.1",
ProfilingPort: 6060,
MetricsEnabled: false,
MetricsHost: "127.0.0.1",
MetricsPort: 9074,
MetricsBasicAuthUsers: "",
}
}
@ -405,6 +431,25 @@ func (c *AppConfig) loadFromEnv() {
if v := os.Getenv(prefix + "OIDC_REDIRECT_URL"); v != "" {
c.Config.OIDCRedirectURL = v
}
if v := os.Getenv(prefix + "METRICS_ENABLED"); v != "" {
c.Config.MetricsEnabled = strings.EqualFold(strings.ToLower(v), "true")
}
if v := os.Getenv(prefix + "METRICS_HOST"); v != "" {
c.Config.MetricsHost = v
}
if v := os.Getenv(prefix + "METRICS_PORT"); v != "" {
i, _ := strconv.ParseInt(v, 10, 32)
if i > 0 {
c.Config.MetricsPort = int(i)
}
}
if v := os.Getenv(prefix + "METRICS_BASIC_AUTH_USERS"); v != "" {
c.Config.MetricsBasicAuthUsers = v
}
}
func validDatabaseType(v string) bool {