mirror of
https://github.com/gogs/gogs.git
synced 2025-12-20 15:20:01 +01:00
metrics: add initial Prometheus support (#4141)
This commit is contained in:
19
cmd/web.go
19
cmd/web.go
@@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/go-macaron/session"
|
"github.com/go-macaron/session"
|
||||||
"github.com/go-macaron/toolbox"
|
"github.com/go-macaron/toolbox"
|
||||||
"github.com/mcuadros/go-version"
|
"github.com/mcuadros/go-version"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
log "gopkg.in/clog.v1"
|
log "gopkg.in/clog.v1"
|
||||||
"gopkg.in/macaron.v1"
|
"gopkg.in/macaron.v1"
|
||||||
@@ -260,11 +261,11 @@ func runWeb(c *cli.Context) error {
|
|||||||
})
|
})
|
||||||
// ***** END: User *****
|
// ***** END: User *****
|
||||||
|
|
||||||
adminReq := context.Toggle(&context.ToggleOptions{SignInRequired: true, AdminRequired: true})
|
reqAdmin := context.Toggle(&context.ToggleOptions{SignInRequired: true, AdminRequired: true})
|
||||||
|
|
||||||
// ***** START: Admin *****
|
// ***** START: Admin *****
|
||||||
m.Group("/admin", func() {
|
m.Group("/admin", func() {
|
||||||
m.Get("", adminReq, admin.Dashboard)
|
m.Get("", admin.Dashboard)
|
||||||
m.Get("/config", admin.Config)
|
m.Get("/config", admin.Config)
|
||||||
m.Post("/config/test_mail", admin.SendTestMail)
|
m.Post("/config/test_mail", admin.SendTestMail)
|
||||||
m.Get("/monitor", admin.Monitor)
|
m.Get("/monitor", admin.Monitor)
|
||||||
@@ -298,7 +299,7 @@ func runWeb(c *cli.Context) error {
|
|||||||
m.Post("/delete", admin.DeleteNotices)
|
m.Post("/delete", admin.DeleteNotices)
|
||||||
m.Get("/empty", admin.EmptyNotices)
|
m.Get("/empty", admin.EmptyNotices)
|
||||||
})
|
})
|
||||||
}, adminReq)
|
}, reqAdmin)
|
||||||
// ***** END: Admin *****
|
// ***** END: Admin *****
|
||||||
|
|
||||||
m.Group("", func() {
|
m.Group("", func() {
|
||||||
@@ -659,6 +660,18 @@ func runWeb(c *cli.Context) error {
|
|||||||
apiv1.RegisterRoutes(m)
|
apiv1.RegisterRoutes(m)
|
||||||
}, ignSignIn)
|
}, ignSignIn)
|
||||||
|
|
||||||
|
m.Group("/-", func() {
|
||||||
|
if setting.Prometheus.Enabled {
|
||||||
|
m.Get("/metrics", func(c *context.Context) {
|
||||||
|
if !setting.Prometheus.EnableBasicAuth {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.RequireBasicAuth(setting.Prometheus.BasicAuthUsername, setting.Prometheus.BasicAuthPassword)
|
||||||
|
}, promhttp.Handler())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// robots.txt
|
// robots.txt
|
||||||
m.Get("/robots.txt", func(c *context.Context) {
|
m.Get("/robots.txt", func(c *context.Context) {
|
||||||
if setting.HasRobotsTxt {
|
if setting.HasRobotsTxt {
|
||||||
|
|||||||
@@ -464,6 +464,12 @@ NEWS_FEED_PAGING_NUM = 20
|
|||||||
; Number of commits that are showed in one page
|
; Number of commits that are showed in one page
|
||||||
COMMITS_PAGING_NUM = 30
|
COMMITS_PAGING_NUM = 30
|
||||||
|
|
||||||
|
[prometheus]
|
||||||
|
ENABLED = true
|
||||||
|
ENABLE_BASIC_AUTH = false
|
||||||
|
BASIC_AUTH_USERNAME =
|
||||||
|
BASIC_AUTH_PASSWORD =
|
||||||
|
|
||||||
[i18n]
|
[i18n]
|
||||||
LANGS = en-US,zh-CN,zh-HK,zh-TW,de-DE,fr-FR,nl-NL,lv-LV,ru-RU,ja-JP,es-ES,pt-BR,pl-PL,bg-BG,it-IT,fi-FI,tr-TR,cs-CZ,sr-SP,sv-SE,ko-KR,gl-ES,uk-UA,en-GB,hu-HU,sk-SK,id-ID,fa-IR,vi-VN
|
LANGS = en-US,zh-CN,zh-HK,zh-TW,de-DE,fr-FR,nl-NL,lv-LV,ru-RU,ja-JP,es-ES,pt-BR,pl-PL,bg-BG,it-IT,fi-FI,tr-TR,cs-CZ,sr-SP,sv-SE,ko-KR,gl-ES,uk-UA,en-GB,hu-HU,sk-SK,id-ID,fa-IR,vi-VN
|
||||||
NAMES = English,简体中文,繁體中文(香港),繁體中文(臺灣),Deutsch,français,Nederlands,latviešu,русский,日本語,español,português do Brasil,polski,български,italiano,suomi,Türkçe,čeština,српски,svenska,한국어,galego,українська,English (United Kingdom),Magyar,Slovenčina,Indonesian,Persian,Vietnamese
|
NAMES = English,简体中文,繁體中文(香港),繁體中文(臺灣),Deutsch,français,Nederlands,latviešu,русский,日本語,español,português do Brasil,polski,български,italiano,suomi,Türkçe,čeština,српски,svenska,한국어,galego,українська,English (United Kingdom),Magyar,Slovenčina,Indonesian,Persian,Vietnamese
|
||||||
|
|||||||
2
gogs.go
2
gogs.go
@@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/gogs/gogs/pkg/setting"
|
"github.com/gogs/gogs/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.11.65.0914"
|
const APP_VER = "0.11.66.0914"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
setting.AppVer = APP_VER
|
setting.AppVer = APP_VER
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -5,13 +5,16 @@
|
|||||||
package context
|
package context
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/go-macaron/csrf"
|
"github.com/go-macaron/csrf"
|
||||||
"gopkg.in/macaron.v1"
|
"gopkg.in/macaron.v1"
|
||||||
|
|
||||||
"github.com/gogs/gogs/pkg/auth"
|
"github.com/gogs/gogs/pkg/auth"
|
||||||
"github.com/gogs/gogs/pkg/setting"
|
"github.com/gogs/gogs/pkg/setting"
|
||||||
|
"github.com/gogs/gogs/pkg/tool"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ToggleOptions struct {
|
type ToggleOptions struct {
|
||||||
@@ -92,3 +95,18 @@ func Toggle(options *ToggleOptions) macaron.Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RequireBasicAuth verifies HTTP Basic Authentication header with given credentials
|
||||||
|
func (c *Context) RequireBasicAuth(username, password string) {
|
||||||
|
fields := strings.Fields(c.Req.Header.Get("Authorization"))
|
||||||
|
if len(fields) != 2 || fields[0] != "Basic" {
|
||||||
|
c.Status(http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
uname, passwd, _ := tool.BasicAuthDecode(fields[1])
|
||||||
|
if uname != username || passwd != password {
|
||||||
|
c.Status(http.StatusForbidden)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -294,6 +294,14 @@ var (
|
|||||||
} `ini:"ui.user"`
|
} `ini:"ui.user"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prometheus settings
|
||||||
|
Prometheus struct {
|
||||||
|
Enabled bool
|
||||||
|
EnableBasicAuth bool
|
||||||
|
BasicAuthUsername string
|
||||||
|
BasicAuthPassword string
|
||||||
|
}
|
||||||
|
|
||||||
// I18n settings
|
// I18n settings
|
||||||
Langs []string
|
Langs []string
|
||||||
Names []string
|
Names []string
|
||||||
@@ -652,27 +660,29 @@ func NewContext() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err = Cfg.Section("http").MapTo(&HTTP); err != nil {
|
if err = Cfg.Section("http").MapTo(&HTTP); err != nil {
|
||||||
log.Fatal(2, "Fail to map HTTP settings: %v", err)
|
log.Fatal(2, "Failed to map HTTP settings: %v", err)
|
||||||
} else if err = Cfg.Section("webhook").MapTo(&Webhook); err != nil {
|
} else if err = Cfg.Section("webhook").MapTo(&Webhook); err != nil {
|
||||||
log.Fatal(2, "Fail to map Webhook settings: %v", err)
|
log.Fatal(2, "Failed to map Webhook settings: %v", err)
|
||||||
} else if err = Cfg.Section("release.attachment").MapTo(&Release.Attachment); err != nil {
|
} else if err = Cfg.Section("release.attachment").MapTo(&Release.Attachment); err != nil {
|
||||||
log.Fatal(2, "Fail to map Release.Attachment settings: %v", err)
|
log.Fatal(2, "Failed to map Release.Attachment settings: %v", err)
|
||||||
} else if err = Cfg.Section("markdown").MapTo(&Markdown); err != nil {
|
} else if err = Cfg.Section("markdown").MapTo(&Markdown); err != nil {
|
||||||
log.Fatal(2, "Fail to map Markdown settings: %v", err)
|
log.Fatal(2, "Failed to map Markdown settings: %v", err)
|
||||||
} else if err = Cfg.Section("smartypants").MapTo(&Smartypants); err != nil {
|
} else if err = Cfg.Section("smartypants").MapTo(&Smartypants); err != nil {
|
||||||
log.Fatal(2, "Fail to map Smartypants settings: %v", err)
|
log.Fatal(2, "Failed to map Smartypants settings: %v", err)
|
||||||
} else if err = Cfg.Section("admin").MapTo(&Admin); err != nil {
|
} else if err = Cfg.Section("admin").MapTo(&Admin); err != nil {
|
||||||
log.Fatal(2, "Fail to map Admin settings: %v", err)
|
log.Fatal(2, "Failed to map Admin settings: %v", err)
|
||||||
} else if err = Cfg.Section("cron").MapTo(&Cron); err != nil {
|
} else if err = Cfg.Section("cron").MapTo(&Cron); err != nil {
|
||||||
log.Fatal(2, "Fail to map Cron settings: %v", err)
|
log.Fatal(2, "Failed to map Cron settings: %v", err)
|
||||||
} else if err = Cfg.Section("git").MapTo(&Git); err != nil {
|
} else if err = Cfg.Section("git").MapTo(&Git); err != nil {
|
||||||
log.Fatal(2, "Fail to map Git settings: %v", err)
|
log.Fatal(2, "Failed to map Git settings: %v", err)
|
||||||
} else if err = Cfg.Section("mirror").MapTo(&Mirror); err != nil {
|
} else if err = Cfg.Section("mirror").MapTo(&Mirror); err != nil {
|
||||||
log.Fatal(2, "Fail to map Mirror settings: %v", err)
|
log.Fatal(2, "Failed to map Mirror settings: %v", err)
|
||||||
} else if err = Cfg.Section("api").MapTo(&API); err != nil {
|
} else if err = Cfg.Section("api").MapTo(&API); err != nil {
|
||||||
log.Fatal(2, "Fail to map API settings: %v", err)
|
log.Fatal(2, "Failed to map API settings: %v", err)
|
||||||
} else if err = Cfg.Section("ui").MapTo(&UI); err != nil {
|
} else if err = Cfg.Section("ui").MapTo(&UI); err != nil {
|
||||||
log.Fatal(2, "Fail to map UI settings: %v", err)
|
log.Fatal(2, "Failed to map UI settings: %v", err)
|
||||||
|
} else if err = Cfg.Section("prometheus").MapTo(&Prometheus); err != nil {
|
||||||
|
log.Fatal(2, "Failed to map Prometheus settings: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if Mirror.DefaultInterval <= 0 {
|
if Mirror.DefaultInterval <= 0 {
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
0.11.65.0914
|
0.11.66.0914
|
||||||
|
|||||||
Reference in New Issue
Block a user