consul-templaterb 1.17.2 → 1.17.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +7 -0
- data/lib/consul/async/version.rb +1 -1
- data/samples/prometheus_consul_coordinates.erb +138 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2fee3b4923d19a2979d9dd2351926f95f9c3fbc6
|
4
|
+
data.tar.gz: 20a354d4f4b0a483fd4da2eae328dfec1033832b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6756e96182db6c5372df52d20388cd765873fce39f2eddd8d302119d17238138cd1790536e4502541a8a002d1fd10505d92bb2767a1b74587656d6c9acc213b7
|
7
|
+
data.tar.gz: 4eea6b3450a7894ace920ef7a3560d33a10d916c4a3c3696202edc93a237502273d16840c8bd9c0efb82ebf4b56773642e94294bee892fdb07f0cbdd9739704d
|
data/CHANGELOG.md
CHANGED
data/lib/consul/async/version.rb
CHANGED
@@ -0,0 +1,138 @@
|
|
1
|
+
# HELP consul_node_rtt_min_seconds Min Round trip with other servers of DC
|
2
|
+
# TYPE consul_node_rtt_min_seconds gauge
|
3
|
+
|
4
|
+
# HELP consul_node_rtt_max_seconds Max Round trip with other servers of DC
|
5
|
+
# TYPE consul_node_rtt_max_seconds gauge
|
6
|
+
|
7
|
+
# HELP consul_node_rtt_sum_seconds Sum in seconds of all RTTs with all other servers
|
8
|
+
# TYPE consul_node_rtt_sum_seconds gauge
|
9
|
+
|
10
|
+
# HELP consul_node_rtt_count Number of nodes
|
11
|
+
# TYPE consul_node_rtt_count gauge
|
12
|
+
<%
|
13
|
+
unless @consul_node_settings
|
14
|
+
@consul_node_settings = {
|
15
|
+
:compute_duration => 0,
|
16
|
+
:initialized => false,
|
17
|
+
:last_results => {},
|
18
|
+
:last_update => Time.parse('2019-01-01 00:00:00 +0100'),
|
19
|
+
:num_cpus => (ENV['CONSUL_COORDINATES_CPUS'] || ENV['MARATHON_APP_RESOURCE_CPUS'] || '-1').to_f.floor,
|
20
|
+
:percentiles => (ENV['CONSUL_COORDINATES_PERCENTILES'] || '.5,.9,.99,.999').split(',').map {|s| s.to_f},
|
21
|
+
}
|
22
|
+
if @consul_node_settings[:num_cpus] < 0
|
23
|
+
require 'etc'
|
24
|
+
@consul_node_settings[:num_cpus] = Etc.nprocessors - 1
|
25
|
+
STDERR.puts "Autodetected #{@consul_node_settings[:num_cpus]} CPUs"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
@consul_node_settings[:percentiles].each do |pctl|
|
30
|
+
fname = "consul_rtt_nodes_q#{pctl.to_s.sub('.', '_')}_seconds"
|
31
|
+
%># HELP <%= fname %> Get the percentile <%= pctl %>
|
32
|
+
# TYPE <%= fname %> gauge
|
33
|
+
|
34
|
+
<%
|
35
|
+
end
|
36
|
+
nodes_meta = nodes.map{ |n| [n['Node'], n['Meta']]}.to_h
|
37
|
+
nodes_coordinates = coordinate.nodes.map { |n| [n['Node'], n] }.to_h
|
38
|
+
|
39
|
+
unless @consul_node_settings[:initialized]
|
40
|
+
@consul_node_settings[:initialized] = true
|
41
|
+
# compute percentile on sorted values
|
42
|
+
def percentile(values_sorted, percentile)
|
43
|
+
k = (percentile*(values_sorted.length-1)+1).floor - 1
|
44
|
+
f = (percentile*(values_sorted.length-1)+1).modulo(1)
|
45
|
+
return values_sorted[k] + (f * (values_sorted[k+1] - values_sorted[k]))
|
46
|
+
end
|
47
|
+
|
48
|
+
# build default statistics
|
49
|
+
def build_stats
|
50
|
+
{
|
51
|
+
'_values' => [],
|
52
|
+
'min_seconds' => 3600,
|
53
|
+
'max_seconds' => 0,
|
54
|
+
'sum_seconds' => 0,
|
55
|
+
'count' => 0,
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
# Add node RTT
|
60
|
+
def add_node_rtt(node_info, rtt_val)
|
61
|
+
vals = node_info['_values']
|
62
|
+
idx = vals.bsearch_index { |x| x > rtt_val }
|
63
|
+
if idx.nil?
|
64
|
+
vals << rtt_val
|
65
|
+
else
|
66
|
+
vals = vals.insert(idx, rtt_val)
|
67
|
+
end
|
68
|
+
node_info['_values'] = vals
|
69
|
+
node_info['min_seconds'] = rtt_val if node_info['min_seconds'] > rtt_val
|
70
|
+
node_info['max_seconds'] = rtt_val if node_info['max_seconds'] < rtt_val
|
71
|
+
node_info['sum_seconds'] += rtt_val
|
72
|
+
node_info['count'] += 1
|
73
|
+
node_info
|
74
|
+
end
|
75
|
+
|
76
|
+
def compute_node_data(src, nodes_meta, nodes_coordinates)
|
77
|
+
node_info = {
|
78
|
+
'results' => build_stats,
|
79
|
+
}
|
80
|
+
metas = nodes_meta[src] || {}
|
81
|
+
metas['src'] = src
|
82
|
+
node_info['metas'] = metas.select {|k,v| !v.empty?}.map{|k,v| "#{k}=\"#{v}\""}.join(',')
|
83
|
+
results = node_info['results']
|
84
|
+
n1 = nodes_coordinates[src]
|
85
|
+
# Handle coordinates not there yet
|
86
|
+
return node_info unless n1
|
87
|
+
nodes_coordinates.each do |c2n, n2|
|
88
|
+
rtt_val = coordinate.rtt(n1['Coord'], n2['Coord'])
|
89
|
+
results = add_node_rtt(results, rtt_val)
|
90
|
+
end
|
91
|
+
@consul_node_settings[:percentiles].each do |pctl|
|
92
|
+
results["q#{pctl.to_s.sub('.', '_')}_seconds"] = percentile(results["_values"], pctl)
|
93
|
+
end unless results["_values"].empty?
|
94
|
+
node_info
|
95
|
+
end
|
96
|
+
|
97
|
+
def compute_map_keys(nodeCoords, nodes_meta, nodes_coordinates)
|
98
|
+
node_name = nodeCoords['Node']
|
99
|
+
[node_name, compute_node_data(node_name, nodes_meta, nodes_coordinates)]
|
100
|
+
end
|
101
|
+
|
102
|
+
def compute_all_results(nodes_meta, nodes_coordinates)
|
103
|
+
start_now = Time.now.utc
|
104
|
+
last_updated = @consul_node_settings[:last_update]
|
105
|
+
# We compute every 30 seconds max
|
106
|
+
if (start_now - last_updated).round > 30 && !nodes_meta.empty? && !nodes_coordinates.empty?
|
107
|
+
if @consul_node_settings[:num_cpus] > 1
|
108
|
+
require 'parallel'
|
109
|
+
all_nodes = Parallel.map(nodes_coordinates, in_processes: @consul_node_settings[:num_cpus] - 1) {|_, c| compute_map_keys(c, nodes_meta, nodes_coordinates)}
|
110
|
+
else
|
111
|
+
all_nodes = nodes_coordinates.map {|_, c| compute_map_keys(c, nodes_meta, nodes_coordinates)}
|
112
|
+
end
|
113
|
+
@consul_node_settings[:last_results] = all_nodes
|
114
|
+
@consul_node_settings[:last_update] = Time.now.utc
|
115
|
+
@consul_node_settings[:compute_duration] = @consul_node_settings[:last_update] - start_now
|
116
|
+
end
|
117
|
+
@consul_node_settings[:last_results]
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
all_nodes = compute_all_results(nodes_meta, nodes_coordinates)
|
122
|
+
%>
|
123
|
+
# HELP consul_node_rtt_compute_duration Time needed to compute all results in seconds
|
124
|
+
# TYPE consul_node_rtt_compute_duration gauge
|
125
|
+
consul_node_rtt_compute_duration <%= @consul_node_settings[:compute_duration] %>
|
126
|
+
consul_node_rtt_compute_cpus <%= @consul_node_settings[:num_cpus] %>
|
127
|
+
consul_node_rtt_compute_nodes_meta_count <%= nodes_meta.count %>
|
128
|
+
consul_node_rtt_compute_nodes_coordinates_count <%= nodes_coordinates.count %>
|
129
|
+
|
130
|
+
<%
|
131
|
+
all_nodes.each do |node, node_info|
|
132
|
+
node_info['results'].each do |k, v|
|
133
|
+
next if k.start_with? '_'
|
134
|
+
%>consul_node_rtt_<%= k %>{<%= node_info['metas'] %>} <%= v.round(5) %>
|
135
|
+
<%
|
136
|
+
end
|
137
|
+
end
|
138
|
+
%>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consul-templaterb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.17.
|
4
|
+
version: 1.17.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SRE Core Services
|
@@ -212,6 +212,7 @@ files:
|
|
212
212
|
- samples/kv_yaml_to_json.json.erb
|
213
213
|
- samples/metrics.erb
|
214
214
|
- samples/nodes.html.erb
|
215
|
+
- samples/prometheus_consul_coordinates.erb
|
215
216
|
- samples/render_template_from_kv.erb
|
216
217
|
- samples/sample_keys.html.erb
|
217
218
|
- samples/service_checks_metrics.erb
|
@@ -242,7 +243,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
242
243
|
- !ruby/object:Gem::Version
|
243
244
|
version: '0'
|
244
245
|
requirements: []
|
245
|
-
|
246
|
+
rubyforge_project:
|
247
|
+
rubygems_version: 2.6.14.4
|
246
248
|
signing_key:
|
247
249
|
specification_version: 4
|
248
250
|
summary: Implementation of Consul template using Ruby and .erb templating language
|