grafana-rb 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/grafana-rb/cli.rb +29 -9
- data/lib/grafana-rb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3156ec2300608d7d5823033df58876cdf87ed54e
|
4
|
+
data.tar.gz: b4a2f11146e868cb6499d7ae954ae05f2ba0c9d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a640c8ebbf28899e98017853f94168deaaaf9890d4267344b8cdd06043c38b8bda991ecc9ff9267742fb7be2d8ebfbeacc8a2babdd773299c8c16d941a196ffc
|
7
|
+
data.tar.gz: 5486cd0110270a11c408f6a1b26f8805b9ee1181f9f0c2a88ddf030ed6a4a949436e5fd3aec13eb352464110c4e8f36d825833183639501b9162248036eef740
|
data/CHANGELOG.md
CHANGED
data/lib/grafana-rb/cli.rb
CHANGED
@@ -7,11 +7,15 @@ module GrafanaRb
|
|
7
7
|
class Cli
|
8
8
|
def initialize(argv)
|
9
9
|
@argv = argv
|
10
|
+
@workdir = Dir.pwd
|
10
11
|
@panel_id = 0
|
11
12
|
end
|
12
13
|
|
13
14
|
def run
|
14
|
-
if @argv
|
15
|
+
if @argv.last == "apply" || @argv.last == "a" || @argv.last == "q"
|
16
|
+
if @argv.size >= 2
|
17
|
+
@workdir = @argv[0]
|
18
|
+
end
|
15
19
|
apply
|
16
20
|
else
|
17
21
|
usage
|
@@ -19,12 +23,15 @@ module GrafanaRb
|
|
19
23
|
end
|
20
24
|
|
21
25
|
private
|
22
|
-
CONFIG_FILE = "grafana.yml"
|
23
26
|
REQUIRE_DEFAULT_TEMPLATE = ["*.yml"]
|
24
27
|
DEFAULT_GRAFANA_USER = "admin"
|
25
28
|
DEFAULT_GRAFANA_PASSWORD = "admin"
|
26
29
|
TAG = "grafana-rb"
|
27
30
|
|
31
|
+
def config_file
|
32
|
+
@config_file ||= File.join(@workdir, "grafana.yml")
|
33
|
+
end
|
34
|
+
|
28
35
|
def request(method, path, params = {})
|
29
36
|
uri = URI("http://" + config["grafana_url"] + path)
|
30
37
|
http = Net::HTTP.new(uri.host, uri.port)
|
@@ -60,11 +67,12 @@ module GrafanaRb
|
|
60
67
|
end
|
61
68
|
|
62
69
|
def check_config_existance
|
63
|
-
unless File.exists?(
|
64
|
-
puts "FATAL: missed #{
|
65
|
-
puts "#{
|
70
|
+
unless File.exists?(config_file)
|
71
|
+
puts "FATAL: missed #{config_file} in current directory"
|
72
|
+
puts "#{config_file} example:"
|
66
73
|
puts ""
|
67
74
|
puts "---"
|
75
|
+
puts "tool_version: #{GrafanaRb::VERSION}"
|
68
76
|
puts "grafana_url: monitoring.your-domain.com:3000 # required"
|
69
77
|
puts "prometheus_url: monitoring.your-domain.com:9090 # required"
|
70
78
|
puts "grafana_user: user # 'admin' if missed"
|
@@ -79,7 +87,7 @@ module GrafanaRb
|
|
79
87
|
end
|
80
88
|
|
81
89
|
def config
|
82
|
-
@config ||= YAML.load(File.read(
|
90
|
+
@config ||= YAML.load(File.read(config_file)) || {}
|
83
91
|
end
|
84
92
|
|
85
93
|
def grafana_user
|
@@ -92,8 +100,8 @@ module GrafanaRb
|
|
92
100
|
|
93
101
|
def require_files
|
94
102
|
@require_files ||= (config["require"] || REQUIRE_DEFAULT_TEMPLATE).flat_map { |template|
|
95
|
-
Dir[template]
|
96
|
-
}.map { |path| File.expand_path(path) } - [File.expand_path(
|
103
|
+
Dir[File.join(@workdir, template)]
|
104
|
+
}.map { |path| File.expand_path(path) } - [File.expand_path(config_file)]
|
97
105
|
end
|
98
106
|
|
99
107
|
def dashboards
|
@@ -312,6 +320,13 @@ module GrafanaRb
|
|
312
320
|
check_config_existance
|
313
321
|
die("missed grafana_url variable") unless config["grafana_url"]
|
314
322
|
die("missed prometheus_url variable") unless config["prometheus_url"]
|
323
|
+
|
324
|
+
tool_version = config["version"] || GrafanaRb::VERSION
|
325
|
+
if compare_versions(tool_version, GrafanaRb::VERSION) > 0
|
326
|
+
puts "FATAL: need at least '#{tool_version}' tool version but current version is '#{GrafanaRb::VERSION}'"
|
327
|
+
exit -1
|
328
|
+
end
|
329
|
+
|
315
330
|
create_or_update_prometheus_datasource
|
316
331
|
create_or_update_slack_notifications if config["slack_url"] && config["slack_channel"]
|
317
332
|
dashboards.each do |dashboard|
|
@@ -321,12 +336,17 @@ module GrafanaRb
|
|
321
336
|
puts "done."
|
322
337
|
end
|
323
338
|
|
339
|
+
def compare_versions(a, b)
|
340
|
+
parse = proc { |v| v.split(".", 3).map(&:to_i) + [v.index("-dev") ? 1 : 0] }
|
341
|
+
parse.call(a) <=> parse.call(b)
|
342
|
+
end
|
343
|
+
|
324
344
|
def usage
|
325
345
|
puts "Grafana-rb: utility to configure grafana dashboards as a code"
|
326
346
|
puts "Version: #{VERSION}"
|
327
347
|
puts ""
|
328
348
|
puts "Usage:"
|
329
|
-
puts " grafana-rb <cmd>"
|
349
|
+
puts " grafana-rb [work-dir] <cmd>"
|
330
350
|
puts ""
|
331
351
|
puts "Commands:"
|
332
352
|
puts " apply - update dashboards"
|
data/lib/grafana-rb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grafana-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Vakhov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|