fozzie 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
data/Guardfile CHANGED
@@ -7,3 +7,6 @@ guard 'rspec', :version => 2 do
7
7
  watch('spec/spec_helper.rb') { "spec" }
8
8
  end
9
9
 
10
+ guard 'rocco' do
11
+ watch(%r{^lib/.*\.rb$})
12
+ end
@@ -0,0 +1,79 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>hash.rb</title>
6
+ <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
+ </head>
8
+ <body>
9
+ <div id='container'>
10
+ <div id="background"></div>
11
+ <div id="jump_to">
12
+ Jump To &hellip;
13
+ <div id="jump_wrapper">
14
+ <div id="jump_page">
15
+ <a class="source" href="hash.html">hash.rb</a>
16
+ <a class="source" href="../fozzie.html">fozzie.rb</a>
17
+ <a class="source" href="../fozzie/configuration.html">configuration.rb</a>
18
+ <a class="source" href="../fozzie/interface.html">interface.rb</a>
19
+ <a class="source" href="../fozzie/rack/middleware.html">middleware.rb</a>
20
+ <a class="source" href="../fozzie/rails/middleware.html">middleware.rb</a>
21
+ <a class="source" href="../fozzie/socket.html">socket.rb</a>
22
+ <a class="source" href="../fozzie/version.html">version.rb</a>
23
+ </div>
24
+ </div>
25
+ </div>
26
+ <table cellspacing=0 cellpadding=0>
27
+ <thead>
28
+ <tr>
29
+ <th class=docs><h1>hash.rb</h1></th>
30
+ <th class=code></th>
31
+ </tr>
32
+ </thead>
33
+ <tbody>
34
+ <tr id='section-1'>
35
+ <td class=docs>
36
+ <div class="pilwrap">
37
+ <a class="pilcrow" href="#section-1">&#182;</a>
38
+ </div>
39
+
40
+ </td>
41
+ <td class=code>
42
+ <div class='highlight'><pre><span class="k">class</span> <span class="nc">Hash</span></pre></div>
43
+ </td>
44
+ </tr>
45
+ <tr id='section-2'>
46
+ <td class=docs>
47
+ <div class="pilwrap">
48
+ <a class="pilcrow" href="#section-2">&#182;</a>
49
+ </div>
50
+ <p>Return self as symbolized keys hash</p>
51
+ </td>
52
+ <td class=code>
53
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">symbolize_keys</span>
54
+ <span class="nb">self</span><span class="o">.</span><span class="n">dup</span><span class="o">.</span><span class="n">inject</span><span class="p">({})</span> <span class="k">do</span> <span class="o">|</span><span class="n">hsh</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span><span class="n">v</span><span class="p">)</span><span class="o">|</span>
55
+ <span class="n">hsh</span><span class="o">[</span><span class="n">k</span><span class="o">.</span><span class="n">to_s</span><span class="o">.</span><span class="n">to_sym</span><span class="o">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">v</span><span class="o">.</span><span class="n">respond_to?</span><span class="p">(</span><span class="ss">:symbolize_keys</span><span class="p">)</span> <span class="p">?</span> <span class="n">v</span><span class="o">.</span><span class="n">symbolize_keys</span> <span class="p">:</span> <span class="n">v</span><span class="p">)</span>
56
+ <span class="n">hsh</span>
57
+ <span class="k">end</span>
58
+ <span class="k">end</span></pre></div>
59
+ </td>
60
+ </tr>
61
+ <tr id='section-3'>
62
+ <td class=docs>
63
+ <div class="pilwrap">
64
+ <a class="pilcrow" href="#section-3">&#182;</a>
65
+ </div>
66
+ <p>Replace self with symbolized keys hash</p>
67
+
68
+ </td>
69
+ <td class=code>
70
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">symbolize_keys!</span>
71
+ <span class="nb">self</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="nb">self</span><span class="o">.</span><span class="n">symbolize_keys</span><span class="p">)</span>
72
+ <span class="k">end</span>
73
+
74
+ <span class="k">end</span></pre></div>
75
+ </td>
76
+ </tr>
77
+ </table>
78
+ </div>
79
+ </body>
@@ -0,0 +1,148 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>fozzie.rb</title>
6
+ <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
+ </head>
8
+ <body>
9
+ <div id='container'>
10
+ <div id="background"></div>
11
+ <div id="jump_to">
12
+ Jump To &hellip;
13
+ <div id="jump_wrapper">
14
+ <div id="jump_page">
15
+ <a class="source" href="core_ext/hash.html">hash.rb</a>
16
+ <a class="source" href="fozzie.html">fozzie.rb</a>
17
+ <a class="source" href="fozzie/configuration.html">configuration.rb</a>
18
+ <a class="source" href="fozzie/interface.html">interface.rb</a>
19
+ <a class="source" href="fozzie/rack/middleware.html">middleware.rb</a>
20
+ <a class="source" href="fozzie/rails/middleware.html">middleware.rb</a>
21
+ <a class="source" href="fozzie/socket.html">socket.rb</a>
22
+ <a class="source" href="fozzie/version.html">version.rb</a>
23
+ </div>
24
+ </div>
25
+ </div>
26
+ <table cellspacing=0 cellpadding=0>
27
+ <thead>
28
+ <tr>
29
+ <th class=docs><h1>fozzie.rb</h1></th>
30
+ <th class=code></th>
31
+ </tr>
32
+ </thead>
33
+ <tbody>
34
+ <tr id='section-1'>
35
+ <td class=docs>
36
+ <div class="pilwrap">
37
+ <a class="pilcrow" href="#section-1">&#182;</a>
38
+ </div>
39
+ <p>Fozzie is an implementation of the Statsd statistics gathering tool,
40
+ designed to make gathering stastistics from applications easy, fast, and effective.</p>
41
+
42
+ <p>Configuration can be applied through a block and/or configuration file (&lsquo;config/fozzie.yml&rsquo;)</p>
43
+
44
+ <p>Fozzie provides automatic namespacing for the current environment, and host.</p>
45
+
46
+ <p>Rack and Rails middleware is avaliable to gather statistics on the processing time of Controller actions.</p>
47
+ </td>
48
+ <td class=code>
49
+ <div class='highlight'><pre><span class="k">module</span> <span class="nn">Fozzie</span>
50
+
51
+ <span class="n">require_relative</span> <span class="s1">&#39;fozzie/configuration&#39;</span>
52
+ <span class="n">require_relative</span> <span class="s2">&quot;fozzie/interface&quot;</span>
53
+ <span class="n">require_relative</span> <span class="s2">&quot;fozzie/version&quot;</span>
54
+
55
+ <span class="n">require_relative</span> <span class="s2">&quot;fozzie/rack/middleware&quot;</span>
56
+ <span class="n">require_relative</span> <span class="s2">&quot;fozzie/rails/middleware&quot;</span>
57
+
58
+ <span class="k">class</span> <span class="o">&lt;&lt;</span> <span class="nb">self</span></pre></div>
59
+ </td>
60
+ </tr>
61
+ <tr id='section-2'>
62
+ <td class=docs>
63
+ <div class="pilwrap">
64
+ <a class="pilcrow" href="#section-2">&#182;</a>
65
+ </div>
66
+ <p>Shortcut for <code>Fozzie.config</code></p>
67
+ </td>
68
+ <td class=code>
69
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">c</span>
70
+ <span class="n">config</span>
71
+ <span class="k">end</span></pre></div>
72
+ </td>
73
+ </tr>
74
+ <tr id='section-3'>
75
+ <td class=docs>
76
+ <div class="pilwrap">
77
+ <a class="pilcrow" href="#section-3">&#182;</a>
78
+ </div>
79
+ <p>Returns the current configuration. Creates configuration on first-time request</p>
80
+ </td>
81
+ <td class=code>
82
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">config</span>
83
+ <span class="vi">@config</span> <span class="o">||=</span> <span class="no">Configuration</span><span class="o">.</span><span class="n">new</span>
84
+ <span class="k">end</span></pre></div>
85
+ </td>
86
+ </tr>
87
+ <tr id='section-4'>
88
+ <td class=docs>
89
+ <div class="pilwrap">
90
+ <a class="pilcrow" href="#section-4">&#182;</a>
91
+ </div>
92
+ <p>Allows the setting on valudes against the configuration</p>
93
+
94
+ <p><code>Fozzie.configure {|config| config.wat = :random }</code></p>
95
+ </td>
96
+ <td class=code>
97
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">configure</span>
98
+ <span class="k">yield</span> <span class="n">c</span> <span class="k">if</span> <span class="nb">block_given?</span>
99
+ <span class="k">end</span></pre></div>
100
+ </td>
101
+ </tr>
102
+ <tr id='section-5'>
103
+ <td class=docs>
104
+ <div class="pilwrap">
105
+ <a class="pilcrow" href="#section-5">&#182;</a>
106
+ </div>
107
+ <p>Set a logger</p>
108
+ </td>
109
+ <td class=code>
110
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">logger</span><span class="o">=</span><span class="p">(</span><span class="n">logger</span><span class="p">)</span>
111
+ <span class="vi">@logger</span> <span class="o">=</span> <span class="n">logger</span>
112
+ <span class="k">end</span></pre></div>
113
+ </td>
114
+ </tr>
115
+ <tr id='section-6'>
116
+ <td class=docs>
117
+ <div class="pilwrap">
118
+ <a class="pilcrow" href="#section-6">&#182;</a>
119
+ </div>
120
+ <p>Accessor for logger</p>
121
+ </td>
122
+ <td class=code>
123
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">logger</span>
124
+ <span class="vi">@logger</span>
125
+ <span class="k">end</span>
126
+
127
+ <span class="k">end</span></pre></div>
128
+ </td>
129
+ </tr>
130
+ <tr id='section-7'>
131
+ <td class=docs>
132
+ <div class="pilwrap">
133
+ <a class="pilcrow" href="#section-7">&#182;</a>
134
+ </div>
135
+ <p>Loads each namespace for registering statistics</p>
136
+
137
+ </td>
138
+ <td class=code>
139
+ <div class='highlight'><pre> <span class="nb">self</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">namespaces</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">klas</span><span class="o">|</span>
140
+ <span class="no">Kernel</span><span class="o">.</span><span class="n">const_set</span><span class="p">(</span><span class="n">klas</span><span class="p">,</span> <span class="no">Interface</span><span class="o">.</span><span class="n">instance</span><span class="p">)</span> <span class="k">unless</span> <span class="nb">const_defined?</span><span class="p">(</span><span class="n">klas</span><span class="p">)</span>
141
+ <span class="k">end</span>
142
+
143
+ <span class="k">end</span></pre></div>
144
+ </td>
145
+ </tr>
146
+ </table>
147
+ </div>
148
+ </body>
@@ -0,0 +1,174 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>configuration.rb</title>
6
+ <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
+ </head>
8
+ <body>
9
+ <div id='container'>
10
+ <div id="background"></div>
11
+ <div id="jump_to">
12
+ Jump To &hellip;
13
+ <div id="jump_wrapper">
14
+ <div id="jump_page">
15
+ <a class="source" href="../core_ext/hash.html">hash.rb</a>
16
+ <a class="source" href="../fozzie.html">fozzie.rb</a>
17
+ <a class="source" href="configuration.html">configuration.rb</a>
18
+ <a class="source" href="interface.html">interface.rb</a>
19
+ <a class="source" href="rack/middleware.html">middleware.rb</a>
20
+ <a class="source" href="rails/middleware.html">middleware.rb</a>
21
+ <a class="source" href="socket.html">socket.rb</a>
22
+ <a class="source" href="version.html">version.rb</a>
23
+ </div>
24
+ </div>
25
+ </div>
26
+ <table cellspacing=0 cellpadding=0>
27
+ <thead>
28
+ <tr>
29
+ <th class=docs><h1>configuration.rb</h1></th>
30
+ <th class=code></th>
31
+ </tr>
32
+ </thead>
33
+ <tbody>
34
+ <tr id='section-1'>
35
+ <td class=docs>
36
+ <div class="pilwrap">
37
+ <a class="pilcrow" href="#section-1">&#182;</a>
38
+ </div>
39
+
40
+ </td>
41
+ <td class=code>
42
+ <div class='highlight'><pre><span class="nb">require</span> <span class="s1">&#39;core_ext/hash&#39;</span>
43
+ <span class="nb">require</span> <span class="s1">&#39;sys/uname&#39;</span>
44
+ <span class="nb">require</span> <span class="s1">&#39;timeout&#39;</span>
45
+
46
+ <span class="k">module</span> <span class="nn">Fozzie</span></pre></div>
47
+ </td>
48
+ </tr>
49
+ <tr id='section-2'>
50
+ <td class=docs>
51
+ <div class="pilwrap">
52
+ <a class="pilcrow" href="#section-2">&#182;</a>
53
+ </div>
54
+ <p>Fozzie configuration allows assignment of global properties
55
+ that will be used within the Fozzie codebase.</p>
56
+ </td>
57
+ <td class=code>
58
+ <div class='highlight'><pre> <span class="k">class</span> <span class="nc">Configuration</span>
59
+ <span class="kp">include</span> <span class="no">Sys</span>
60
+
61
+ <span class="kp">attr_accessor</span> <span class="ss">:env</span><span class="p">,</span> <span class="ss">:config_path</span><span class="p">,</span> <span class="ss">:host</span><span class="p">,</span> <span class="ss">:port</span><span class="p">,</span> <span class="ss">:appname</span><span class="p">,</span> <span class="ss">:namespaces</span><span class="p">,</span> <span class="ss">:timeout</span>
62
+
63
+ <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">args</span> <span class="o">=</span> <span class="p">{})</span>
64
+ <span class="n">merge_and_assign_config</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
65
+ <span class="nb">self</span><span class="o">.</span><span class="n">origin_name</span>
66
+ <span class="k">end</span></pre></div>
67
+ </td>
68
+ </tr>
69
+ <tr id='section-3'>
70
+ <td class=docs>
71
+ <div class="pilwrap">
72
+ <a class="pilcrow" href="#section-3">&#182;</a>
73
+ </div>
74
+ <p>Returns the prefix for any stat requested to be registered</p>
75
+ </td>
76
+ <td class=code>
77
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">data_prefix</span>
78
+ <span class="n">s</span> <span class="o">=</span> <span class="o">[</span><span class="n">appname</span><span class="p">,</span> <span class="n">origin_name</span><span class="p">,</span> <span class="n">env</span><span class="o">].</span><span class="n">collect</span> <span class="k">do</span> <span class="o">|</span><span class="n">s</span><span class="o">|</span>
79
+ <span class="n">s</span><span class="o">.</span><span class="n">empty?</span> <span class="p">?</span> <span class="kp">nil</span> <span class="p">:</span> <span class="n">s</span><span class="o">.</span><span class="n">gsub</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">,</span> <span class="s1">&#39;-&#39;</span><span class="p">)</span>
80
+ <span class="k">end</span><span class="o">.</span><span class="n">compact</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span>
81
+ <span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">empty?</span> <span class="p">?</span> <span class="kp">nil</span> <span class="p">:</span> <span class="n">s</span><span class="p">)</span>
82
+ <span class="k">end</span></pre></div>
83
+ </td>
84
+ </tr>
85
+ <tr id='section-4'>
86
+ <td class=docs>
87
+ <div class="pilwrap">
88
+ <a class="pilcrow" href="#section-4">&#182;</a>
89
+ </div>
90
+ <p>Returns the origin name of the current machine to register the stat against</p>
91
+ </td>
92
+ <td class=code>
93
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">origin_name</span>
94
+ <span class="vi">@origin_name</span> <span class="o">||=</span> <span class="no">Uname</span><span class="o">.</span><span class="n">uname</span><span class="o">.</span><span class="n">nodename</span>
95
+ <span class="k">end</span>
96
+
97
+ <span class="kp">private</span></pre></div>
98
+ </td>
99
+ </tr>
100
+ <tr id='section-5'>
101
+ <td class=docs>
102
+ <div class="pilwrap">
103
+ <a class="pilcrow" href="#section-5">&#182;</a>
104
+ </div>
105
+ <p>Handle the merging of the given configuaration, and the default config.</p>
106
+ </td>
107
+ <td class=code>
108
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">merge_and_assign_config</span><span class="p">(</span><span class="n">args</span> <span class="o">=</span> <span class="p">{})</span>
109
+ <span class="n">arg</span> <span class="o">=</span> <span class="nb">self</span><span class="o">.</span><span class="n">class</span><span class="o">.</span><span class="n">default_configuration</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">args</span><span class="o">.</span><span class="n">symbolize_keys</span><span class="p">)</span>
110
+ <span class="n">arg</span><span class="o">.</span><span class="n">merge!</span><span class="p">(</span><span class="n">config_from_yaml</span><span class="p">(</span><span class="n">arg</span><span class="p">))</span>
111
+ <span class="n">arg</span><span class="o">.</span><span class="n">each</span> <span class="p">{</span><span class="o">|</span><span class="n">a</span><span class="p">,</span><span class="n">v</span><span class="o">|</span> <span class="nb">self</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="n">a</span><span class="si">}</span><span class="s2">=&quot;</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span> <span class="k">if</span> <span class="nb">self</span><span class="o">.</span><span class="n">respond_to?</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">to_sym</span><span class="p">)</span> <span class="p">}</span>
112
+
113
+ <span class="n">arg</span>
114
+ <span class="k">end</span></pre></div>
115
+ </td>
116
+ </tr>
117
+ <tr id='section-6'>
118
+ <td class=docs>
119
+ <div class="pilwrap">
120
+ <a class="pilcrow" href="#section-6">&#182;</a>
121
+ </div>
122
+ <p>Default configuration settings</p>
123
+ </td>
124
+ <td class=code>
125
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">default_configuration</span>
126
+ <span class="p">{</span>
127
+ <span class="ss">:host</span> <span class="o">=&gt;</span> <span class="s1">&#39;127.0.0.1&#39;</span><span class="p">,</span>
128
+ <span class="ss">:port</span> <span class="o">=&gt;</span> <span class="mi">8125</span><span class="p">,</span>
129
+ <span class="ss">:config_path</span> <span class="o">=&gt;</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
130
+ <span class="ss">:env</span> <span class="o">=&gt;</span> <span class="p">(</span><span class="no">ENV</span><span class="o">[</span><span class="s1">&#39;RACK_ENV&#39;</span><span class="o">]</span> <span class="o">||</span> <span class="no">ENV</span><span class="o">[</span><span class="s1">&#39;RAILS_ENV&#39;</span><span class="o">]</span> <span class="o">||</span> <span class="s1">&#39;development&#39;</span><span class="p">),</span>
131
+ <span class="ss">:appname</span> <span class="o">=&gt;</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
132
+ <span class="ss">:namespaces</span> <span class="o">=&gt;</span> <span class="sx">%w{Stats S Statistics Warehouse}</span><span class="p">,</span>
133
+ <span class="ss">:timeout</span> <span class="o">=&gt;</span> <span class="mi">0</span><span class="o">.</span><span class="mi">5</span>
134
+ <span class="p">}</span><span class="o">.</span><span class="n">dup</span>
135
+ <span class="k">end</span></pre></div>
136
+ </td>
137
+ </tr>
138
+ <tr id='section-7'>
139
+ <td class=docs>
140
+ <div class="pilwrap">
141
+ <a class="pilcrow" href="#section-7">&#182;</a>
142
+ </div>
143
+ <p>Loads the configuration from YAML, if possible</p>
144
+ </td>
145
+ <td class=code>
146
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">config_from_yaml</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
147
+ <span class="n">fp</span> <span class="o">=</span> <span class="n">full_config_path</span><span class="p">(</span><span class="n">args</span><span class="o">[</span><span class="ss">:config_path</span><span class="o">]</span><span class="p">)</span>
148
+ <span class="k">return</span> <span class="p">{}</span> <span class="k">unless</span> <span class="no">File</span><span class="o">.</span><span class="n">exists?</span><span class="p">(</span><span class="n">fp</span><span class="p">)</span>
149
+ <span class="n">cnf</span> <span class="o">=</span> <span class="no">YAML</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="no">File</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">fp</span><span class="p">))</span><span class="o">[</span><span class="n">args</span><span class="o">[</span><span class="ss">:env</span><span class="o">]]</span>
150
+ <span class="p">(</span><span class="n">cnf</span><span class="o">.</span><span class="n">kind_of?</span><span class="p">(</span><span class="no">Hash</span><span class="p">))</span> <span class="p">?</span> <span class="n">cnf</span><span class="o">.</span><span class="n">symbolize_keys</span> <span class="p">:</span> <span class="p">{}</span>
151
+ <span class="k">end</span></pre></div>
152
+ </td>
153
+ </tr>
154
+ <tr id='section-8'>
155
+ <td class=docs>
156
+ <div class="pilwrap">
157
+ <a class="pilcrow" href="#section-8">&#182;</a>
158
+ </div>
159
+ <p>Returns the absolute file path for the Fozzie configuration, relative to the given path</p>
160
+
161
+ </td>
162
+ <td class=code>
163
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">full_config_path</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
164
+ <span class="no">File</span><span class="o">.</span><span class="n">expand_path</span><span class="p">(</span><span class="s1">&#39;config/fozzie.yml&#39;</span><span class="p">,</span> <span class="n">path</span><span class="p">)</span>
165
+ <span class="k">end</span>
166
+
167
+ <span class="k">end</span>
168
+
169
+ <span class="k">end</span></pre></div>
170
+ </td>
171
+ </tr>
172
+ </table>
173
+ </div>
174
+ </body>
@@ -0,0 +1,288 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>interface.rb</title>
6
+ <link rel="stylesheet" href="http://jashkenas.github.com/docco/resources/docco.css">
7
+ </head>
8
+ <body>
9
+ <div id='container'>
10
+ <div id="background"></div>
11
+ <div id="jump_to">
12
+ Jump To &hellip;
13
+ <div id="jump_wrapper">
14
+ <div id="jump_page">
15
+ <a class="source" href="../core_ext/hash.html">hash.rb</a>
16
+ <a class="source" href="../fozzie.html">fozzie.rb</a>
17
+ <a class="source" href="configuration.html">configuration.rb</a>
18
+ <a class="source" href="interface.html">interface.rb</a>
19
+ <a class="source" href="rack/middleware.html">middleware.rb</a>
20
+ <a class="source" href="rails/middleware.html">middleware.rb</a>
21
+ <a class="source" href="socket.html">socket.rb</a>
22
+ <a class="source" href="version.html">version.rb</a>
23
+ </div>
24
+ </div>
25
+ </div>
26
+ <table cellspacing=0 cellpadding=0>
27
+ <thead>
28
+ <tr>
29
+ <th class=docs><h1>interface.rb</h1></th>
30
+ <th class=code></th>
31
+ </tr>
32
+ </thead>
33
+ <tbody>
34
+ <tr id='section-1'>
35
+ <td class=docs>
36
+ <div class="pilwrap">
37
+ <a class="pilcrow" href="#section-1">&#182;</a>
38
+ </div>
39
+
40
+ </td>
41
+ <td class=code>
42
+ <div class='highlight'><pre><span class="nb">require</span> <span class="s1">&#39;singleton&#39;</span>
43
+ <span class="nb">require</span> <span class="s1">&#39;fozzie/socket&#39;</span>
44
+
45
+ <span class="k">module</span> <span class="nn">Fozzie</span>
46
+ <span class="k">class</span> <span class="nc">Interface</span>
47
+ <span class="kp">include</span> <span class="no">Fozzie</span><span class="o">::</span><span class="no">Socket</span><span class="p">,</span> <span class="no">Singleton</span></pre></div>
48
+ </td>
49
+ </tr>
50
+ <tr id='section-2'>
51
+ <td class=docs>
52
+ <div class="pilwrap">
53
+ <a class="pilcrow" href="#section-2">&#182;</a>
54
+ </div>
55
+ <p>Increments the given stat by one, with an optional sample rate</p>
56
+
57
+ <p><code>Stats.increment &lsquo;wat&rsquo;</code></p>
58
+ </td>
59
+ <td class=code>
60
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">increment</span><span class="p">(</span><span class="n">stat</span><span class="p">,</span> <span class="n">sample_rate</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
61
+ <span class="n">count</span><span class="p">(</span><span class="n">stat</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">sample_rate</span><span class="p">)</span>
62
+ <span class="k">end</span></pre></div>
63
+ </td>
64
+ </tr>
65
+ <tr id='section-3'>
66
+ <td class=docs>
67
+ <div class="pilwrap">
68
+ <a class="pilcrow" href="#section-3">&#182;</a>
69
+ </div>
70
+ <p>Decrements the given stat by one, with an optional sample rate</p>
71
+
72
+ <p><code>Stats.decrement &lsquo;wat&rsquo;</code></p>
73
+ </td>
74
+ <td class=code>
75
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">decrement</span><span class="p">(</span><span class="n">stat</span><span class="p">,</span> <span class="n">sample_rate</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
76
+ <span class="n">count</span><span class="p">(</span><span class="n">stat</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">sample_rate</span><span class="p">)</span>
77
+ <span class="k">end</span></pre></div>
78
+ </td>
79
+ </tr>
80
+ <tr id='section-4'>
81
+ <td class=docs>
82
+ <div class="pilwrap">
83
+ <a class="pilcrow" href="#section-4">&#182;</a>
84
+ </div>
85
+ <p>Registers a count for the given stat, with an optional sample rate</p>
86
+
87
+ <p><code>Stats.count &lsquo;wat&rsquo;, 500</code></p>
88
+ </td>
89
+ <td class=code>
90
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">count</span><span class="p">(</span><span class="n">stat</span><span class="p">,</span> <span class="n">count</span><span class="p">,</span> <span class="n">sample_rate</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
91
+ <span class="nb">send</span><span class="p">(</span><span class="n">stat</span><span class="p">,</span> <span class="n">count</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="n">sample_rate</span><span class="p">)</span>
92
+ <span class="k">end</span></pre></div>
93
+ </td>
94
+ </tr>
95
+ <tr id='section-5'>
96
+ <td class=docs>
97
+ <div class="pilwrap">
98
+ <a class="pilcrow" href="#section-5">&#182;</a>
99
+ </div>
100
+ <p>Registers a timing (in ms) for the given stat, with an optional sample rate</p>
101
+
102
+ <p><code>Stats.timing &lsquo;wat&rsquo;, 500</code></p>
103
+ </td>
104
+ <td class=code>
105
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">timing</span><span class="p">(</span><span class="n">stat</span><span class="p">,</span> <span class="n">ms</span><span class="p">,</span> <span class="n">sample_rate</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
106
+ <span class="nb">send</span><span class="p">(</span><span class="n">stat</span><span class="p">,</span> <span class="n">ms</span><span class="p">,</span> <span class="s1">&#39;ms&#39;</span><span class="p">,</span> <span class="n">sample_rate</span><span class="p">)</span>
107
+ <span class="k">end</span></pre></div>
108
+ </td>
109
+ </tr>
110
+ <tr id='section-6'>
111
+ <td class=docs>
112
+ <div class="pilwrap">
113
+ <a class="pilcrow" href="#section-6">&#182;</a>
114
+ </div>
115
+ <p>Registers the time taken to complete a given block (in ms), with an optional sample rate</p>
116
+
117
+ <p><code>Stats.time &lsquo;wat&rsquo; { # Do something&hellip; }</code></p>
118
+ </td>
119
+ <td class=code>
120
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">time</span><span class="p">(</span><span class="n">stat</span><span class="p">,</span> <span class="n">sample_rate</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
121
+ <span class="n">stat</span> <span class="o">=</span> <span class="n">stat</span><span class="o">.</span><span class="n">flatten</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)</span> <span class="k">if</span> <span class="n">stat</span><span class="o">.</span><span class="n">kind_of?</span><span class="p">(</span><span class="nb">Array</span><span class="p">)</span>
122
+ <span class="n">start</span> <span class="o">=</span> <span class="no">Time</span><span class="o">.</span><span class="n">now</span>
123
+ <span class="n">result</span> <span class="o">=</span> <span class="k">yield</span>
124
+ <span class="n">timing</span><span class="p">(</span><span class="n">stat</span><span class="p">,</span> <span class="p">((</span><span class="no">Time</span><span class="o">.</span><span class="n">now</span> <span class="o">-</span> <span class="n">start</span><span class="p">)</span> <span class="o">*</span> <span class="mi">1000</span><span class="p">)</span><span class="o">.</span><span class="n">round</span><span class="p">,</span> <span class="n">sample_rate</span><span class="p">)</span>
125
+ <span class="n">result</span>
126
+ <span class="k">end</span></pre></div>
127
+ </td>
128
+ </tr>
129
+ <tr id='section-7'>
130
+ <td class=docs>
131
+ <div class="pilwrap">
132
+ <a class="pilcrow" href="#section-7">&#182;</a>
133
+ </div>
134
+ <p>Registers the time taken to complete a given block (in ms), with an optional sample rate</p>
135
+
136
+ <p><code>Stats.time_to_do &lsquo;wat&rsquo; { # Do something, again&hellip; }</code></p>
137
+ </td>
138
+ <td class=code>
139
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">time_to_do</span><span class="p">(</span><span class="n">stat</span><span class="p">,</span> <span class="n">sample_rate</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">block</span><span class="p">)</span>
140
+ <span class="n">time_for</span><span class="p">(</span><span class="n">stat</span><span class="p">,</span> <span class="n">sample_rate</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">block</span><span class="p">)</span>
141
+ <span class="k">end</span></pre></div>
142
+ </td>
143
+ </tr>
144
+ <tr id='section-8'>
145
+ <td class=docs>
146
+ <div class="pilwrap">
147
+ <a class="pilcrow" href="#section-8">&#182;</a>
148
+ </div>
149
+ <p>Registers the time taken to complete a given block (in ms), with an optional sample rate</p>
150
+
151
+ <p><code>Stats.time_for &lsquo;wat&rsquo; { # Do something, grrr&hellip; }</code></p>
152
+ </td>
153
+ <td class=code>
154
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">time_for</span><span class="p">(</span><span class="n">stat</span><span class="p">,</span> <span class="n">sample_rate</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">block</span><span class="p">)</span>
155
+ <span class="n">time</span><span class="p">(</span><span class="n">stat</span><span class="p">,</span> <span class="n">sample_rate</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">block</span><span class="p">)</span>
156
+ <span class="k">end</span></pre></div>
157
+ </td>
158
+ </tr>
159
+ <tr id='section-9'>
160
+ <td class=docs>
161
+ <div class="pilwrap">
162
+ <a class="pilcrow" href="#section-9">&#182;</a>
163
+ </div>
164
+ <p>Registers a commit</p>
165
+
166
+ <p><code>Stats.commit</code></p>
167
+ </td>
168
+ <td class=code>
169
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">commit</span>
170
+ <span class="n">event</span> <span class="ss">:commit</span>
171
+ <span class="k">end</span></pre></div>
172
+ </td>
173
+ </tr>
174
+ <tr id='section-10'>
175
+ <td class=docs>
176
+ <div class="pilwrap">
177
+ <a class="pilcrow" href="#section-10">&#182;</a>
178
+ </div>
179
+ <p>Registers a commit</p>
180
+
181
+ <p><code>Stats.commit</code></p>
182
+ </td>
183
+ <td class=code>
184
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">committed</span>
185
+ <span class="n">commit</span>
186
+ <span class="k">end</span></pre></div>
187
+ </td>
188
+ </tr>
189
+ <tr id='section-11'>
190
+ <td class=docs>
191
+ <div class="pilwrap">
192
+ <a class="pilcrow" href="#section-11">&#182;</a>
193
+ </div>
194
+ <p>Registers that the app has been built</p>
195
+
196
+ <p><code>Stats.built</code></p>
197
+ </td>
198
+ <td class=code>
199
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">built</span>
200
+ <span class="n">event</span> <span class="ss">:build</span>
201
+ <span class="k">end</span></pre></div>
202
+ </td>
203
+ </tr>
204
+ <tr id='section-12'>
205
+ <td class=docs>
206
+ <div class="pilwrap">
207
+ <a class="pilcrow" href="#section-12">&#182;</a>
208
+ </div>
209
+ <p>Registers a build for the app</p>
210
+
211
+ <p><code>Stats.build</code></p>
212
+ </td>
213
+ <td class=code>
214
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">build</span>
215
+ <span class="n">built</span>
216
+ <span class="k">end</span></pre></div>
217
+ </td>
218
+ </tr>
219
+ <tr id='section-13'>
220
+ <td class=docs>
221
+ <div class="pilwrap">
222
+ <a class="pilcrow" href="#section-13">&#182;</a>
223
+ </div>
224
+ <p>Registers a deployed status for the given app</p>
225
+
226
+ <p><code>Stats.deployed &lsquo;watapp&rsquo;</code></p>
227
+ </td>
228
+ <td class=code>
229
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">deployed</span><span class="p">(</span><span class="n">app</span> <span class="o">=</span> <span class="kp">nil</span><span class="p">)</span>
230
+ <span class="n">event</span> <span class="ss">:deploy</span><span class="p">,</span> <span class="n">app</span>
231
+ <span class="k">end</span></pre></div>
232
+ </td>
233
+ </tr>
234
+ <tr id='section-14'>
235
+ <td class=docs>
236
+ <div class="pilwrap">
237
+ <a class="pilcrow" href="#section-14">&#182;</a>
238
+ </div>
239
+ <p>Registers a deployment for the given app</p>
240
+
241
+ <p><code>Stats.deploy &lsquo;watapp&rsquo;</code></p>
242
+ </td>
243
+ <td class=code>
244
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">deploy</span><span class="p">(</span><span class="n">app</span> <span class="o">=</span> <span class="kp">nil</span><span class="p">)</span>
245
+ <span class="n">deployed</span><span class="p">(</span><span class="n">app</span><span class="p">)</span>
246
+ <span class="k">end</span></pre></div>
247
+ </td>
248
+ </tr>
249
+ <tr id='section-15'>
250
+ <td class=docs>
251
+ <div class="pilwrap">
252
+ <a class="pilcrow" href="#section-15">&#182;</a>
253
+ </div>
254
+ <p>Registers an increment on the result of the given boolean</p>
255
+
256
+ <p><code>Stats.increment_on &lsquo;wat&rsquo;, wat.random?</code></p>
257
+ </td>
258
+ <td class=code>
259
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">increment_on</span><span class="p">(</span><span class="n">stat</span><span class="p">,</span> <span class="n">perf</span><span class="p">,</span> <span class="n">sample_rate</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
260
+ <span class="n">key</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">#{</span><span class="n">stat</span><span class="si">}</span><span class="s2">.%s&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">perf</span> <span class="p">?</span> <span class="s2">&quot;success&quot;</span> <span class="p">:</span> <span class="s2">&quot;fail&quot;</span><span class="p">)</span>
261
+ <span class="n">increment</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">sample_rate</span><span class="p">)</span>
262
+ <span class="n">perf</span>
263
+ <span class="k">end</span></pre></div>
264
+ </td>
265
+ </tr>
266
+ <tr id='section-16'>
267
+ <td class=docs>
268
+ <div class="pilwrap">
269
+ <a class="pilcrow" href="#section-16">&#182;</a>
270
+ </div>
271
+ <p>Register an event of any type</p>
272
+
273
+ <p><code>Stats.event &lsquo;wat&rsquo;, &lsquo;app&rsquo;</code></p>
274
+
275
+ </td>
276
+ <td class=code>
277
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">event</span><span class="p">(</span><span class="nb">type</span><span class="p">,</span> <span class="n">app</span> <span class="o">=</span> <span class="kp">nil</span><span class="p">)</span>
278
+ <span class="n">stat</span> <span class="o">=</span> <span class="o">[</span><span class="s2">&quot;event&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">.</span><span class="n">to_s</span><span class="p">,</span> <span class="n">app</span><span class="o">].</span><span class="n">compact</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)</span>
279
+ <span class="n">timing</span> <span class="n">stat</span><span class="p">,</span> <span class="no">Time</span><span class="o">.</span><span class="n">now</span><span class="o">.</span><span class="n">usec</span>
280
+ <span class="k">end</span>
281
+
282
+ <span class="k">end</span>
283
+ <span class="k">end</span></pre></div>
284
+ </td>
285
+ </tr>
286
+ </table>
287
+ </div>
288
+ </body>