metrix 0.0.10 → 0.0.11

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.
@@ -4,6 +4,9 @@ require "metrix/mongodb"
4
4
  require "metrix/nginx"
5
5
  require "metrix/system"
6
6
  require "metrix/load"
7
+ require "metrix/memory"
8
+ require "metrix/diskstats"
9
+ require "metrix/df"
7
10
  require "metrix/fpm"
8
11
  require "metrix/process_metric"
9
12
  require "metrix/load"
@@ -98,12 +101,15 @@ module Metrix
98
101
  begin
99
102
  cnt += 1
100
103
  now = Time.now.utc
101
- fetch_metrix(:elasticsearch) { reporter << Metrix::ElasticSearch.new(fetch_resource(:elasticsearch)) }
102
- fetch_metrix(:mongodb) { reporter << Metrix::Mongodb.new(fetch_resource(:mongodb)) }
103
- fetch_metrix(:nginx) { reporter << Metrix::Nginx.new(fetch_resource(:nginx)) }
104
- fetch_metrix(:fpm) { reporter << Metrix::FPM.new(fetch_resource(:fpm)) }
105
- fetch_metrix(:system) { reporter << Metrix::System.new(File.read("/proc/stat")) }
106
- fetch_metrix(:load) { reporter << Metrix::Load.new(File.read("/proc/loadavg")) }
104
+ fetch_metrix(:elasticsearch) { reporter << Metrix::ElasticSearch.new(fetch_resource(:elasticsearch)) }
105
+ fetch_metrix(:mongodb) { reporter << Metrix::Mongodb.new(fetch_resource(:mongodb)) }
106
+ fetch_metrix(:nginx) { reporter << Metrix::Nginx.new(fetch_resource(:nginx)) }
107
+ fetch_metrix(:fpm) { reporter << Metrix::FPM.new(fetch_resource(:fpm)) }
108
+ fetch_metrix(:system) { reporter << Metrix::System.new(File.read("/proc/stat")) }
109
+ fetch_metrix(:load) { reporter << Metrix::Load.new(File.read("/proc/loadavg")) }
110
+ fetch_metrix(:memory) { reporter << Metrix::Memory.new(File.read("/proc/meminfo")) }
111
+ fetch_metrix(:diskstats) { reporter << Metrix::Diskstats.new(File.read("/proc/diskstats")) }
112
+ fetch_metrix(:df) { reporter << Metrix::Df.new(`df -k`) }
107
113
 
108
114
  fetch_metrix :processes do
109
115
  Metrix::ProcessMetric.all.each do |m|
@@ -0,0 +1,34 @@
1
+ require "metrix/base"
2
+
3
+ module Metrix
4
+ class Df < Base
5
+ set_prefix "df"
6
+
7
+ MAPPING = {
8
+ total: 1,
9
+ used: 2,
10
+ available: 3,
11
+ used_perc: 4,
12
+ }
13
+
14
+ set_known_metrics MAPPING.keys.map(&:to_s)
15
+
16
+ def initialize(data)
17
+ @data = data
18
+ @time = Time.now
19
+ end
20
+
21
+ def metrics
22
+ metrics = []
23
+ @data.scan(%r(^(/.*)/)).each do |(line)|
24
+ chunks = line.split(/\s+/)
25
+ disk = chunks.at(0)
26
+ MAPPING.each do |key, idx|
27
+ value = cast_int(chunks.at(idx))
28
+ metrics << Metric.new("#{prefix}.#{key}", value, time, disk: disk)
29
+ end
30
+ end
31
+ metrics
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ module Metrix
2
+ class Diskstats < Base
3
+ MAPPING = {
4
+ reads_completed: 0,
5
+ reads_merged: 1,
6
+ sectors_read: 2,
7
+ milliseconds_rea: 3,
8
+ writes_completed: 4,
9
+ writes_merged: 5,
10
+ sectors_written: 6,
11
+ milliseconds_written: 7,
12
+ ios_in_progress: 8,
13
+ milliseconds_io: 9,
14
+ weighted_milliseconds_io: 10,
15
+ }
16
+ set_prefix "diskstats"
17
+ set_known_metrics MAPPING.keys.map(&:to_s)
18
+
19
+ def initialize(data)
20
+ @data = data
21
+ @time = Time.now
22
+ end
23
+
24
+ def metrics
25
+ @data.scan(/^\s*(\d+)\s*(\d+)\s*(.*?) (.*)/).map do |(_, _, disk, rest)|
26
+ next if disk.start_with?("loop") || disk.start_with?("ram")
27
+ chunks = rest.split(" ").map(&:to_i)
28
+ metrics = []
29
+ MAPPING.keys.each_with_index do |m, i|
30
+ value = chunks.at(i)
31
+ metrics << Metric.new("#{prefix}.#{m}", value, @time, disk: disk)
32
+ end
33
+ metrics
34
+ end.flatten.compact
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,77 @@
1
+ require "metrix/base"
2
+
3
+ module Metrix
4
+ class Memory < Base
5
+ set_prefix "memory"
6
+
7
+ def initialize(data)
8
+ @data = data
9
+ @time = Time.now
10
+ end
11
+
12
+ MAPPING = {
13
+ "MemTotal" => :mem_total,
14
+ "MemFree" => :mem_free,
15
+ "Buffers" => :buffers,
16
+ "Cached" => :cached,
17
+ "SwapCached" => :swap_cached,
18
+ "Active" => :active,
19
+ "Inactive" => :inactive,
20
+ "Active(anon)" => :active_anon,
21
+ "Inactive(anon)" => :inactive_anon,
22
+ "Active(file)" => :active_file,
23
+ "Inactive(file)" => :inactive_file,
24
+ "Unevictable" => :unevictable,
25
+ "Mlocked" => :mlocked,
26
+ "SwapTotal" => :swap_total,
27
+ "SwapFree" => :swap_free,
28
+ "Dirty" => :dirty,
29
+ "Writeback" => :writeback,
30
+ "AnonPages" => :anon_pages,
31
+ "Mapped" => :mapped,
32
+ "Shmem" => :shmem,
33
+ "Slab" => :slab,
34
+ "SReclaimable" => :s_reclaimable,
35
+ "SUnreclaim" => :s_unreclaim,
36
+ "KernelStack" => :kernel_stack,
37
+ "PageTables" => :page_tables,
38
+ "NFS_Unstable" => :nfs_unstable,
39
+ "Bounce" => :bounce,
40
+ "WritebackTmp" => :writeback_tmp,
41
+ "CommitLimit" => :commit_limit,
42
+ "Committed_AS" => :committed_as,
43
+ "VmallocTotal" => :vmalloc_total,
44
+ "VmallocUsed" => :vmalloc_used,
45
+ "VmallocChunk" => :vmalloc_chunk,
46
+ "HardwareCorrupted" => :hardware_corrupted,
47
+ "AnonHugePages" => :anon_huge_pages,
48
+ "HugePages_Total" => :huge_pages_total,
49
+ "HugePages_Free" => :huge_pages_free,
50
+ "HugePages_Rsvd" => :huge_pages_rsvd,
51
+ "HugePages_Surp" => :huge_pages_surp,
52
+ "Hugepagesize" => :hugepagesize,
53
+ "DirectMap4k" => :direct_map4k,
54
+ "DirectMap2M" => :direct_map2m,
55
+ }
56
+
57
+ set_known_metrics MAPPING.values
58
+
59
+ MAPPING.each do |from, to|
60
+ define_method(to) do
61
+ cast_int(parsed[from])
62
+ end
63
+ end
64
+
65
+ def extract(data = nil)
66
+ MAPPING.values.inject({}) do |hash, method|
67
+ hash[method] = send(method)
68
+ hash
69
+ end
70
+ end
71
+
72
+ def parsed
73
+ @parsed ||= Hash[@data.scan(/^(.*?):\s*(\d+)/).map { |k, v| [k, cast_int(v)] }]
74
+ end
75
+
76
+ end
77
+ end
@@ -10,10 +10,10 @@ module Metrix
10
10
 
11
11
  class << self
12
12
  def all
13
- Dir.glob("/proc/*").select do |path|
14
- File.directory?(path) && File.basename(path)[/^\d+$/]
15
- end.map do |path|
16
- Metrix::ProcessMetric.new(File.read(path + "/stat"))
13
+ IO.popen("find /proc -maxdepth 2 -mindepth 2 -name stat") do |io|
14
+ io.map do |path|
15
+ Metrix::ProcessMetric.new(File.read(path.strip))
16
+ end
17
17
  end
18
18
  end
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module Metrix
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -0,0 +1,2 @@
1
+ /dev/xvda1 8125880 4736276 2970176 62% /
2
+ /dev/xvdb 412814512 804612 391040124 1% /mnt
@@ -0,0 +1,26 @@
1
+ 1 0 ram0 0 0 0 0 0 0 0 0 0 0 0
2
+ 1 1 ram1 0 0 0 0 0 0 0 0 0 0 0
3
+ 1 2 ram2 0 0 0 0 0 0 0 0 0 0 0
4
+ 1 3 ram3 0 0 0 0 0 0 0 0 0 0 0
5
+ 1 4 ram4 0 0 0 0 0 0 0 0 0 0 0
6
+ 1 5 ram5 0 0 0 0 0 0 0 0 0 0 0
7
+ 1 6 ram6 0 0 0 0 0 0 0 0 0 0 0
8
+ 1 7 ram7 0 0 0 0 0 0 0 0 0 0 0
9
+ 1 8 ram8 0 0 0 0 0 0 0 0 0 0 0
10
+ 1 9 ram9 0 0 0 0 0 0 0 0 0 0 0
11
+ 1 10 ram10 0 0 0 0 0 0 0 0 0 0 0
12
+ 1 11 ram11 0 0 0 0 0 0 0 0 0 0 0
13
+ 1 12 ram12 0 0 0 0 0 0 0 0 0 0 0
14
+ 1 13 ram13 0 0 0 0 0 0 0 0 0 0 0
15
+ 1 14 ram14 0 0 0 0 0 0 0 0 0 0 0
16
+ 1 15 ram15 0 0 0 0 0 0 0 0 0 0 0
17
+ 7 0 loop0 0 0 0 0 0 0 0 0 0 0 0
18
+ 7 1 loop1 0 0 0 0 0 0 0 0 0 0 0
19
+ 7 2 loop2 0 0 0 0 0 0 0 0 0 0 0
20
+ 7 3 loop3 0 0 0 0 0 0 0 0 0 0 0
21
+ 7 4 loop4 0 0 0 0 0 0 0 0 0 0 0
22
+ 7 5 loop5 0 0 0 0 0 0 0 0 0 0 0
23
+ 7 6 loop6 0 0 0 0 0 0 0 0 0 0 0
24
+ 7 7 loop7 0 0 0 0 0 0 0 0 0 0 0
25
+ 8 0 sda 12732 743 377314 11532 8669 13477 569336 26884 0 10216 37124
26
+ 8 1 sda1 12567 721 375818 11404 7362 13477 569336 26716 0 10076 36868
@@ -0,0 +1,42 @@
1
+ MemTotal: 4049980 kB
2
+ MemFree: 3614536 kB
3
+ Buffers: 44580 kB
4
+ Cached: 273180 kB
5
+ SwapCached: 0 kB
6
+ Active: 162464 kB
7
+ Inactive: 176392 kB
8
+ Active(anon): 21128 kB
9
+ Inactive(anon): 216 kB
10
+ Active(file): 141336 kB
11
+ Inactive(file): 176176 kB
12
+ Unevictable: 0 kB
13
+ Mlocked: 0 kB
14
+ SwapTotal: 0 kB
15
+ SwapFree: 0 kB
16
+ Dirty: 32 kB
17
+ Writeback: 0 kB
18
+ AnonPages: 21116 kB
19
+ Mapped: 11312 kB
20
+ Shmem: 252 kB
21
+ Slab: 39200 kB
22
+ SReclaimable: 30092 kB
23
+ SUnreclaim: 9108 kB
24
+ KernelStack: 640 kB
25
+ PageTables: 2408 kB
26
+ NFS_Unstable: 0 kB
27
+ Bounce: 0 kB
28
+ WritebackTmp: 0 kB
29
+ CommitLimit: 2024988 kB
30
+ Committed_AS: 78416 kB
31
+ VmallocTotal: 34359738367 kB
32
+ VmallocUsed: 64036 kB
33
+ VmallocChunk: 34359671800 kB
34
+ HardwareCorrupted: 0 kB
35
+ AnonHugePages: 0 kB
36
+ HugePages_Total: 0
37
+ HugePages_Free: 0
38
+ HugePages_Rsvd: 0
39
+ HugePages_Surp: 0
40
+ Hugepagesize: 2048 kB
41
+ DirectMap4k: 44992 kB
42
+ DirectMap2M: 4149248 kB
@@ -0,0 +1,36 @@
1
+ require "spec_helper"
2
+ require "metrix/df"
3
+
4
+ describe "Metrix::Df", :wip do
5
+ let(:data) { FIXTURES_PATH.join("df.txt").read }
6
+ subject(:df) { Metrix::Df.new(data) }
7
+
8
+ it { should_not be_nil }
9
+
10
+ it { Metrix::Df.prefix.should eq("df") }
11
+
12
+ describe "#known_metrics" do
13
+ subject(:known) { Metrix::Df.known_metrics }
14
+ it { should be_kind_of(Array) }
15
+ end
16
+
17
+ describe "#metrics" do
18
+ subject(:metrics) { df.metrics }
19
+ it { should be_kind_of(Array) }
20
+ it { subject.count.should eq(8) }
21
+
22
+ describe "#first" do
23
+ before do
24
+ df.stub(:time) { Time.at(11) }
25
+ end
26
+
27
+ subject(:first) { metrics.first }
28
+ it { should_not be_nil }
29
+ it { subject.key.should eq("df.total") }
30
+ it { subject.value.should eq(8125880) }
31
+ it { subject.time.should eq(Time.at(11)) }
32
+ it { subject.tags.should eq(disk: "/dev/xvda1") }
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+ require "metrix/diskstats"
3
+
4
+ describe "Metrix::Diskstats", :wip do
5
+ let(:data) { FIXTURES_PATH.join("diskstats.txt").read }
6
+ subject(:stats) { Metrix::Diskstats.new(data) }
7
+ it { should_not be_nil }
8
+
9
+ it { subject.prefix.should eq("diskstats") }
10
+
11
+ it { Metrix::Diskstats.known_metrics.count.should eq(11) }
12
+
13
+ describe "#metrics" do
14
+ subject(:metrics) { stats.metrics }
15
+ it { subject.count.should eq(22) }
16
+
17
+ describe "first metric" do
18
+ subject(:first) { metrics.first }
19
+ it { should_not be_nil }
20
+ it { subject.key.should eq("diskstats.reads_completed") }
21
+ it { subject.value.should eq(12732) }
22
+ it { subject.tags.should eq(disk: "sda") }
23
+ it { subject.to_opentsdb.should include("hostname=") }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+ require "metrix/memory"
3
+
4
+ describe "Metrix::Memory" do
5
+ let(:data) { FIXTURES_PATH.join("memory.txt").read }
6
+ subject(:memory) { Metrix::Memory.new(data) }
7
+ it { should_not be_nil }
8
+
9
+ it { memory.prefix.should eq("memory") }
10
+
11
+ it { subject.mem_total.should eq(4049980) }
12
+ it { subject.mem_free.should eq(3614536) }
13
+ it { subject.active_anon.should eq(21128) }
14
+
15
+ it { Metrix::Memory.known_metrics.should be_kind_of(Array) }
16
+
17
+ it { subject.metrics.count.should eq(42) }
18
+
19
+ describe "first value" do
20
+ subject(:first) { memory.metrics.first }
21
+
22
+ it { subject.key.should eq("memory.mem_total") }
23
+ it { subject.value.should eq(4049980) }
24
+ end
25
+ end
@@ -8,7 +8,7 @@ describe "Metrix" do
8
8
  subject(:known_metrics) { Metrix.known_metrics }
9
9
  it { should be_kind_of(Array) }
10
10
  it { should_not be_empty }
11
- it { subject.count.should eq(170) }
11
+ it { subject.count.should > 170 }
12
12
 
13
13
  it { should include("mongodb.uptime") }
14
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-04 00:00:00.000000000 Z
12
+ date: 2013-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: SyslogLogger
@@ -92,11 +92,14 @@ files:
92
92
  - lib/metrix.rb
93
93
  - lib/metrix/base.rb
94
94
  - lib/metrix/cli.rb
95
+ - lib/metrix/df.rb
96
+ - lib/metrix/diskstats.rb
95
97
  - lib/metrix/elastic_search.rb
96
98
  - lib/metrix/fpm.rb
97
99
  - lib/metrix/graphite.rb
98
100
  - lib/metrix/json_metric.rb
99
101
  - lib/metrix/load.rb
102
+ - lib/metrix/memory.rb
100
103
  - lib/metrix/metric.rb
101
104
  - lib/metrix/mongodb.rb
102
105
  - lib/metrix/nginx.rb
@@ -106,9 +109,12 @@ files:
106
109
  - lib/metrix/system.rb
107
110
  - lib/metrix/version.rb
108
111
  - metrix.gemspec
112
+ - spec/fixtures/df.txt
113
+ - spec/fixtures/diskstats.txt
109
114
  - spec/fixtures/ec2metadata.txt
110
115
  - spec/fixtures/es_status.json
111
116
  - spec/fixtures/loadavg.txt
117
+ - spec/fixtures/memory.txt
112
118
  - spec/fixtures/metrix.yml
113
119
  - spec/fixtures/mongo_server_status.json
114
120
  - spec/fixtures/nginx.status.txt
@@ -117,10 +123,13 @@ files:
117
123
  - spec/fixtures/proc.stat.txt
118
124
  - spec/lib/metrix/base_spec.rb
119
125
  - spec/lib/metrix/cli_spec.rb
126
+ - spec/lib/metrix/df_spec.rb
127
+ - spec/lib/metrix/diskstats_spec.rb
120
128
  - spec/lib/metrix/elastic_search_spec.rb
121
129
  - spec/lib/metrix/fpm_spec.rb
122
130
  - spec/lib/metrix/graphite_spec.rb
123
131
  - spec/lib/metrix/load_spec.rb
132
+ - spec/lib/metrix/memory_spec.rb
124
133
  - spec/lib/metrix/metric_spec.rb
125
134
  - spec/lib/metrix/mongodb_spec.rb
126
135
  - spec/lib/metrix/nginx_spec.rb
@@ -154,9 +163,12 @@ signing_key:
154
163
  specification_version: 3
155
164
  summary: Ruby Metrics Library
156
165
  test_files:
166
+ - spec/fixtures/df.txt
167
+ - spec/fixtures/diskstats.txt
157
168
  - spec/fixtures/ec2metadata.txt
158
169
  - spec/fixtures/es_status.json
159
170
  - spec/fixtures/loadavg.txt
171
+ - spec/fixtures/memory.txt
160
172
  - spec/fixtures/metrix.yml
161
173
  - spec/fixtures/mongo_server_status.json
162
174
  - spec/fixtures/nginx.status.txt
@@ -165,10 +177,13 @@ test_files:
165
177
  - spec/fixtures/proc.stat.txt
166
178
  - spec/lib/metrix/base_spec.rb
167
179
  - spec/lib/metrix/cli_spec.rb
180
+ - spec/lib/metrix/df_spec.rb
181
+ - spec/lib/metrix/diskstats_spec.rb
168
182
  - spec/lib/metrix/elastic_search_spec.rb
169
183
  - spec/lib/metrix/fpm_spec.rb
170
184
  - spec/lib/metrix/graphite_spec.rb
171
185
  - spec/lib/metrix/load_spec.rb
186
+ - spec/lib/metrix/memory_spec.rb
172
187
  - spec/lib/metrix/metric_spec.rb
173
188
  - spec/lib/metrix/mongodb_spec.rb
174
189
  - spec/lib/metrix/nginx_spec.rb