Skip to content

Commit

Permalink
add prometheus metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
rzrbld committed Mar 21, 2020
1 parent 61e473a commit 4f23264
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 0 deletions.
Binary file removed .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
.DS_Store
Binary file removed src/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var (
ScCookieName = getEnv("ADMINIO_COOKIE_NAME", "adminiosessionid")
OauthEnable, _ = strconv.ParseBool(getEnv("ADMINIO_OAUTH_ENABLE", "false"))
AuditLogEnable, _ = strconv.ParseBool(getEnv("ADMINIO_AUDIT_LOG_ENABLE", "false"))
MetricsEnable, _ = strconv.ParseBool(getEnv("ADMINIO_METRICS_ENABLE", "false"))
OauthProvider = getEnv("ADMINIO_OAUTH_PROVIDER", "github")
OauthClientId = getEnv("ADMINIO_OAUTH_CLIENT_ID", "my-github-oauth-app-client-id")
OauthClientSecret = getEnv("ADMINIO_OAUTH_CLIENT_SECRET", "my-github-oauth-app-secret")
Expand Down
6 changes: 6 additions & 0 deletions src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ require (
github.com/gorilla/securecookie v1.1.1
github.com/imkira/go-interpol v1.1.0 // indirect
github.com/iris-contrib/middleware/cors v0.0.0-20191219204441-78279b78a367
github.com/iris-contrib/middleware/prometheus v0.0.0-20191219204441-78279b78a367
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
github.com/kataras/iris/v12 v12.1.8
github.com/markbates/goth v1.62.0
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/minio/minio v0.0.0-20200315185552-c9212819afbf
github.com/minio/minio-go/v6 v6.0.50-0.20200306231101-b882ba63d570
github.com/moul/http2curl v1.0.0 // indirect
github.com/onsi/ginkgo v1.12.0 // indirect
github.com/onsi/gomega v1.9.0 // indirect
github.com/prometheus/client_golang v1.2.1
github.com/rzrbld/goth-provider-wso2 v0.0.0-20200321083654-32bbe73a67d4
github.com/sergi/go-diff v1.1.0 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
Expand All @@ -26,4 +29,7 @@ require (
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
golang.org/x/net v0.0.0-20200320220750-118fecf932d8 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)
45 changes: 45 additions & 0 deletions src/go.sum

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions src/handlers/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package handlers

import (
"log"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

var opsProcessed = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "bucket_size_current",
Help: "bucket size in kbytes",
}, []string{"bucket"})

func RecordMetrics() {
go func() {
for {
du, err := madmClnt.DataUsageInfo()
if err != nil {
log.Print("Error while getting bucket size metrics from server")
} else {
if len(du.BucketsSizes) != 0 {
for k, v := range du.BucketsSizes {
opsProcessed.WithLabelValues(string(k)).Set(float64(v))
}
}
}
time.Sleep(30 * time.Minute)
}
}()
}
11 changes: 11 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package main

import (
"fmt"

"github.com/iris-contrib/middleware/cors"
prometheusMiddleware "github.com/iris-contrib/middleware/prometheus"
iris "github.com/kataras/iris/v12"
"github.com/markbates/goth"
"github.com/markbates/goth/providers/amazon"
Expand All @@ -17,6 +19,7 @@ import (
"github.com/markbates/goth/providers/onedrive"
"github.com/markbates/goth/providers/salesforce"
"github.com/markbates/goth/providers/slack"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/rzrbld/goth-provider-wso2"

cnf "github.com/rzrbld/adminio-api/config"
Expand Down Expand Up @@ -54,6 +57,14 @@ func main() {
AllowCredentials: true,
})

// prometheus default metrics
if cnf.MetricsEnable {
m := prometheusMiddleware.New("adminio", 0.3, 1.2, 5.0)
hdl.RecordMetrics()
app.Use(m.ServeHTTP)
app.Get("/metrics", iris.FromStd(promhttp.Handler()))
}

v1auth := app.Party("/auth/", crs).AllowMethods(iris.MethodOptions)
{
v1auth.Get("/logout/", hdl.AuthLogout)
Expand Down

0 comments on commit 4f23264

Please sign in to comment.