Skip to content

Commit

Permalink
Prometheus changes
Browse files Browse the repository at this point in the history
  • Loading branch information
benbjohnson committed Jan 3, 2021
1 parent d56cd35 commit a08ee5d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion http/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// Websocket metrics.
var (
websocketConnections = promauto.NewGauge(prometheus.GaugeOpts{
Name: "litestream_http_websocket_connections",
Name: "wtf_http_websocket_connections",
Help: "Total number of connected websocket users",
})
)
Expand Down
2 changes: 1 addition & 1 deletion http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// Generic HTTP metrics.
var (
errorCount = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "litestream_http_error_count",
Name: "wtf_http_error_count",
Help: "Total number of errors by error code",
}, []string{"code"})
)
Expand Down
32 changes: 16 additions & 16 deletions http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@ import (
"github.com/benbjohnson/wtf/http/html"
"github.com/gorilla/mux"
"github.com/gorilla/securecookie"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
//"github.com/prometheus/client_golang/prometheus"
//"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"golang.org/x/crypto/acme/autocert"
"golang.org/x/oauth2"
"golang.org/x/oauth2/github"
)

// Generic HTTP metrics.
var (
requestCount = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "litestream_http_request_count",
Help: "Total number of requests by route",
}, []string{"route"})

requestSeconds = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "litestream_http_request_seconds",
Help: "Total amount of request time by route, in seconds",
}, []string{"route"})
)
//var (
// requestCount = promauto.NewCounterVec(prometheus.CounterOpts{
// Name: "wtf_http_request_count",
// Help: "Total number of requests by route",
// }, []string{"route"})
//
// requestSeconds = promauto.NewCounterVec(prometheus.CounterOpts{
// Name: "wtf_http_request_seconds",
// Help: "Total amount of request time by route, in seconds",
// }, []string{"route"})
//)

// ShutdownTimeout is the time given for outstanding requests to finish before shutdown.
const ShutdownTimeout = 1 * time.Second
Expand Down Expand Up @@ -370,16 +370,16 @@ func loadFlash(next http.Handler) http.Handler {
func trackMetrics(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Obtain path template & start time of request.
t := time.Now()
// t := time.Now()
tmpl := requestPathTemplate(r)

// Delegate to next handler in middleware chain.
next.ServeHTTP(w, r)

// Track total time unless it is the WebSocket endpoint for events.
if tmpl != "" && tmpl != "/events" {
requestCount.WithLabelValues(tmpl).Inc()
requestSeconds.WithLabelValues(tmpl).Add(float64(time.Since(t).Seconds()))
//requestCount.WithLabelValues(tmpl).Inc()
//requestSeconds.WithLabelValues(tmpl).Add(float64(time.Since(t).Seconds()))
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ import (
// Database metrics.
var (
userCountGauge = promauto.NewGauge(prometheus.GaugeOpts{
Name: "litestream_db_users",
Name: "wtf_db_users",
Help: "The total number of users",
})

dialCountGauge = promauto.NewGauge(prometheus.GaugeOpts{
Name: "litestream_db_dials",
Name: "wtf_db_dials",
Help: "The total number of dials",
})

dialMembershipCountGauge = promauto.NewGauge(prometheus.GaugeOpts{
Name: "litestream_db_dial_memberships",
Name: "wtf_db_dial_memberships",
Help: "The total number of dial memberships",
})
)
Expand Down

0 comments on commit a08ee5d

Please sign in to comment.