Skip to content

Commit bdc6462

Browse files
authored
Separate web from worker metrics and add 2 more (#2)
* Report hostname to prometheus as the instance name * Separate worker from web metrics and add 2 more * Deprecate older ruby versions and add new ones in travis
1 parent 3d13dd9 commit bdc6462

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: ruby
22
rvm:
3-
- 2.1
4-
- 2.2
53
- 2.3
64
- 2.4
5+
- 2.5
6+
- 2.6
77
cache: bundler

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
scaltainer (0.3.0)
4+
scaltainer (0.4.0)
55
docker-api
66
dotenv
77
excon (>= 0.47.0)

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,13 @@ of the push gateway. For Kubernetes environments the above denotes the gateway s
6565
name (`prometheus-pushgateway`), where it is installed in the namespace called
6666
`monitoring`. Scaltainer will report the following metrics to Prometheus:
6767

68-
- `rayyan_controller_replicas`: number of replicas scaled (or untouched thereof).
68+
- `scaltainer_web_replicas_total`: number of web replicas scaled (or untouched thereof).
6969
This is labeled by the namespace and controller name, both matching the scaltainer
7070
configuration file.
71-
- `rayyan_scaltainer_ticks`: iterations scaltainer has performed (if `-w` is used)
71+
- `scaltainer_worker_replicas_total`: Same as above, but for workers
72+
- `scaltainer_web_response_time_seconds`: response times as reported by the web services
73+
- `scaltainer_worker_queue_size_total`: queue sizes as reported by the worker services
74+
- `scaltainer_ticks_total`: iterations scaltainer has performed (if `-w` is used)
7275

7376
## Configuration
7477

lib/scaltainer/runner.rb

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "yaml"
2+
require 'socket'
23
require 'prometheus/client'
34
require 'prometheus/client/push'
45

@@ -81,6 +82,8 @@ def process_service(service_name, config, state, namespace, type, metrics)
8182
@logger.debug "#{service.type.capitalize} #{service.name} is currently configured for #{current_replicas} replica(s)"
8283
metric = metrics[service.name]
8384
raise Scaltainer::Warning.new("Configured #{service.type} '#{service.name}' not found in metrics endpoint") unless metric
85+
state["metric"] = metric
86+
state["service_type"] = type.to_s
8487
desired_replicas = type.determine_desired_replicas metric, config, current_replicas
8588
@logger.debug "Desired number of replicas for #{service.type} #{service.name} is #{desired_replicas}"
8689
adjusted_replicas = type.adjust_desired_replicas(desired_replicas, config)
@@ -121,16 +124,29 @@ def scale_out(service, current_replicas, desired_replicas)
121124

122125
def register_pushgateway(pushgateway)
123126
@registry = Prometheus::Client.registry
124-
@replicas_gauge = @registry.gauge(:rayyan_controller_replicas, docstring: 'Rayyan replicas', labels: [:controller, :namespace])
125-
@ticks_counter = @registry.counter(:rayyan_scaltainer_ticks, docstring: 'Rayyan Scaltainer ticks', labels: [:namespace])
127+
@web_replicas_gauge = @registry.gauge(:scaltainer_web_replicas_total, docstring: 'Scaltainer controller replicas for web services', labels: [:controller, :namespace])
128+
@worker_replicas_gauge = @registry.gauge(:scaltainer_worker_replicas_total, docstring: 'Scaltainer controller replicas for worker services', labels: [:controller, :namespace])
129+
@web_metrics_gauge = @registry.gauge(:scaltainer_web_response_time_seconds, docstring: 'Scaltainer controller response time metric in seconds', labels: [:controller, :namespace])
130+
@worker_metrics_gauge = @registry.gauge(:scaltainer_worker_queue_size_total, docstring: 'Scaltainer controller queue size metric', labels: [:controller, :namespace])
131+
@ticks_counter = @registry.counter(:scaltainer_ticks_total, docstring: 'Scaltainer ticks', labels: [:namespace])
126132

127-
@pushgateway = Prometheus::Client::Push.new("scaltainer", "scaltainer", "http://#{pushgateway}")
133+
@pushgateway = Prometheus::Client::Push.new("scaltainer", Socket.gethostname, "http://#{pushgateway}")
128134
end
129135

130136
def sync_pushgateway(namespace, state)
131137
@logger.debug("Now syncing state #{state} in namespace #{namespace}")
138+
factor = 1
132139
state.each do |service, state|
133-
@replicas_gauge.set(state["replicas"], labels: {namespace: namespace, controller: service}) if state["replicas"]
140+
if state["service_type"] == 'Web'
141+
replicas_gauge = @web_replicas_gauge
142+
metrics_gauge = @web_metrics_gauge
143+
factor = 0.001
144+
else
145+
replicas_gauge = @worker_replicas_gauge
146+
metrics_gauge = @worker_metrics_gauge
147+
end
148+
replicas_gauge.set(state["replicas"], labels: {namespace: namespace, controller: service})
149+
metrics_gauge.set(state["metric"] * factor, labels: {namespace: namespace, controller: service})
134150
end
135151
@ticks_counter.increment(labels: {namespace: namespace})
136152
begin

lib/scaltainer/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Scaltainer
2-
VERSION = "0.3.0"
2+
VERSION = "0.4.0"
33
end

0 commit comments

Comments
 (0)