Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New metrics #586

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e8b1531
Refactor metrics
magiconair Feb 11, 2018
f774356
Remove 'Register' methods and create objects directly.
magiconair Mar 24, 2018
713c450
Add Gauge and use it for websocket connections
magiconair Mar 24, 2018
806c4f0
Vendoring in github.com/alexcesaro/statsd
magiconair Mar 24, 2018
20fa958
First stab at integrating raw statsd from #335
magiconair Mar 24, 2018
f394deb
Added support of Prometheus.Counter with go-kit/metrics
mbarouski Dec 12, 2018
e21c6ca
Added Prometheus.Gauge
mbarouski Dec 12, 2018
ba2dd84
Prometheus Histograms and Timers (needs testing)
mbarouski Dec 12, 2018
49aadaa
Fixed timer.Duration arguments
mbarouski Dec 12, 2018
42b202c
Refactored Timers
mbarouski Dec 13, 2018
1974cee
Fixedusing of labels
mbarouski Dec 13, 2018
301c7e9
Added sync to Prometheus metrics provider
mbarouski Dec 13, 2018
1288a0c
Added NoopMetrics; Commented histograms; Added StatsD Gauge.
mbarouski Dec 13, 2018
785446c
Removed comments
mbarouski Dec 13, 2018
cb7b1fb
Added StatsD Counter and Timer
mbarouski Dec 13, 2018
68e1181
Small refactoring
mbarouski Dec 13, 2018
3e1cfe4
Simplified Timer interface
mbarouski Dec 14, 2018
eee0495
Simplified Prometheus timer
mbarouski Dec 14, 2018
c6186e2
Made Provider closable
mbarouski Dec 14, 2018
fae8636
Added tests for labling of StatsD metrics
mbarouski Dec 14, 2018
e885ad5
StatsD tests are refactored
mbarouski Dec 14, 2018
ee1edf5
Untagged metrics abstraction
mbarouski Dec 14, 2018
f643d27
Added Graphite and StdOut metric drivers
mbarouski Dec 17, 2018
b2c7c63
Fixed naming through dot
mbarouski Dec 17, 2018
0c915ea
Added stdout to initMetrics
mbarouski Dec 17, 2018
9e5db05
Added Circonus
mbarouski Dec 17, 2018
d006713
Refactored Circonus to new Provider interface
mbarouski Dec 17, 2018
8b23b1e
Metric prefix
mbarouski Dec 18, 2018
0851ff3
Fixed issues after renaming names -> prefix
mbarouski Dec 18, 2018
5d2d3c8
Refactored Prometheus prefix
mbarouski Dec 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions admin/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func (h *RoutesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Weight: tg.Weight,
Tags: tg.Tags,
Cmd: "route add",
Rate1: tg.Timer.Rate1(),
Pct99: tg.Timer.Percentile(0.99),
// Rate1: tg.Timer.Rate1(),
// Pct99: tg.Timer.Percentile(0.99),
}
routes = append(routes, ar)
}
Expand Down
12 changes: 12 additions & 0 deletions admin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"github.com/fabiolb/fabio/admin/api"
"github.com/fabiolb/fabio/admin/ui"
"github.com/fabiolb/fabio/config"
"github.com/fabiolb/fabio/metrics4"
"github.com/fabiolb/fabio/proxy"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

// Server provides the HTTP server for the admin UI and API.
Expand All @@ -20,6 +22,7 @@ type Server struct {
Version string
Commands string
Cfg *config.Config
Metrics *metrics4.Provider
}

// ListenAndServe starts the admin server.
Expand Down Expand Up @@ -64,12 +67,21 @@ func (s *Server) handler() http.Handler {
mux.Handle("/api/routes", &api.RoutesHandler{})
mux.Handle("/api/version", &api.VersionHandler{Version: s.Version})
mux.Handle("/routes", &ui.RoutesHandler{Color: s.Color, Title: s.Title, Version: s.Version})

initMetricsHandlers(mux, s)

mux.HandleFunc("/logo.svg", ui.HandleLogo)
mux.HandleFunc("/health", handleHealth)
mux.Handle("/", http.RedirectHandler("/routes", http.StatusSeeOther))
return mux
}

func initMetricsHandlers(mux *http.ServeMux, s *Server) {
if strings.Contains(s.Cfg.Metrics.Target, "prometheus") && s.Cfg.Metrics.Prometheus.MetricsEndpoint != "" {
mux.HandleFunc(s.Cfg.Metrics.Prometheus.MetricsEndpoint, promhttp.Handler().ServeHTTP)
}
}

func handleHealth(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "OK")
}
Expand Down
29 changes: 20 additions & 9 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,26 @@ type Log struct {
}

type Metrics struct {
Target string
Prefix string
Names string
Interval time.Duration
Timeout time.Duration
Retry time.Duration
GraphiteAddr string
StatsDAddr string
Circonus Circonus
Target string
Prefix string
Interval time.Duration
Prometheus Prometheus
StatsD StatsD
Graphite Graphite
Circonus Circonus
}

type Graphite struct {
Addr string
}

type StatsD struct {
Addr string
SampleRate float64
}

type Prometheus struct {
MetricsEndpoint string
}

type Registry struct {
Expand Down
15 changes: 11 additions & 4 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,18 @@ var defaultConfig = &Config{
Level: "INFO",
},
Metrics: Metrics{
Prefix: "{{clean .Hostname}}.{{clean .Exec}}",
Names: "{{clean .Service}}.{{clean .Host}}.{{clean .Path}}.{{clean .TargetURL.Host}}",
//Prefix: "{{clean .Hostname}}.{{clean .Exec}}",
//Names: "{{clean .Service}}.{{clean .Host}}.{{clean .Path}}.{{clean .TargetURL.Host}}",
Interval: 30 * time.Second,
Timeout: 10 * time.Second,
Retry: 500 * time.Millisecond,
//Timeout: 10 * time.Second,
//Retry: 500 * time.Millisecond,
Prometheus: Prometheus{
MetricsEndpoint: "/metrics/prometheus",
},
StatsD: StatsD{
SampleRate: 1,
},
Graphite: Graphite{},
Circonus: Circonus{
APIApp: "fabio",
},
Expand Down
16 changes: 11 additions & 5 deletions config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,25 @@ func load(cmdline, environ, envprefix []string, props *properties.Properties) (c
f.StringVar(&cfg.Log.AccessTarget, "log.access.target", defaultConfig.Log.AccessTarget, "access log target")
f.StringVar(&cfg.Log.RoutesFormat, "log.routes.format", defaultConfig.Log.RoutesFormat, "log format of routing table updates")
f.StringVar(&cfg.Log.Level, "log.level", defaultConfig.Log.Level, "log level: TRACE, DEBUG, INFO, WARN, ERROR, FATAL")

f.StringVar(&cfg.Metrics.Target, "metrics.target", defaultConfig.Metrics.Target, "metrics backend")

f.StringVar(&cfg.Metrics.Prefix, "metrics.prefix", defaultConfig.Metrics.Prefix, "prefix for reported metrics")
f.StringVar(&cfg.Metrics.Names, "metrics.names", defaultConfig.Metrics.Names, "route metric name template")
f.DurationVar(&cfg.Metrics.Interval, "metrics.interval", defaultConfig.Metrics.Interval, "metrics reporting interval")
f.DurationVar(&cfg.Metrics.Timeout, "metrics.timeout", defaultConfig.Metrics.Timeout, "timeout for metrics to become available")
f.DurationVar(&cfg.Metrics.Retry, "metrics.retry", defaultConfig.Metrics.Retry, "retry interval during startup")
f.StringVar(&cfg.Metrics.GraphiteAddr, "metrics.graphite.addr", defaultConfig.Metrics.GraphiteAddr, "graphite server address")
f.StringVar(&cfg.Metrics.StatsDAddr, "metrics.statsd.addr", defaultConfig.Metrics.StatsDAddr, "statsd server address")

f.StringVar(&cfg.Metrics.Prometheus.MetricsEndpoint, "metrics.prometheus.endpoint", defaultConfig.Metrics.Prometheus.MetricsEndpoint, "metrics endpoint for Prometheus")

f.StringVar(&cfg.Metrics.Graphite.Addr, "metrics.graphite.addr", defaultConfig.Metrics.Graphite.Addr, "graphite carbon receiver or aggregator (plaintext) address")

f.StringVar(&cfg.Metrics.StatsD.Addr, "metrics.statsd.addr", defaultConfig.Metrics.StatsD.Addr, "statsd server address")
f.Float64Var(&cfg.Metrics.StatsD.SampleRate, "metrics.statsd.sampleRate", defaultConfig.Metrics.StatsD.SampleRate, "statsd sample rate")

f.StringVar(&cfg.Metrics.Circonus.APIKey, "metrics.circonus.apikey", defaultConfig.Metrics.Circonus.APIKey, "Circonus API token key")
f.StringVar(&cfg.Metrics.Circonus.APIApp, "metrics.circonus.apiapp", defaultConfig.Metrics.Circonus.APIApp, "Circonus API token app")
f.StringVar(&cfg.Metrics.Circonus.APIURL, "metrics.circonus.apiurl", defaultConfig.Metrics.Circonus.APIURL, "Circonus API URL")
f.StringVar(&cfg.Metrics.Circonus.BrokerID, "metrics.circonus.brokerid", defaultConfig.Metrics.Circonus.BrokerID, "Circonus Broker ID")
f.StringVar(&cfg.Metrics.Circonus.CheckID, "metrics.circonus.checkid", defaultConfig.Metrics.Circonus.CheckID, "Circonus Check ID")

f.StringVar(&cfg.Registry.Backend, "registry.backend", defaultConfig.Registry.Backend, "registry backend")
f.DurationVar(&cfg.Registry.Timeout, "registry.timeout", defaultConfig.Registry.Timeout, "timeout for registry to become available")
f.DurationVar(&cfg.Registry.Retry, "registry.retry", defaultConfig.Registry.Retry, "retry interval during startup")
Expand Down
7 changes: 0 additions & 7 deletions config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,13 +646,6 @@ func TestLoad(t *testing.T) {
return cfg
},
},
{
args: []string{"-metrics.names", "some names"},
cfg: func(cfg *Config) *Config {
cfg.Metrics.Names = "some names"
return cfg
},
},
{
args: []string{"-metrics.interval", "5ms"},
cfg: func(cfg *Config) *Config {
Expand Down
Loading