diff options
author | Valery Piashchynski <[email protected]> | 2020-12-10 10:53:38 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-10 10:53:38 +0300 |
commit | 73d3f968b690b0e34e571580243e5fdd0d42199c (patch) | |
tree | c19174a239253cf2c62c18398c2a69d400627416 | |
parent | 95bcb4c3f390bebb91041db710dbb4bde994d2fe (diff) | |
parent | 72ef974e2f79c9ee8eb2584baa50ea9a8b98eac9 (diff) |
Merge pull request #442 from spiral/feature/metrics_add_objectives
Add objectives to the metrics summary
-rw-r--r-- | .rr.yaml | 55 | ||||
-rw-r--r-- | service/metrics/config.go | 12 | ||||
-rw-r--r-- | service/metrics/config_test.go | 3 | ||||
-rw-r--r-- | service/metrics/rpc.go | 11 |
4 files changed, 48 insertions, 33 deletions
@@ -8,27 +8,34 @@ rpc: enable: true # rpc connection DSN. Supported TCP and Unix sockets. - listen: tcp://127.0.0.1:6001 + listen: tcp://127.0.0.1:6001 metrics: # prometheus client address (path /metrics added automatically) address: localhost:2112 - + # list of metrics to collect from application collect: # metric name app_metric: # type [gauge, counter, histogram, summary] - type: histogram - + type: histogram + # short description - help: "Custom application metric" - + help: "Custom application metric" + # metric groups/tags - labels: ["type"] - + labels: [ "type" ] + # for histogram only - buckets: [0.1, 0.2, 0.3, 1.0] + buckets: [ 0.1, 0.2, 0.3, 1.0 ] + + # objectives defines the quantile rank estimates with their respective + # absolute error [ for summary only ] + objectives: + - 1.4: 2.3 + - 2.0: 1.4 + # http service configuration. http: @@ -37,19 +44,19 @@ http: ssl: # custom https port (default 443) - port: 443 + port: 443 # force redirect to https connection redirect: true # ssl cert - cert: server.crt + cert: server.crt # ssl private key - key: server.key + key: server.key # rootCA certificate - rootCa: root.crt + rootCa: root.crt # HTTP service provides FastCGI as frontend fcgi: @@ -63,7 +70,7 @@ http: # enable H2C on TCP connections h2c: true - + # max transfer channels maxConcurrentStreams: 128 @@ -73,18 +80,18 @@ http: # file upload configuration. uploads: # list of file extensions which are forbidden for uploading. - forbid: [".php", ".exe", ".bat"] + forbid: [ ".php", ".exe", ".bat" ] # cidr blocks which can set ip using X-Real-Ip or X-Forwarded-For - trustedSubnets: ["10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10"] + trustedSubnets: [ "10.0.0.0/8", "127.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "::1/128", "fc00::/7", "fe80::/10" ] # http worker pool configuration. workers: # php worker command. - command: "php psr-worker.php pipes" + command: "php psr-worker.php pipes" # connection method (pipes, tcp://:9000, unix://socket.unix). default "pipes" - relay: "pipes" + relay: "pipes" # user under which process will be started user: "" @@ -95,13 +102,13 @@ http: numWorkers: 4 # maximum jobs per worker, 0 - unlimited. - maxJobs: 0 + maxJobs: 0 # for how long worker is allowed to be bootstrapped. allocateTimeout: 60 # amount of time given to worker to gracefully destruct itself. - destroyTimeout: 60 + destroyTimeout: 60 # Additional HTTP headers and CORS control. headers: @@ -157,10 +164,10 @@ limit: # static file serving. remove this section to disable static file serving. static: # root directory for static file (http would not serve .php and .htaccess files). - dir: "public" + dir: "public" # list of extensions for forbid for serving. - forbid: [".php", ".htaccess"] + forbid: [ ".php", ".htaccess" ] # Automatically add headers to every request. request: @@ -181,13 +188,13 @@ reload: interval: 1s # file extensions to watch, defaults to [.php] - patterns: [".php"] + patterns: [ ".php" ] # list of services to watch services: http: # list of dirs, "" root - dirs: [""] + dirs: [ "" ] # include sub directories recursive: true
\ No newline at end of file diff --git a/service/metrics/config.go b/service/metrics/config.go index c95fd940..023eff27 100644 --- a/service/metrics/config.go +++ b/service/metrics/config.go @@ -2,6 +2,7 @@ package metrics import ( "fmt" + "github.com/prometheus/client_golang/prometheus" "github.com/spiral/roadrunner/service" ) @@ -54,6 +55,8 @@ type Collector struct { Labels []string `json:"labels"` // Buckets for histogram metric. Buckets []float64 `json:"buckets"` + // Objectives for the summary opts + Objectives map[float64]float64 `json:"objectives"` } // Hydrate configuration. @@ -114,10 +117,11 @@ func (c *Config) getCollectors() (map[string]prometheus.Collector, error) { } case Summary: opts := prometheus.SummaryOpts{ - Name: name, - Namespace: m.Namespace, - Subsystem: m.Subsystem, - Help: m.Help, + Name: name, + Namespace: m.Namespace, + Subsystem: m.Subsystem, + Help: m.Help, + Objectives: m.Objectives, } if len(m.Labels) != 0 { diff --git a/service/metrics/config_test.go b/service/metrics/config_test.go index a64e9047..94f97da5 100644 --- a/service/metrics/config_test.go +++ b/service/metrics/config_test.go @@ -1,11 +1,12 @@ package metrics import ( + "testing" + json "github.com/json-iterator/go" "github.com/prometheus/client_golang/prometheus" "github.com/spiral/roadrunner/service" "github.com/stretchr/testify/assert" - "testing" ) type mockCfg struct{ cfg string } diff --git a/service/metrics/rpc.go b/service/metrics/rpc.go index 377d6173..0544d109 100644 --- a/service/metrics/rpc.go +++ b/service/metrics/rpc.go @@ -2,6 +2,7 @@ package metrics import ( "fmt" + "github.com/prometheus/client_golang/prometheus" ) @@ -134,6 +135,7 @@ func (rpc *rpcServer) Observe(m *Metric, ok *bool) (err error) { *ok = true return nil } + // Declare is used to register new collector in prometheus // THE TYPES ARE: // NamedCollector -> Collector with the name @@ -200,10 +202,11 @@ func (rpc *rpcServer) Declare(c *NamedCollector, ok *bool) (err error) { } case Summary: opts := prometheus.SummaryOpts{ - Name: c.Name, - Namespace: c.Namespace, - Subsystem: c.Subsystem, - Help: c.Help, + Name: c.Name, + Namespace: c.Namespace, + Subsystem: c.Subsystem, + Help: c.Help, + Objectives: c.Objectives, } if len(c.Labels) != 0 { |