nosey 0.0.4 → 0.0.5

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.
data/lib/nosey/munin.rb CHANGED
@@ -3,15 +3,15 @@ require 'socket'
3
3
  module Nosey
4
4
  module Munin
5
5
  # Print the output of the munin graph to $stdout
6
- def self.graph(args=ARGV,&block)
7
- client = Graph::DSL.new(&block).client
6
+ def self.graph(args=ARGV,out=$stdio,&block)
7
+ graph = Graph::DSL.new(&block).graph
8
8
 
9
9
  # Munin passes configure into this to figure out the graph.
10
- puts case args.first
10
+ out.puts case args.first
11
11
  when 'configure'
12
- client.configure
12
+ graph.configure
13
13
  else
14
- client.sample
14
+ graph.sample
15
15
  end
16
16
  end
17
17
 
@@ -20,7 +20,7 @@ module Nosey
20
20
  attr_accessor :data, :title, :vertical_label, :category
21
21
  attr_writer :probe_set
22
22
 
23
- def initialize(data)
23
+ def initialize(data=nil)
24
24
  @data = data
25
25
  @category = 'App' # Default it to app duuude
26
26
  yield self if block_given?
@@ -77,7 +77,6 @@ module Nosey
77
77
  report[@probe_set ||= report.keys.first]
78
78
  end
79
79
 
80
-
81
80
  def title
82
81
  @title ||= probe_set
83
82
  end
@@ -110,6 +109,11 @@ module Nosey
110
109
  class Graph::DSL
111
110
  Category = 'App'
112
111
 
112
+ def initialize(&block)
113
+ block.arity > 1 ? block.call(self) : instance_eval(&block)
114
+ self
115
+ end
116
+
113
117
  def socket(host=EventMachine::Nosey::SocketServer::Host,port=EventMachine::Nosey::SocketServer::Port)
114
118
  @host, @port = host, port
115
119
  self
@@ -121,6 +125,21 @@ module Nosey
121
125
  self
122
126
  end
123
127
 
128
+ def title(title)
129
+ @title = title
130
+ self
131
+ end
132
+
133
+ def vertical_label(vertical_label)
134
+ @vertical_label = vertical_label
135
+ self
136
+ end
137
+
138
+ def data(data)
139
+ @data = data
140
+ self
141
+ end
142
+
124
143
  # Category this thing will be in
125
144
  def category(category=Category)
126
145
  @category = category
@@ -129,14 +148,20 @@ module Nosey
129
148
 
130
149
  # Configure an instance of a client.
131
150
  def graph
132
- Graph.new do |c|
133
- c.data = read_socket
134
- c.probe_set = probe_Set
135
- c.category = category
151
+ Graph.new read_data do |c|
152
+ c.probe_set = @probe_set
153
+ c.category = @category
154
+ c.title = @title
155
+ c.vertical_label = @vertical_label
136
156
  end
137
157
  end
138
158
 
139
159
  private
160
+ # Let us drop a string right in here in case we need to test some stuff
161
+ def read_data
162
+ @data || read_socket
163
+ end
164
+
140
165
  # Read the report YAML data from the socket
141
166
  def read_socket
142
167
  UNIXSocket.new(@host).gets("\n\n")
data/lib/nosey/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nosey
2
- VERSION = "0.0.4"
3
- end
2
+ VERSION = "0.0.5"
3
+ end
@@ -52,4 +52,30 @@ describe Nosey::Munin::Graph do
52
52
  @text.scan(/[A-Za-z0-9_]+\.value .+\n/).should have(6).items
53
53
  end
54
54
  end
55
+
56
+ context "munin client" do
57
+ def graph(report, *argv)
58
+ out = StringIO.new
59
+
60
+ Nosey::Munin.graph argv, out do |g|
61
+ g.data report.to_s
62
+ g.category 'Bananas'
63
+ g.title 'Fruit Fly Charts'
64
+ g.vertical_label 'Wing speed (beats per second'
65
+ end
66
+
67
+ out.rewind
68
+ out.read
69
+ end
70
+
71
+ it "should configure" do
72
+ graph(@report, 'configure').should match(/graph_title Fruit Fly Charts/)
73
+ end
74
+
75
+ it "should sample" do
76
+ graph(@report).should match(/chopper_avg\.value \d+/)
77
+ end
78
+
79
+ it "should read from socket"
80
+ end
55
81
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brad Gessler