Skip to content

Commit

Permalink
Allow metrics configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
iknite committed Feb 19, 2019
1 parent e6b7dec commit 9f0d6f8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ func newStartCommand(ctx *cmdContext) *cobra.Command {
conf.APIKey = ctx.apiKey
conf.NodeID = v.GetString("server.node-id")
conf.EnableProfiling = v.GetBool("server.profiling")
conf.EnableMetrics = v.GetBool("server.metrics")
conf.PrivateKeyPath, _ = homedir.Expand(v.GetString("server.key"))
conf.SSLCertificate, _ = homedir.Expand(v.GetString("server.tls.certificate"))
conf.SSLCertificateKey, _ = homedir.Expand(v.GetString("server.tls.certificate_key"))
conf.HTTPAddr = v.GetString("server.addr.http")
conf.RaftAddr = v.GetString("server.addr.raft")
conf.MgmtAddr = v.GetString("server.addr.mgmt")
conf.MetricsAddr = v.GetString("server.addr.metrics")
conf.RaftJoinAddr = v.GetStringSlice("server.addr.join")
conf.GossipAddr = v.GetString("server.addr.gossip")
conf.GossipJoinAddr = v.GetStringSlice("server.addr.gossip_join")
Expand Down Expand Up @@ -84,13 +86,15 @@ func newStartCommand(ctx *cmdContext) *cobra.Command {
hostname, _ := os.Hostname()
f.StringVar(&conf.NodeID, "node-id", hostname, "Unique name for node. If not set, fallback to hostname")
f.BoolVarP(&conf.EnableProfiling, "profiling", "f", false, "Allow a pprof url (localhost:6060) for profiling purposes")
f.BoolVarP(&conf.EnableMetrics, "metrics", "m", false, "Allow export metrics through --metrics-addr (default localhost:9990)")
f.StringVar(&conf.PrivateKeyPath, "keypath", fmt.Sprintf("%s/%s", ctx.path, "id_ed25519"), "Server Singning private key file path")
f.StringVar(&conf.SSLCertificate, "certificate", fmt.Sprintf("%s/%s", ctx.path, "server.crt"), "Server crt file")
f.StringVar(&conf.SSLCertificateKey, "certificate-key", fmt.Sprintf("%s/%s", ctx.path, "server.key"), "Server key file")

f.StringVar(&conf.HTTPAddr, "http-addr", ":8080", "Endpoint for REST requests on (host:port)")
f.StringVar(&conf.RaftAddr, "raft-addr", "9000", "Raft bind address (host:port)")
f.StringVar(&conf.MgmtAddr, "mgmt-addr", "8090", "Management endpoint bind address (host:port)")
f.StringVar(&conf.MgmtAddr, "metrics-addr", "9990", "Metrics export bind address (host:port)")
f.StringSliceVar(&conf.RaftJoinAddr, "join-addr", []string{}, "Raft: Comma-delimited list of nodes ([host]:port), through which a cluster can be joined")
f.StringVar(&conf.GossipAddr, "gossip-addr", ":9100", "Gossip: management endpoint bind address (host:port)")
f.StringSliceVar(&conf.GossipJoinAddr, "gossip-join-addr", []string{}, "Gossip: Comma-delimited list of nodes ([host]:port), through which a cluster can be joined")
Expand All @@ -102,12 +106,14 @@ func newStartCommand(ctx *cmdContext) *cobra.Command {
// Lookups
v.BindPFlag("server.node-id", f.Lookup("node-id"))
v.BindPFlag("server.profiling", f.Lookup("profiling"))
v.BindPFlag("server.metrics", f.Lookup("metrics"))
v.BindPFlag("server.key", f.Lookup("keypath"))
v.BindPFlag("server.tls.certificate", f.Lookup("certificate"))
v.BindPFlag("server.tls.certificate_key", f.Lookup("certificate-key"))

v.BindPFlag("server.addr.http", f.Lookup("http-addr"))
v.BindPFlag("server.addr.mgmt", f.Lookup("mgmt-addr"))
v.BindPFlag("server.addr.metrics", f.Lookup("metrics-addr"))
v.BindPFlag("server.addr.raft", f.Lookup("raft-addr"))
v.BindPFlag("server.addr.raft_join", f.Lookup("join-addr"))
v.BindPFlag("server.addr.gossip", f.Lookup("gossip-addr"))
Expand Down
2 changes: 2 additions & 0 deletions config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ path: "/var/tmp/qed/" # Set root path used for dbpath, raftpath, private key and
server:
node_id: "hostname" # Unique name for node. If not set, fallback to hostname.
profiling: false # Allow a pprof url (localhost:6060) for profiling purposes.
metrics: false # Allow metrics
key: "/var/tmp/qed/id_ed25519" # Path to the ed25519 key file.
tls:
certificate: "/var/tmp/qed/server.crt" # Server certificate file
certificate_key: "/var/tmp/qed/server.key" # Server certificate key file
addr:
http: ":8080" # Endpoint for REST requests on (host:port).
mgmt: ":8090" # Management endpoint bind address (host:port).
metrics: ":9990" # Metrics endpoint (host:port).
raft: ":9000" # Raft bind address (host:port).
raft_join: # Raft: list of nodes ([host]:port), through which a cluster can be joined.
- "127.0.0.1:9000"
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/bbva/qed
require (
github.com/VictoriaMetrics/fastcache v1.3.0
github.com/bbva/raft-badger v0.1.1
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 // indirect
github.com/boltdb/bolt v1.3.1 // indirect
github.com/coocood/freecache v1.0.1
github.com/coreos/bbolt v1.3.0
Expand Down Expand Up @@ -43,7 +44,7 @@ require (
github.com/onsi/ginkgo v1.7.0 // indirect
github.com/onsi/gomega v1.4.3 // indirect
github.com/pborman/uuid v1.2.0
github.com/prometheus/client_golang v0.9.1 // indirect
github.com/prometheus/client_golang v0.9.1
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 // indirect
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275 // indirect
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ github.com/bbva/raft-badger v0.1.0 h1:2Rs2cE84pYaqE4IqI6ZZr/wXUvetZ8jV4doOH0Yaw8
github.com/bbva/raft-badger v0.1.0/go.mod h1:/XINu34Us6PULTVQn0D6I/WtniWHHjut9lnsfFVECDA=
github.com/bbva/raft-badger v0.1.1 h1:v0BlEP2glTd3o1U4ShD4HtyGc08PXt4gcEBdO6Fh7Oc=
github.com/bbva/raft-badger v0.1.1/go.mod h1:KqKb1IrW6hsgFSzXTavxddJH+5E3TmDxBbFhitk0vpY=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
Expand Down Expand Up @@ -166,6 +168,7 @@ github.com/prometheus/common v0.0.0-20181126121408-4724e9255275 h1:PnBWHBf+6L0jO
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/procfs v0.0.0-20181126161756-619930b0b471 h1:yLaU2uaatUJcbMacSwa4Dvstrkh6GXm2LhIpo0eGAms=
github.com/prometheus/procfs v0.0.0-20181126161756-619930b0b471/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a h1:9a8MnZMP0X2nLJdBg+pBmGgkJlSaKC2KaQmTCk1XDtE=
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
Expand Down
6 changes: 5 additions & 1 deletion server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ type Config struct {
// and get cluster information.
MgmtAddr string

// Metrics bind address/port.
MetricsAddr string

// List of raft nodes, through which a cluster can be joined
// (protocol://host:port).
RaftJoinAddr []string
Expand Down Expand Up @@ -88,14 +91,15 @@ func DefaultConfig() *Config {
HTTPAddr: "127.0.0.1:8080",
RaftAddr: "127.0.0.1:9000",
MgmtAddr: "127.0.0.1:8090",
MetricsAddr: "127.0.0.1:9990",
RaftJoinAddr: []string{},
GossipAddr: "127.0.0.1:9100",
GossipJoinAddr: []string{},
DBPath: currentDir + "/db",
RaftPath: currentDir + "/wal",
EnableProfiling: false,
EnableTampering: false,
EnableMetrics: true,
EnableMetrics: false,
EnableTLS: false,
SSLCertificate: "",
SSLCertificateKey: "",
Expand Down
4 changes: 3 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,18 @@ func NewServer(conf *Config) (*Server, error) {
tamperMux := tampering.NewTamperingApi(store, hashing.NewSha256Hasher())
server.tamperingServer = newHTTPServer("localhost:8081", tamperMux)
}

if conf.EnableProfiling {
server.profilingServer = newHTTPServer("localhost:6060", nil)
}

if conf.EnableMetrics {
r := prometheus.NewRegistry()
metrics.Register(r)
server.prometheusRegistry = r
metricsMux := metricshttp.NewMetricsHTTP(r)

server.metricsServer = newHTTPServer("localhost:9990", metricsMux)
server.metricsServer = newHTTPServer(conf.MetricsAddr, metricsMux)
}

return server, nil
Expand Down

0 comments on commit 9f0d6f8

Please sign in to comment.