prometheus-config-builder 0.0.11 → 0.0.12
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37a41a4e9ee37b38bd8bc7c7025c60732aa7b5f9
|
4
|
+
data.tar.gz: 98ccfbd194f736ff97ead53a8fc5ccf12b20f9f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11c610a52b55816774141a432b0c4e527d3b076b8e6cdef200dcb3b4d0084699dbab2dcf422d497826f9f0f57b24f3e3d141168de5c9dbcf84f86982dd11e5e5
|
7
|
+
data.tar.gz: 7c958b3d7fce912530951fd10c6ce16cee716528666d01a6a925b2deda8179abe7055e07d1522c82c54958f65bc112e4f71131bd69060a7f132e555cdb69b0db
|
@@ -8,6 +8,9 @@ require 'prometheus-config-builder'
|
|
8
8
|
require 'pp'
|
9
9
|
require 'yaml'
|
10
10
|
require 'json'
|
11
|
+
require 'prometheus_exporter'
|
12
|
+
require 'prometheus_exporter/client'
|
13
|
+
require 'prometheus_exporter/server'
|
11
14
|
|
12
15
|
config = {}
|
13
16
|
config[:paths] ||= []
|
@@ -15,6 +18,17 @@ config[:root] ||= 'test/data'
|
|
15
18
|
config[:every] = 60
|
16
19
|
config[:pgrep] = nil
|
17
20
|
|
21
|
+
server = PrometheusExporter::Server::WebServer.new port: 12345
|
22
|
+
PrometheusExporter::Client.default = PrometheusExporter::LocalClient.new(collector: server.collector)
|
23
|
+
server.start
|
24
|
+
|
25
|
+
something_changed_count = PrometheusExporter::Client.default.register(:counter, "prometheusconfigbuilder_changes_count", "Number of times configuration has changed.")
|
26
|
+
error_count = PrometheusExporter::Client.default.register(:counter, "prometheusconfigbuilder_errors_count", "Number of exceptions during evaluation.")
|
27
|
+
iteration_count = PrometheusExporter::Client.default.register(:counter, "prometheusconfigbuilder_iteration_count", "Number of times configuration has changed.")
|
28
|
+
iteration_duration = PrometheusExporter::Client.default.register(:gauge, "prometheusconfigbuilder_last_iteration_duration", "Duration (in seconds) of the last full config iteration")
|
29
|
+
|
30
|
+
error_count.observe(0)
|
31
|
+
|
18
32
|
# Defaults
|
19
33
|
op = OptionParser.new do |o|
|
20
34
|
o.banner = "Usage: #{$PROGRAM_NAME} [OPTIONS]"
|
@@ -72,7 +86,17 @@ end
|
|
72
86
|
|
73
87
|
|
74
88
|
loop do
|
75
|
-
|
89
|
+
starting = Time.now
|
90
|
+
begin
|
91
|
+
something_changed = builder.write_out()
|
92
|
+
rescue Exception => e
|
93
|
+
log.warn("Error while building config: #{e}")
|
94
|
+
error_count.increment
|
95
|
+
next
|
96
|
+
end
|
97
|
+
|
98
|
+
something_changed_count.increment if something_changed
|
99
|
+
iteration_count.increment
|
76
100
|
|
77
101
|
# Send a SIGHUP signal to Prometheus so that it knows to reload config files
|
78
102
|
if something_changed && config[:pgrep] != nil
|
@@ -89,5 +113,8 @@ loop do
|
|
89
113
|
log.level = Logger::WARN
|
90
114
|
end
|
91
115
|
|
116
|
+
ending = Time.now
|
117
|
+
iteration_duration.observe(ending-starting)
|
118
|
+
|
92
119
|
sleep(config[:every])
|
93
120
|
end
|
@@ -14,8 +14,8 @@ require 'logger'
|
|
14
14
|
require_relative './logger.rb'
|
15
15
|
require_relative './scrape_passthrough.rb'
|
16
16
|
require_relative './scrape_ecs.rb'
|
17
|
-
|
18
|
-
|
17
|
+
require 'prometheus_exporter'
|
18
|
+
require 'prometheus_exporter/client'
|
19
19
|
|
20
20
|
module PrometheusConfigBuilder
|
21
21
|
|
@@ -202,6 +202,9 @@ module PrometheusConfigBuilder
|
|
202
202
|
@discoverer = ConfigDiscover.new
|
203
203
|
@paths = []
|
204
204
|
@last_hash = ""
|
205
|
+
|
206
|
+
@@config_files = PrometheusExporter::Client.default.register(:gauge, "prometheusconfigbuilder_config_files", "Number of found config files")
|
207
|
+
|
205
208
|
end
|
206
209
|
|
207
210
|
def add_path(path)
|
@@ -224,6 +227,8 @@ module PrometheusConfigBuilder
|
|
224
227
|
cfs.add(cf)
|
225
228
|
end
|
226
229
|
|
230
|
+
@@config_files.observe(files.length)
|
231
|
+
|
227
232
|
rules_dir = @dst_dir + "/rules"
|
228
233
|
scrape_files_dir = @dst_dir + "/scrape_files"
|
229
234
|
cfs.set_rules_dir(rules_dir)
|
@@ -23,23 +23,7 @@ module PrometheusConfigBuilder
|
|
23
23
|
})
|
24
24
|
$VERBOSE = x
|
25
25
|
tasks = get_tasks(config["cluster"], config["service"])
|
26
|
-
|
27
|
-
|
28
|
-
targets = []
|
29
|
-
ips.each do |ip|
|
30
|
-
if config["metrics_port"]
|
31
|
-
targets << ip + ":" + config["metrics_port"].to_s
|
32
|
-
else
|
33
|
-
targets << ip
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
data = [
|
38
|
-
{
|
39
|
-
"targets" => targets,
|
40
|
-
"labels" => config["labels"]
|
41
|
-
}
|
42
|
-
]
|
26
|
+
endpoints = get_task_endpoints(config["cluster"], tasks, config["labels"], config["metrics_port"])
|
43
27
|
|
44
28
|
if !config["job_name"]
|
45
29
|
logger.warn("File #{basename}: the scrape_configs of type:ecs-tasks doesn't have \"job_name\" field set. Ignoring!")
|
@@ -48,7 +32,7 @@ module PrometheusConfigBuilder
|
|
48
32
|
|
49
33
|
file = File.expand_path(dst_prefix + "_" + config["job_name"] + ".json")
|
50
34
|
File.open(file, "w") do |file|
|
51
|
-
file.write(
|
35
|
+
file.write(endpoints.to_json)
|
52
36
|
end
|
53
37
|
|
54
38
|
# Make copy of the settings and remove our custom properties from it.
|
@@ -96,8 +80,8 @@ module PrometheusConfigBuilder
|
|
96
80
|
return tasks
|
97
81
|
end
|
98
82
|
|
99
|
-
def self.
|
100
|
-
|
83
|
+
def self.get_task_endpoints(cluster, tasks, common_labels, metrics_port)
|
84
|
+
endpoints = []
|
101
85
|
task_chunk = tasks.pop(100)
|
102
86
|
loop do
|
103
87
|
begin
|
@@ -110,7 +94,16 @@ module PrometheusConfigBuilder
|
|
110
94
|
result.tasks.each do |task|
|
111
95
|
# FIXME: This assumes somewhat on the ip structure.
|
112
96
|
ip = task.containers[0].network_interfaces[0].private_ipv_4_address
|
113
|
-
|
97
|
+
|
98
|
+
if metrics_port
|
99
|
+
ip = ip + ":" + metrics_port.to_s
|
100
|
+
end
|
101
|
+
labels = common_labels.clone
|
102
|
+
labels["ecs_arn"] = task.task_arn
|
103
|
+
endpoints << {
|
104
|
+
"targets" => [ip],
|
105
|
+
"labels" => labels
|
106
|
+
}
|
114
107
|
end
|
115
108
|
end
|
116
109
|
rescue Aws::ECS::Errors::ServiceError => e
|
@@ -121,7 +114,7 @@ module PrometheusConfigBuilder
|
|
121
114
|
break if tasks.length == 0
|
122
115
|
task_chunk = tasks.pop(100)
|
123
116
|
end
|
124
|
-
return
|
117
|
+
return endpoints
|
125
118
|
end
|
126
119
|
|
127
120
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'prometheus-config-builder'
|
6
|
-
s.version = '0.0.
|
6
|
+
s.version = '0.0.12'
|
7
7
|
s.date = Time.now
|
8
8
|
|
9
9
|
s.summary = %q{Template based config generation}
|
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.required_ruby_version = '>= 2.0.0'
|
17
17
|
|
18
18
|
s.add_dependency 'aws-sdk', '~> 3'
|
19
|
+
s.add_dependency 'prometheus_exporter', '>= 0.4.13'
|
19
20
|
|
20
21
|
s.add_development_dependency 'rubygems-tasks', '~> 0.2'
|
21
22
|
s.add_development_dependency 'minitest', '~> 5.4'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prometheus-config-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juho Mäkinen juho.makinen@gmail.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: prometheus_exporter
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.4.13
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.4.13
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rubygems-tasks
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|