em-http-metrics 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ Em-Http-Metrics
2
+ ===============
3
+
4
+ Keeps some data of http request.
5
+
6
+ Em-Http-Metrics is a middleware for em-http-request.
7
+
8
+ Values are kept in RAM, but you can handle it, to do some math, or export it, to use an other tool to find som meaning in all this numbers.
9
+
10
+ Use it
11
+ ------
12
+
13
+ Metrics class handle all the values. The middleware is easy to use : you can use it on a specific connection, or globaly.
14
+
15
+ ```ruby
16
+ m = Metrics::Metrics.new
17
+ EM::HttpRequest.use EventMachine::Middleware::Metrics, m
18
+ ```
19
+ Do some requests.
20
+
21
+ You can export it as a CSV :
22
+
23
+ ```ruby
24
+ require "em-http-metrics/csv"
25
+
26
+ puts m.to_csv.string
27
+ ```
28
+
29
+ Licence
30
+ -------
31
+
32
+ LGPL.
@@ -0,0 +1,39 @@
1
+ module Metrics
2
+ # Metrics storage object
3
+ class Metrics < Array
4
+ end
5
+ end
6
+
7
+ # [TODO] choose what you store, with a block
8
+ # [TODO] log live with a Redis
9
+
10
+ module EventMachine
11
+ module Middleware
12
+ class Metrics
13
+
14
+ def initialize(metrics)
15
+ @metrics = metrics
16
+ @conn = {}
17
+ end
18
+
19
+ def request(client, head, body)
20
+ @conn[client.hash] = Time.new
21
+ [head, body]
22
+ end
23
+
24
+ def response(resp)
25
+ timestamp = Time.new
26
+ t = timestamp - @conn[resp.hash]
27
+ @conn.delete resp.hash
28
+ @metrics << {
29
+ :time => t,
30
+ :timestamp => timestamp,
31
+ :status => resp.response_header.status,
32
+ :uri => resp.req.uri.to_s
33
+ }
34
+ resp
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ require 'csv'
2
+
3
+ module Metrics
4
+ class Metrics
5
+
6
+ # Dump metrics as a CSV
7
+ def to_csv sep=";"
8
+ csv = CSV.new "", :col_sep => sep
9
+ first = true
10
+ self.each do |row|
11
+ if first
12
+ csv << row.keys
13
+ first = false
14
+ end
15
+ csv << row.values
16
+ end
17
+ csv
18
+ end
19
+
20
+ end
21
+ end
File without changes
File without changes
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: em-http-metrics
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mathieu Lecarme
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: em-http-request
16
+ requirement: &2152250380 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0.beta4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2152250380
25
+ - !ruby/object:Gem::Dependency
26
+ name: minitest
27
+ requirement: &2152249180 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2152249180
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &2152248480 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2152248480
47
+ description: Keep metrics of http request
48
+ email: mathieu@garambrogne.net
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files:
52
+ - README.md
53
+ files:
54
+ - README.md
55
+ - lib/em-http-metrics/csv.rb
56
+ - lib/em-http-metrics/json.rb
57
+ - lib/em-http-metrics/redis.rb
58
+ - lib/em-http-metrics.rb
59
+ homepage: http://github.com/athoune/em-http-metrics
60
+ licenses: []
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.10
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Keep metrics of http request
83
+ test_files: []