munin2graphite 0.2.3 → 0.3.0
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 +4 -4
- data/Gemfile +1 -0
- data/VERSION +1 -1
- data/lib/ast_node.rb +5 -5
- data/lib/munin2graphite/config.rb +1 -1
- data/lib/munin2graphite/scheduler.rb +28 -19
- data/lib/munin_graph.rb +19 -19
- data/munin2graphite.gemspec +7 -4
- data/test/test_my_graph.rb +3 -1
- metadata +23 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4726ddda92c26d794bb3015c44dee126bfc5aa04
|
4
|
+
data.tar.gz: 55e16f215324c77407719c6bf7410bf26e0e1dff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b996f9f88b6b11cd094d0829de7eadce6806e741e764ed35b9368593848260f4f0724c88a458cdc9d5eca41f1a5fd869d3890b6a3655676636d1f19e8116c90
|
7
|
+
data.tar.gz: ed9c0b1867ff224575713f17108d28536836c4247b64ba965f4c13dd17b3e4a200a2b065e448d6fe29710f9b4e1ea184a03313c233aa0cedcd6432f8b805a254
|
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/ast_node.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'cgi'
|
2
2
|
|
3
3
|
class ASTNode
|
4
4
|
|
@@ -92,14 +92,14 @@ class ASTNode
|
|
92
92
|
aux_graph_properties.delete :yMin
|
93
93
|
end
|
94
94
|
|
95
|
-
aux = aux_graph_properties.map{|i,j| "#{i}=#{
|
95
|
+
aux = aux_graph_properties.map{|i,j| "#{i}=#{CGI.escape(j.to_s.gsub('%','percent'))}"}.join("&")
|
96
96
|
return aux
|
97
97
|
end
|
98
98
|
|
99
99
|
# This returns the url field of the graph after compiling it
|
100
100
|
def url
|
101
101
|
self.compile
|
102
|
-
url = "#{properties[:endpoint]}/render/?width=586&height=308&#{properties_to_url}&target=" +
|
102
|
+
url = "#{properties[:endpoint]}/render/?width=586&height=308&#{properties_to_url}&target=" + CGI.escape(targets.map{|i| i.compile}.compact.join("&target="))
|
103
103
|
end
|
104
104
|
|
105
105
|
def to_gdash
|
@@ -124,7 +124,7 @@ end
|
|
124
124
|
class GlobalDeclarationNode < ASTNode
|
125
125
|
def initialize(line)
|
126
126
|
super
|
127
|
-
line =~ /^([\
|
127
|
+
line =~ /^([\w]*)\ (.*)/
|
128
128
|
@value = $2
|
129
129
|
end
|
130
130
|
end
|
@@ -254,7 +254,7 @@ class FieldPropertyNode < ASTNode
|
|
254
254
|
|
255
255
|
def initialize(line)
|
256
256
|
super
|
257
|
-
line =~ /([\
|
257
|
+
line =~ /([\w]+)\.(\w+)\ (.*)$/
|
258
258
|
@metric = $1
|
259
259
|
@function = $2
|
260
260
|
@value = $3
|
@@ -17,6 +17,7 @@
|
|
17
17
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18
18
|
require 'rufus/scheduler'
|
19
19
|
require 'thread'
|
20
|
+
require 'diplomat'
|
20
21
|
module Munin2Graphite
|
21
22
|
##
|
22
23
|
# This class holds the main scheduler of the system, it will perform the applicacion loops
|
@@ -41,13 +42,30 @@ module Munin2Graphite
|
|
41
42
|
raise "CategoryNotFound in #{config}"
|
42
43
|
end
|
43
44
|
|
45
|
+
def workers_from_consul_config!
|
46
|
+
return unless @config['consul_url']
|
47
|
+
Diplomat.configure do |c|
|
48
|
+
c.url = @config['consul_url']
|
49
|
+
end
|
50
|
+
Diplomat::Service.get(@config['consul_service'], :all).each do |i|
|
51
|
+
@config.config.params['workers'] ||= []
|
52
|
+
@config.config.params['workers'] << i['Node']
|
53
|
+
@config.config.params[i['Node']] = {
|
54
|
+
'munin_hostname' => i['Address'],
|
55
|
+
'munin_port' => i['ServicePort'],
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
44
60
|
def munin_config(reload = false)
|
45
61
|
return @munin_config if @munin_config && !reload
|
46
62
|
@munin_config = {}
|
47
63
|
@config.log.info("Obtaining metrics configuration")
|
48
64
|
@munin_config[:workers] = []
|
65
|
+
|
49
66
|
semaphore = Mutex.new
|
50
67
|
threads = []
|
68
|
+
|
51
69
|
workers.each do |worker|
|
52
70
|
threads << Thread.new do
|
53
71
|
current_config = {}
|
@@ -60,6 +78,7 @@ module Munin2Graphite
|
|
60
78
|
config.log.error("This node will be skipped")
|
61
79
|
Thread.current.exit
|
62
80
|
end
|
81
|
+
|
63
82
|
current_config[:nodes] = {}
|
64
83
|
semaphore_nodes = Mutex.new
|
65
84
|
threads_nodes = []
|
@@ -112,6 +131,7 @@ module Munin2Graphite
|
|
112
131
|
end
|
113
132
|
|
114
133
|
def workers
|
134
|
+
workers_from_consul_config!
|
115
135
|
@workers ||= (@config.workers.empty? ? ["global"] : @config.workers )
|
116
136
|
end
|
117
137
|
|
@@ -135,19 +155,16 @@ module Munin2Graphite
|
|
135
155
|
metrics_threads = []
|
136
156
|
categories = {}
|
137
157
|
metrics.each do |metric|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
@config.log.error(e.backtrace.inspect)
|
147
|
-
end
|
158
|
+
begin
|
159
|
+
local_munin = Munin::Node.new(config["munin_hostname"],config["munin_port"])
|
160
|
+
values[metric] = local_munin.fetch metric
|
161
|
+
local_munin.disconnect
|
162
|
+
rescue Exception => e
|
163
|
+
@config.log.error("There was a problem when getting the metric #{metric} for #{node} , Ignored")
|
164
|
+
@config.log.error(e.message)
|
165
|
+
@config.log.error(e.backtrace.inspect)
|
148
166
|
end
|
149
167
|
end
|
150
|
-
metrics_threads.each {|i| i.join}
|
151
168
|
config.log.debug(values.inspect)
|
152
169
|
config.log.info("Done with: #{node} (#{Time.now - metric_time} s)")
|
153
170
|
carbon = @carbon || Carbon.new(config["carbon_hostname"],config["carbon_port"])
|
@@ -233,14 +250,6 @@ module Munin2Graphite
|
|
233
250
|
@scheduler.every config["scheduler_metrics_period"] do
|
234
251
|
metric_loop(worker)
|
235
252
|
end
|
236
|
-
|
237
|
-
=begin
|
238
|
-
# Graph rereading is disabled by now there are concurrency problems
|
239
|
-
@scheduler.every config["scheduler_graphs_period"] do
|
240
|
-
obtain_graphs
|
241
|
-
end
|
242
|
-
=end
|
243
|
-
|
244
253
|
end
|
245
254
|
end
|
246
255
|
end
|
data/lib/munin_graph.rb
CHANGED
@@ -85,25 +85,25 @@ class MuninGraph
|
|
85
85
|
{:matcher => /^graph_width .*/, :klass => GraphWidthGlobalDeclarationNode},
|
86
86
|
{:matcher => /^graph_height .*/, :klass => GraphHeightGlobalDeclarationNode},
|
87
87
|
{:matcher => /^graph_printfformat .*/, :klass => GraphPrintFormatGlobalDeclarationNode},
|
88
|
-
{:matcher => /([\
|
89
|
-
{:matcher => /([\
|
90
|
-
{:matcher => /([\
|
91
|
-
{:matcher => /([\
|
92
|
-
{:matcher => /([\
|
93
|
-
{:matcher => /([\
|
94
|
-
{:matcher => /([\
|
95
|
-
{:matcher => /([\
|
96
|
-
{:matcher => /([\
|
97
|
-
{:matcher => /([\
|
98
|
-
{:matcher => /([\
|
99
|
-
{:matcher => /([\
|
100
|
-
{:matcher => /([\
|
101
|
-
{:matcher => /([\
|
102
|
-
{:matcher => /([\
|
103
|
-
{:matcher => /([\
|
104
|
-
{:matcher => /([\
|
105
|
-
{:matcher => /([\
|
106
|
-
{:matcher => /([\
|
88
|
+
{:matcher => /([\w]+)\.label\ .*$/,:klass => LabelFieldPropertyNode},
|
89
|
+
{:matcher => /([\w]+)\.cdef\ .*$/,:klass => CDefFieldPropertyNode},
|
90
|
+
{:matcher => /([\w]+)\.draw\ .*$/,:klass => DrawFieldPropertyNode},
|
91
|
+
{:matcher => /([\w]+)\.graph\ .*$/,:klass => GraphFieldPropertyNode},
|
92
|
+
{:matcher => /([\w]+)\.info\ .*$/,:klass => InfoFieldPropertyNode},
|
93
|
+
{:matcher => /([\w]+)\.extinfo\ .*$/,:klass => ExtInfoFieldPropertyNode},
|
94
|
+
{:matcher => /([\w]+)\.max\ .*$/,:klass => MaxFieldPropertyNode},
|
95
|
+
{:matcher => /([\w]+)\.min\ .*$/,:klass => MinFieldPropertyNode},
|
96
|
+
{:matcher => /([\w]+)\.negative\ .*$/,:klass => NegativeFieldPropertyNode},
|
97
|
+
{:matcher => /([\w]+)\.type\ .*$/,:klass => TypeFieldPropertyNode},
|
98
|
+
{:matcher => /([\w]+)\.warning\ .*$/,:klass => WarningFieldPropertyNode},
|
99
|
+
{:matcher => /([\w]+)\.critical\ .*$/,:klass => CriticalFieldPropertyNode},
|
100
|
+
{:matcher => /([\w]+)\.colour\ .*$/,:klass => ColourFieldPropertyNode},
|
101
|
+
{:matcher => /([\w]+)\.skipdraw\ .*$/,:klass => SkipDrawFieldPropertyNode},
|
102
|
+
{:matcher => /([\w]+)\.sum\ .*$/,:klass => SumFieldPropertyNode},
|
103
|
+
{:matcher => /([\w]+)\.stack\ .*$/,:klass => StackFieldPropertyNode},
|
104
|
+
{:matcher => /([\w]+)\.linevalue\[:color\[:label\]\]\ .*$/,:klass => LineValueFieldPropertyNode},
|
105
|
+
{:matcher => /([\w]+)\.oldname\ .*$/,:klass => OldNameFieldPropertyNode},
|
106
|
+
{:matcher => /([\w]+)\.value\ .*$/,:klass => ValueFieldPropertyNode}
|
107
107
|
]
|
108
108
|
|
109
109
|
def parse_config
|
data/munin2graphite.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: munin2graphite 0.
|
5
|
+
# stub: munin2graphite 0.3.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "munin2graphite"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.3.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Jose Fernandez (magec)"]
|
14
|
-
s.date = "2017-
|
14
|
+
s.date = "2017-11-06"
|
15
15
|
s.description = "This gem will install as a daemon and can be used to connect to a graphite and a carbon backend. It will not only post the data for the metrics but also create graphs into graphite, by means of a translation from munin-node."
|
16
16
|
s.email = "jfernandezperez@gmail.com"
|
17
17
|
s.executables = ["munin2gdash", "munin2graphite", "munin2graphite-1r", "munin2graphite-daemon"]
|
@@ -55,7 +55,7 @@ Gem::Specification.new do |s|
|
|
55
55
|
]
|
56
56
|
s.homepage = "http://github.com/magec/munin2graphite"
|
57
57
|
s.licenses = ["MIT"]
|
58
|
-
s.rubygems_version = "2.4.5"
|
58
|
+
s.rubygems_version = "2.4.5.1"
|
59
59
|
s.summary = "Allows to post both data and graphic info from munin to graphite (https://launchpad.net/graphite)"
|
60
60
|
|
61
61
|
if s.respond_to? :specification_version then
|
@@ -67,6 +67,7 @@ Gem::Specification.new do |s|
|
|
67
67
|
s.add_runtime_dependency(%q<parseconfig>, [">= 0"])
|
68
68
|
s.add_runtime_dependency(%q<munin-ruby>, ["~> 0.2.1"])
|
69
69
|
s.add_runtime_dependency(%q<json>, ["~> 1.8.2"])
|
70
|
+
s.add_runtime_dependency(%q<diplomat>, [">= 2.0.2", "~> 2.0"])
|
70
71
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
71
72
|
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
72
73
|
else
|
@@ -75,6 +76,7 @@ Gem::Specification.new do |s|
|
|
75
76
|
s.add_dependency(%q<parseconfig>, [">= 0"])
|
76
77
|
s.add_dependency(%q<munin-ruby>, ["~> 0.2.1"])
|
77
78
|
s.add_dependency(%q<json>, ["~> 1.8.2"])
|
79
|
+
s.add_dependency(%q<diplomat>, [">= 2.0.2", "~> 2.0"])
|
78
80
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
79
81
|
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
80
82
|
end
|
@@ -84,6 +86,7 @@ Gem::Specification.new do |s|
|
|
84
86
|
s.add_dependency(%q<parseconfig>, [">= 0"])
|
85
87
|
s.add_dependency(%q<munin-ruby>, ["~> 0.2.1"])
|
86
88
|
s.add_dependency(%q<json>, ["~> 1.8.2"])
|
89
|
+
s.add_dependency(%q<diplomat>, [">= 2.0.2", "~> 2.0"])
|
87
90
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
88
91
|
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
89
92
|
end
|
data/test/test_my_graph.rb
CHANGED
@@ -6,8 +6,9 @@ class TestMyGraph < Test::Unit::TestCase
|
|
6
6
|
def setup
|
7
7
|
Munin2Graphite::Config.config_file = TEST_CONFIG_FILE
|
8
8
|
@graphic = Graphite::MyGraph.new
|
9
|
-
@graphic.url = "http://
|
9
|
+
@graphic.url = "http://test.es/composer/../render/?width=1371&height=707&_salt=1312965749.741&target=alias(scale(derivative(campus.frontends.linux.aleia.apache.apache_volume.volume80)%2C0.016666666666666666)%2C%22Bytes%20por%20segundo%22)&title=Bytes%20transmitidos"
|
10
10
|
@graphic.name = "Apache.Transferencia"
|
11
|
+
puts @graphic.inspect
|
11
12
|
@graphic.save!
|
12
13
|
end
|
13
14
|
|
@@ -22,6 +23,7 @@ class TestMyGraph < Test::Unit::TestCase
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def test_find_by_name
|
26
|
+
puts Graphite::MyGraph.find_by_name("Apache.Transferencia").inspect
|
25
27
|
assert_equal Graphite::MyGraph.find_by_name("Apache.Transferencia").name , "Apache.Transferencia"
|
26
28
|
end
|
27
29
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: munin2graphite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jose Fernandez (magec)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rufus-scheduler
|
@@ -80,6 +80,26 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 1.8.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: diplomat
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.0.2
|
90
|
+
- - "~>"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '2.0'
|
93
|
+
type: :runtime
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 2.0.2
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '2.0'
|
83
103
|
- !ruby/object:Gem::Dependency
|
84
104
|
name: jeweler
|
85
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -174,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
194
|
version: '0'
|
175
195
|
requirements: []
|
176
196
|
rubyforge_project:
|
177
|
-
rubygems_version: 2.4.5
|
197
|
+
rubygems_version: 2.4.5.1
|
178
198
|
signing_key:
|
179
199
|
specification_version: 4
|
180
200
|
summary: Allows to post both data and graphic info from munin to graphite (https://launchpad.net/graphite)
|