metrix 0.0.1 → 0.0.2

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.
@@ -0,0 +1,72 @@
1
+ require "metrix/base"
2
+
3
+ module Metrix
4
+ class System < Base
5
+ class Cpu
6
+ def initialize(values)
7
+ @values = values
8
+ end
9
+
10
+ {
11
+ user: 0,
12
+ nice: 1,
13
+ system: 2,
14
+ idle: 3,
15
+ iowait: 4,
16
+ irq: 5,
17
+ softirq: 6,
18
+ }.each do |k, v|
19
+ define_method(k) do
20
+ @values.at(v)
21
+ end
22
+ end
23
+ end
24
+
25
+ def initialize(raw = File.read("/proc/stat"), time = Time.now)
26
+ @raw = raw
27
+ @time = time
28
+ end
29
+
30
+ [:processes, :procs_running, :procs_blocked, :ctxt].each do |m|
31
+ define_method(m) do
32
+ cast_int(@raw[/^#{m} (\d+)/, 1])
33
+ end
34
+ end
35
+
36
+ def unfiltered_metrics
37
+ {
38
+ "processes" => processes,
39
+ "procs_running" => procs_running,
40
+ "procs_blocked" => procs_blocked,
41
+ "ctxt" => ctxt,
42
+ "cpu.user" => cpu.user,
43
+ "cpu.nice" => cpu.nice,
44
+ "cpu.system" => cpu.system,
45
+ "cpu.idle" => cpu.idle,
46
+ "cpu.iowait" => cpu.iowait,
47
+ "cpu.irq" => cpu.irq,
48
+ "cpu.softirq" => cpu.softirq,
49
+ }
50
+ end
51
+
52
+ def load1
53
+ loadavg.split(" ").first.to_f
54
+ end
55
+
56
+ def loadavg
57
+ @loadavg ||= File.read("/proc/loadavg")
58
+ end
59
+
60
+ def prefix
61
+ "system"
62
+ end
63
+
64
+ def cpu
65
+ Cpu.new(@raw[/^cpu (.*)/, 1].split(" ").map(&:to_i))
66
+ end
67
+
68
+ def cast_int(value)
69
+ value.to_i if value
70
+ end
71
+ end
72
+ end
@@ -1,3 +1,3 @@
1
1
  module Metrix
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/metrix.rb CHANGED
@@ -9,5 +9,9 @@ module Metrix
9
9
  require "logger"
10
10
  @logger ||= Logger.new(STDOUT)
11
11
  end
12
+
13
+ def hostname
14
+ @hostname ||= `hostname`.strip
15
+ end
12
16
  end
13
17
  end
@@ -0,0 +1,25 @@
1
+ ami-id: ami-12345
2
+ ami-launch-index: 0
3
+ ami-manifest-path: (unknown)
4
+ ancestor-ami-ids: unavailable
5
+ availability-zone: eu-west-1a
6
+ block-device-mapping: ami
7
+ ephemeral0
8
+ root
9
+ swap
10
+ instance-action: none
11
+ instance-id: i-252535
12
+ instance-type: m1.small
13
+ local-hostname: ip-1-2-3-4.eu-west-1.compute.internal
14
+ local-ipv4: 1.2.3.4
15
+ kernel-id: aki-71665e05
16
+ mac: unavailable
17
+ profile: default-paravirtual
18
+ product-codes: unavailable
19
+ public-hostname: ec2-2-4-6-8.eu-west-1.compute.amazonaws.com
20
+ public-ipv4: 2.4.6.8
21
+ public-keys: ['some.ssh.key']
22
+ ramdisk-id: unavailable
23
+ reserveration-id: unavailable
24
+ security-groups: default
25
+ user-data: unavailable
@@ -0,0 +1 @@
1
+ 0.04 0.23 0.26 1/84 8512
@@ -1,63 +1,125 @@
1
- { "host" : "tobias-mba.local",
2
- "version" : "2.0.4",
1
+ { "host" : "mbp-tobias.local",
2
+ "version" : "2.4.3",
3
3
  "process" : "mongod",
4
- "uptime" : 36,
5
- "uptimeEstimate" : 32,
6
- "localTime" : { "$date" : "Fri May 31 17:56:54 2013" },
7
- "globalLock" : { "totalTime" : 36018171,
8
- "lockTime" : 347,
9
- "ratio" : 9.634026114207743e-06,
10
- "currentQueue" : { "total" : 0,
11
- "readers" : 0,
12
- "writers" : 0 },
13
- "activeClients" : { "total" : 0,
14
- "readers" : 0,
15
- "writers" : 0 } },
16
- "mem" : { "bits" : 64,
17
- "resident" : 14,
18
- "virtual" : 2414,
19
- "supported" : true,
20
- "mapped" : 0,
21
- "mappedWithJournal" : 0 },
22
- "connections" : { "current" : 0,
23
- "available" : 2048 },
24
- "extra_info" : { "note" : "fields vary by platform" },
25
- "indexCounters" : { "btree" : { "accesses" : 0,
26
- "hits" : 0,
27
- "misses" : 0,
28
- "resets" : 0,
29
- "missRatio" : 0 } },
30
- "backgroundFlushing" : { "flushes" : 0,
31
- "total_ms" : 0,
32
- "average_ms" : 0,
33
- "last_ms" : 0,
34
- "last_finished" : { "$date" : 0 } },
35
- "cursors" : { "totalOpen" : 0,
36
- "clientCursors_size" : 0,
37
- "timedOut" : 0 },
38
- "network" : { "bytesIn" : 0,
39
- "bytesOut" : 0,
40
- "numRequests" : 0 },
41
- "opcounters" : { "insert" : 0,
42
- "query" : 1,
43
- "update" : 0,
44
- "delete" : 0,
45
- "getmore" : 0,
46
- "command" : 0 },
4
+ "pid" : 83257,
5
+ "uptime" : 475,
6
+ "uptimeMillis" : 474819,
7
+ "uptimeEstimate" : 440,
8
+ "localTime" : { "$date" : "Sat Jun 1 16:32:41 2013" },
47
9
  "asserts" : { "regular" : 0,
48
10
  "warning" : 0,
49
11
  "msg" : 0,
50
12
  "user" : 0,
51
13
  "rollovers" : 0 },
52
- "writeBacksQueued" : false,
14
+ "backgroundFlushing" : { "flushes" : 7,
15
+ "total_ms" : 803,
16
+ "average_ms" : 114.7142857142857,
17
+ "last_ms" : 2,
18
+ "last_finished" : { "$date" : "Sat Jun 1 16:31:46 2013" } },
19
+ "connections" : { "current" : 0,
20
+ "available" : 2048,
21
+ "totalCreated" : 11 },
22
+ "cursors" : { "totalOpen" : 0,
23
+ "clientCursors_size" : 0,
24
+ "timedOut" : 0 },
53
25
  "dur" : { "commits" : 29,
54
26
  "journaledMB" : 0,
55
27
  "writeToDataFilesMB" : 0,
56
28
  "compression" : 0,
57
29
  "commitsInWriteLock" : 0,
58
30
  "earlyCommits" : 0,
59
- "timeMs" : { "dt" : 3036,
31
+ "timeMs" : { "dt" : 3024,
60
32
  "prepLogBuffer" : 0,
61
33
  "writeToJournal" : 0,
62
34
  "writeToDataFiles" : 0,
63
- "remapPrivateView" : 0 } } }
35
+ "remapPrivateView" : 0 } },
36
+ "extra_info" : { "note" : "fields vary by platform",
37
+ "page_faults" : 1176 },
38
+ "globalLock" : { "totalTime" : 474819000,
39
+ "lockTime" : 1060706,
40
+ "currentQueue" : { "total" : 0,
41
+ "readers" : 0,
42
+ "writers" : 0 },
43
+ "activeClients" : { "total" : 0,
44
+ "readers" : 0,
45
+ "writers" : 0 } },
46
+ "indexCounters" : { "accesses" : 3,
47
+ "hits" : 3,
48
+ "misses" : 0,
49
+ "resets" : 0,
50
+ "missRatio" : 0 },
51
+ "locks" : { "." : { "timeLockedMicros" : { "R" : 23926,
52
+ "W" : 1060706 },
53
+ "timeAcquiringMicros" : { "R" : 946700,
54
+ "W" : 1234045 } },
55
+ "admin" : { "timeLockedMicros" : {},
56
+ "timeAcquiringMicros" : {} },
57
+ "local" : { "timeLockedMicros" : { "r" : 897017,
58
+ "w" : 0 },
59
+ "timeAcquiringMicros" : { "r" : 87,
60
+ "w" : 0 } },
61
+ "opentsdb" : { "timeLockedMicros" : { "r" : 12800,
62
+ "w" : 670009 },
63
+ "timeAcquiringMicros" : { "r" : 168,
64
+ "w" : 28 } } },
65
+ "network" : { "bytesIn" : 2963,
66
+ "bytesOut" : 3099,
67
+ "numRequests" : 37 },
68
+ "opcounters" : { "insert" : 4,
69
+ "query" : 18,
70
+ "update" : 0,
71
+ "delete" : 0,
72
+ "getmore" : 0,
73
+ "command" : 31 },
74
+ "opcountersRepl" : { "insert" : 0,
75
+ "query" : 0,
76
+ "update" : 0,
77
+ "delete" : 0,
78
+ "getmore" : 0,
79
+ "command" : 0 },
80
+ "recordStats" : { "accessesNotInMemory" : 0,
81
+ "pageFaultExceptionsThrown" : 0,
82
+ "local" : { "accessesNotInMemory" : 0,
83
+ "pageFaultExceptionsThrown" : 0 },
84
+ "opentsdb" : { "accessesNotInMemory" : 0,
85
+ "pageFaultExceptionsThrown" : 0 } },
86
+ "writeBacksQueued" : false,
87
+ "mem" : { "bits" : 64,
88
+ "resident" : 9,
89
+ "virtual" : 2814,
90
+ "supported" : true,
91
+ "mapped" : 160,
92
+ "mappedWithJournal" : 320 },
93
+ "metrics" : { "document" : { "deleted" : 0,
94
+ "inserted" : 4,
95
+ "returned" : 5,
96
+ "updated" : 0 },
97
+ "getLastError" : { "wtime" : { "num" : 3,
98
+ "totalMillis" : 0 },
99
+ "wtimeouts" : 0 },
100
+ "operation" : { "fastmod" : 0,
101
+ "idhack" : 0,
102
+ "scanAndOrder" : 0 },
103
+ "queryExecutor" : { "scanned" : 12 },
104
+ "record" : { "moves" : 0 },
105
+ "repl" : { "apply" : { "batches" : { "num" : 0,
106
+ "totalMillis" : 0 },
107
+ "ops" : 0 },
108
+ "buffer" : { "count" : 0,
109
+ "maxSizeBytes" : 268435456,
110
+ "sizeBytes" : 0 },
111
+ "network" : { "bytes" : 0,
112
+ "getmores" : { "num" : 0,
113
+ "totalMillis" : 0 },
114
+ "ops" : 0,
115
+ "readersCreated" : 0 },
116
+ "oplog" : { "insert" : { "num" : 0,
117
+ "totalMillis" : 0 },
118
+ "insertBytes" : 0 },
119
+ "preload" : { "docs" : { "num" : 0,
120
+ "totalMillis" : 0 },
121
+ "indexes" : { "num" : 0,
122
+ "totalMillis" : 0 } } },
123
+ "ttl" : { "deletedDocuments" : 0,
124
+ "passes" : 7 } },
125
+ "ok" : 1 }
@@ -0,0 +1,3 @@
1
+ 26928 (java) S 1 26852 26723 34816 28475 4218880 332517 9459 13 0 32337 34740 2 16 20 0 125 0 2630432 1688936448 289510
2
+ 18446744073709551615 4194304 4196484 140734482110432 140734482092992 140087191929368 0 0 3 16800972 18446744073709551615 0 0 17
3
+ 0 0 0 0 0 0 6293640 6294276 39821312 140734482113510 140734482117905 140734482117905 140734482120657 0
@@ -0,0 +1,18 @@
1
+ cpu 79833 8300 84916 5887890 54619 93 19796 0 0 0
2
+ cpu0 38333 6351 41352 2933041 23957 69 17322 0 0 0
3
+ cpu1 41500 1948 43563 2954849 30662 23 2474 0 0 0
4
+ intr 5525124 60 9 0 0 0 0 0 0 0 0 0 0 150 0 0 0 1780060 0 0 338428 24852 406960 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
5
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
6
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
7
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
8
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
9
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
10
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
11
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
12
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
13
+ ctxt 9201101
14
+ btime 1370038650
15
+ processes 28467
16
+ procs_running 1
17
+ procs_blocked 0
18
+ softirq 4015410 0 661828 12899 1839122 396522 0 78 248229 10294 846438
@@ -1,40 +1,41 @@
1
1
  require "spec_helper"
2
2
  require "metrix/elastic_search"
3
3
 
4
- describe "Metrox::ElasticSearch", :wip do
4
+ describe "Metrox::ElasticSearch" do
5
5
  let(:payload) { FIXTURES_PATH.join("es_status.json").read }
6
- subject(:es_status) { Metrix::ElasticSearch.from_json(payload) }
6
+ subject(:es_status) { Metrix::ElasticSearch.new(payload) }
7
7
  it { should_not be_nil }
8
8
  it { subject.attributes.should be_kind_of(Hash) }
9
+ it { subject.time.should_not be_nil }
9
10
 
10
11
  describe "#metrics" do
11
- subject(:metrics) { es_status.metrics }
12
+ subject(:metrics) { hash_metrics(es_status.metrics) }
12
13
  it { should be_kind_of(Hash) }
13
14
  it { should_not be_empty }
14
15
 
15
16
  {
16
- "_shards.total"=>10,
17
- "_shards.successful"=>5,
18
- "_shards.failed"=>0,
19
- "indices.search.index.primary_size_in_bytes"=>2008,
20
- "indices.search.index.size_in_bytes"=>2008,
21
- "indices.search.translog.operations"=>1,
22
- "indices.search.docs.num_docs"=>1,
23
- "indices.search.docs.max_doc"=>1,
24
- "indices.search.docs.deleted_docs"=>0,
25
- "indices.search.merges.current"=>0,
26
- "indices.search.merges.current_docs"=>0,
27
- "indices.search.merges.current_size_in_bytes"=>0,
28
- "indices.search.merges.total"=>0,
29
- "indices.search.merges.total_time_in_millis"=>0,
30
- "indices.search.merges.total_docs"=>0,
31
- "indices.search.merges.total_size_in_bytes"=>0,
32
- "indices.search.refresh.total"=>6,
33
- "indices.search.refresh.total_time_in_millis"=>124,
34
- "indices.search.flush.total"=>0,
17
+ "elasticsearch._shards.total"=>10,
18
+ "elasticsearch._shards.successful"=>5,
19
+ "elasticsearch._shards.failed"=>0,
20
+ "elasticsearch.indices.search.index.primary_size_in_bytes"=>2008,
21
+ "elasticsearch.indices.search.index.size_in_bytes"=>2008,
22
+ "elasticsearch.indices.search.translog.operations"=>1,
23
+ "elasticsearch.indices.search.docs.num_docs"=>1,
24
+ "elasticsearch.indices.search.docs.max_doc"=>1,
25
+ "elasticsearch.indices.search.docs.deleted_docs"=>0,
26
+ "elasticsearch.indices.search.merges.current"=>0,
27
+ "elasticsearch.indices.search.merges.current_docs"=>0,
28
+ "elasticsearch.indices.search.merges.current_size_in_bytes"=>0,
29
+ "elasticsearch.indices.search.merges.total"=>0,
30
+ "elasticsearch.indices.search.merges.total_time_in_millis"=>0,
31
+ "elasticsearch.indices.search.merges.total_docs"=>0,
32
+ "elasticsearch.indices.search.merges.total_size_in_bytes"=>0,
33
+ "elasticsearch.indices.search.refresh.total"=>6,
34
+ "elasticsearch.indices.search.refresh.total_time_in_millis"=>124,
35
+ "elasticsearch.indices.search.flush.total"=>0,
35
36
  }.each do |k, v|
36
37
  it "should set attributes #{k.inspect} to #{v.inspect}" do
37
- subject[k].should eq(v)
38
+ subject[k].value.should eq(v)
38
39
  end
39
40
  end
40
41
  it { subject.keys.count.should eq(20) }
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+ require "metrix/graphite"
3
+
4
+ describe "Metrix::Graphite" do
5
+ let(:data) { FIXTURES_PATH.join("proc.26928.txt").read }
6
+ let(:metric) { Metrix::Process.new(data, Time.at(1370091027)) }
7
+ subject(:client) { Metrix::Graphite.new("128.0.0.1") }
8
+
9
+ it { should_not be_nil }
10
+ it { subject.port.should eq(2003) }
11
+
12
+ describe "#<<" do
13
+ before do
14
+ client << metric
15
+ end
16
+
17
+ it { should_not be_nil }
18
+ it { client.buffers.count.should eq(11) }
19
+ describe "first line" do
20
+ subject(:line) { client.buffers.first }
21
+ it { should eq("metrix.test.host.system.process.minflt 332517 1370091027") }
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+ require "metrix/load"
3
+
4
+ describe "Metrix::Load" do
5
+ let(:data) {FIXTURES_PATH.join("loadavg.txt").read }
6
+ subject(:loadavg) { Metrix::Load.new(data) }
7
+
8
+ it { should_not be_nil }
9
+ it { loadavg.load1.should eq(0.04) }
10
+ it { loadavg.load5.should eq(0.23) }
11
+ it { loadavg.load15.should eq(0.26) }
12
+
13
+ describe "#metrics" do
14
+ subject(:metrics) { loadavg.extract(1) }
15
+ it { should be_kind_of(Hash) }
16
+ it { subject.count.should eq(3) }
17
+
18
+ {
19
+ load1: 0.04,
20
+ load5: 0.23,
21
+ load15: 0.26,
22
+ }.each do |k, v|
23
+ it "should return #{k.inspect} with #{v.inspect}" do
24
+ subject[k].should eq(v)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+ require "metrix/metric"
3
+
4
+ describe "Metrix::Metric" do
5
+ subject(:metric) do
6
+ Metrix::Metric.new("recordStats.pageFaultExceptionsThrown", 10, Time.at(12), database: "opentsdb")
7
+ end
8
+
9
+ it { should_not be_nil }
10
+
11
+ describe "#to_graphite" do
12
+ subject(:string) { metric.to_graphite }
13
+ it { should be_kind_of(String) }
14
+ it { should eq("metrix.test.host.databases.opentsdb.recordStats.pageFaultExceptionsThrown 10 12") }
15
+ end
16
+
17
+ describe "#to_opentsdb" do
18
+ subject(:string) { metric.to_opentsdb }
19
+ it { should be_kind_of(String) }
20
+ it { should eq("put recordStats.pageFaultExceptionsThrown 12 10 database=opentsdb hostname=test.host") }
21
+ end
22
+ end
23
+
@@ -1,37 +1,60 @@
1
1
  require "spec_helper"
2
2
  require "metrix/mongodb"
3
3
 
4
- describe "Metrix::Mongodb", :wip do
4
+ describe "Metrix::Mongodb" do
5
5
  let(:payload) { FIXTURES_PATH.join("mongo_server_status.json").read }
6
6
 
7
- subject(:status) { Metrix::Mongodb.from_json(payload) }
7
+ subject(:status) { Metrix::Mongodb.new(payload) }
8
8
  it { should_not be_nil }
9
9
 
10
+ describe "tagged_metrics" do
11
+ subject(:tagged_metrics) { status.tagged_metrics }
12
+ it { should be_kind_of(Array) }
13
+ it { should_not be_empty }
14
+ end
15
+
16
+ describe "ignore_metric?" do
17
+ %w(
18
+ locks...timeAcquiringMicros.W
19
+ recordStats.opentsdb.pageFaultExceptionsThrown
20
+ ).each do |m|
21
+ it "should ignore #{m}" do
22
+ status.should be_ignore_metric(m)
23
+ end
24
+ end
25
+ end
26
+
10
27
  describe "#metrics" do
11
- subject(:metrics) { status.metrics }
28
+ subject(:metrics) { hash_metrics(status.metrics) }
12
29
  it { should be_kind_of(Hash) }
13
30
 
14
- %w(ok mem.bits pid uptime uptimeMillis uptimeEstimate).each do |name|
31
+ %w(
32
+ mongodb.ok mongodb.mem.bits mongodb.pid mongodb.uptime
33
+ mongodb.uptimeMillis mongodb.uptimeEstimate
34
+ mongodb.recordStats.opentsdb.pageFaultExceptionsThrown
35
+ mongodb.locks.local.timeLockedMicros.r
36
+ ).each do |name|
15
37
  it "should not have key #{name.inspect}" do
16
38
  subject.should_not have_key(name)
17
39
  end
18
40
  end
19
41
 
20
42
  {
21
- "globalLock.totalTime"=>36018171,
22
- "globalLock.lockTime"=>347,
23
- "globalLock.ratio"=>9.634026114207743e-06,
24
- "globalLock.currentQueue.total"=>0,
25
- "globalLock.currentQueue.readers"=>0,
26
- "globalLock.currentQueue.writers"=>0,
27
- "globalLock.activeClients.total"=>0,
28
- "globalLock.activeClients.readers"=>0,
29
- "globalLock.activeClients.writers"=>0,
30
- "mem.resident"=>14,
31
- "mem.virtual"=>2414,
43
+ "mongodb.globalLock.totalTime"=>474819000,
44
+ "mongodb.globalLock.lockTime"=>1060706,
45
+ "mongodb.globalLock.currentQueue.total"=>0,
46
+ "mongodb.globalLock.currentQueue.readers"=>0,
47
+ "mongodb.globalLock.currentQueue.writers"=>0,
48
+ "mongodb.globalLock.activeClients.total"=>0,
49
+ "mongodb.globalLock.activeClients.readers"=>0,
50
+ "mongodb.globalLock.activeClients.writers"=>0,
51
+ "mongodb.mem.resident"=>9,
52
+ "mongodb.mem.virtual"=>2814,
53
+ "mongodb.recordStats.accessesNotInMemory" => 0,
54
+ "mongodb.recordStats.pageFaultExceptionsThrown" => 0,
32
55
  }.each do |k, v|
33
56
  it "should set #{k} to #{v}" do
34
- subject[k].should eq(v)
57
+ subject[k].value.should eq(v)
35
58
  end
36
59
  end
37
60
  end
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+ require "metrix/opentsdb"
3
+
4
+ describe "Metrix::OpenTSDB" do
5
+ let(:data) { FIXTURES_PATH.join("proc.26928.txt").read }
6
+ subject(:client) { Metrix::OpenTSDB.new("127.0.0.1", 1234) }
7
+ let(:metric) { Metrix::Process.new(data) }
8
+
9
+ it { should_not be_nil }
10
+
11
+ describe "adding a metric" do
12
+ before do
13
+ client << metric
14
+ end
15
+
16
+ it { should_not be_nil }
17
+ it { subject.buffers.count.should eq(11) }
18
+
19
+ describe "first in buffer" do
20
+ subject(:line) { client.buffers.first }
21
+ it { should be_kind_of(String) }
22
+ it { should include("pid=26928") }
23
+ it { should include("332517 name=java") }
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,49 @@
1
+ require "spec_helper"
2
+ require "metrix/process"
3
+
4
+ describe "Metrix::Process" do
5
+ let(:data) { FIXTURES_PATH.join("proc.26928.txt").read }
6
+ subject(:process) { Metrix::Process.new(data) }
7
+
8
+ it { should_not be_nil }
9
+ it { subject.time.should be_kind_of(Time) }
10
+
11
+ it { subject.name.should eq("java") }
12
+ it { subject.state.should eq("S") }
13
+ it { subject.utime.should eq(32337) }
14
+ it { subject.stime.should eq(34740) }
15
+
16
+ describe "#metrics" do
17
+ subject(:metrics) do
18
+ hash_metrics(process.metrics)
19
+ end
20
+
21
+ it { should be_kind_of(Hash) }
22
+
23
+ {
24
+ "system.process.minflt" => 332517,
25
+ "system.process.cminflt" => 9459,
26
+ "system.process.majflt" => 13,
27
+ "system.process.cmajflt" => 0,
28
+ "system.process.utime" => 32337,
29
+ "system.process.stime" => 34740,
30
+ "system.process.cutime" => 2,
31
+ "system.process.sctime" => 16,
32
+ "system.process.num_threads" => 125,
33
+ "system.process.vsize" => 1688936448,
34
+ "system.process.rss" => 289510,
35
+ }.each do |k, v|
36
+ it "should set #{k.inspect} to #{v.inspect}" do
37
+ subject[k].value.should eq(v)
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#tags" do
43
+ subject(:tags) { process.tags }
44
+ it { should be_kind_of(Hash) }
45
+ it { subject[:name].should eq("java") }
46
+ it { subject[:pid].should eq(26928) }
47
+ it { subject[:ppid].should eq(1) }
48
+ end
49
+ end
@@ -0,0 +1,38 @@
1
+ require "spec_helper"
2
+ require "metrix/system"
3
+
4
+ describe "Metrix::System" do
5
+ let(:data) {FIXTURES_PATH.join("proc.stat.txt").read }
6
+ subject(:system) { Metrix::System.new(data) }
7
+
8
+ it { should_not be_nil }
9
+ it { subject.processes.should eq(28467) }
10
+ it { subject.procs_running.should eq(1) }
11
+ it { subject.procs_blocked.should eq(0) }
12
+
13
+ describe "#metrics" do
14
+ subject(:metrics) { hash_metrics(system.metrics) }
15
+
16
+ {
17
+ "system.processes" => 28467,
18
+ "system.procs_running"=>1,
19
+ "system.procs_blocked"=>0
20
+ }.each do |k, v|
21
+ it "should set #{k.inspect} to #{v.inspect}" do
22
+ subject[k].value.should eq(v)
23
+ end
24
+ end
25
+ end
26
+
27
+ describe "#cpu" do
28
+ subject(:cpu) { system.cpu }
29
+ it { subject.user.should eq(79833) }
30
+ it { subject.nice.should eq(8300) }
31
+ it { subject.system.should eq(84916) }
32
+ it { subject.idle.should eq(5887890) }
33
+ it { subject.iowait.should eq(54619) }
34
+ it { subject.irq.should eq(93) }
35
+ it { subject.softirq.should eq(19796) }
36
+ end
37
+ end
38
+
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,19 @@ RSpec.configure do |c|
5
5
  c.treat_symbols_as_metadata_keys_with_true_values = true
6
6
  c.filter_run :focus => true
7
7
  c.run_all_when_everything_filtered = true
8
+
9
+ c.before do
10
+ require "metrix"
11
+ Metrix.stub(:hostname) { "test.host" }
12
+ Metrix.logger.level = Logger::ERROR
13
+ end
14
+ end
15
+
16
+ def hash_metrics(metrics)
17
+ metrics.inject({}) do |hash, m|
18
+ hash[m.key] = m
19
+ hash
20
+ end
8
21
  end
9
22
 
10
23
  require "pathname"