simple_metrics 0.3.6 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +53 -16
- data/Rakefile +0 -17
- data/bin/populate +13 -26
- data/bin/simple_metrics_client +64 -0
- data/bin/simple_metrics_server +3 -4
- data/lib/simple_metrics.rb +76 -17
- data/lib/simple_metrics/bucket.rb +106 -43
- data/lib/simple_metrics/client.rb +83 -0
- data/lib/simple_metrics/data_point.rb +137 -45
- data/lib/simple_metrics/functions.rb +5 -5
- data/lib/simple_metrics/graph.rb +32 -69
- data/lib/simple_metrics/mongo.rb +48 -0
- data/lib/simple_metrics/server.rb +66 -0
- data/lib/simple_metrics/version.rb +1 -1
- data/simple_metrics.gemspec +0 -6
- data/spec/bucket_spec.rb +152 -17
- data/spec/data_point_spec.rb +64 -14
- data/spec/graph_spec.rb +19 -30
- data/spec/spec_helper.rb +3 -3
- metadata +24 -139
- data/.travis.yml +0 -3
- data/bin/simple_metrics_web +0 -11
- data/config.ru +0 -6
- data/default_config.yml +0 -34
- data/lib/simple_metrics/app.rb +0 -52
- data/lib/simple_metrics/configuration.rb +0 -97
- data/lib/simple_metrics/data_point/base.rb +0 -59
- data/lib/simple_metrics/data_point/counter.rb +0 -20
- data/lib/simple_metrics/data_point/event.rb +0 -16
- data/lib/simple_metrics/data_point/gauge.rb +0 -19
- data/lib/simple_metrics/data_point/timing.rb +0 -15
- data/lib/simple_metrics/data_point_repository.rb +0 -114
- data/lib/simple_metrics/importer.rb +0 -64
- data/lib/simple_metrics/metric.rb +0 -29
- data/lib/simple_metrics/metric_repository.rb +0 -54
- data/lib/simple_metrics/public/css/bootstrap-responsive.min.css +0 -12
- data/lib/simple_metrics/public/css/bootstrap.min.css +0 -689
- data/lib/simple_metrics/public/css/graph.css +0 -45
- data/lib/simple_metrics/public/css/rickshaw.min.css +0 -1
- data/lib/simple_metrics/public/img/glyphicons-halflings-white.png +0 -0
- data/lib/simple_metrics/public/img/glyphicons-halflings.png +0 -0
- data/lib/simple_metrics/public/js/app.js +0 -20
- data/lib/simple_metrics/public/js/collections/graph.js +0 -16
- data/lib/simple_metrics/public/js/collections/metric.js +0 -9
- data/lib/simple_metrics/public/js/helpers.js +0 -23
- data/lib/simple_metrics/public/js/lib/backbone-0.9.2.min.js +0 -38
- data/lib/simple_metrics/public/js/lib/bootstrap.min.js +0 -6
- data/lib/simple_metrics/public/js/lib/d3.v2.min.js +0 -4
- data/lib/simple_metrics/public/js/lib/handlebars-1.0.0.beta.6.js +0 -1550
- data/lib/simple_metrics/public/js/lib/jquery-1.7.1.min.js +0 -4
- data/lib/simple_metrics/public/js/lib/moment.min.js +0 -6
- data/lib/simple_metrics/public/js/lib/rickshaw.min.js +0 -1
- data/lib/simple_metrics/public/js/lib/underscore-1.3.1.min.js +0 -31
- data/lib/simple_metrics/public/js/models/graph.js +0 -6
- data/lib/simple_metrics/public/js/models/metric.js +0 -7
- data/lib/simple_metrics/public/js/router.js +0 -42
- data/lib/simple_metrics/public/js/views/app.js +0 -18
- data/lib/simple_metrics/public/js/views/dashboard.js +0 -10
- data/lib/simple_metrics/public/js/views/graph.js +0 -101
- data/lib/simple_metrics/public/js/views/metric.js +0 -82
- data/lib/simple_metrics/public/js/views/metrics.js +0 -10
- data/lib/simple_metrics/repository.rb +0 -34
- data/lib/simple_metrics/udp_server.rb +0 -81
- data/lib/simple_metrics/views/graph.erb +0 -93
- data/lib/simple_metrics/views/index.erb +0 -0
- data/lib/simple_metrics/views/layout.erb +0 -138
- data/lib/simple_metrics/views/show.erb +0 -31
- data/spec/data_point_repository_spec.rb +0 -77
- data/spec/importer_spec.rb +0 -126
- data/spec/metric_repository_spec.rb +0 -53
@@ -1,93 +0,0 @@
|
|
1
|
-
<h3><%= graph_title params[:time] %></h3><br>
|
2
|
-
<div class="graph" id="graph-<%= params[:time] %>"/>
|
3
|
-
<div class="y-axis" id="y-axis-<%= params[:time] %>"/>
|
4
|
-
|
5
|
-
<script>
|
6
|
-
|
7
|
-
var data = <%= JSON.generate(@series) %>;
|
8
|
-
|
9
|
-
var pastel = [
|
10
|
-
'#239928',
|
11
|
-
'#6CCC70',
|
12
|
-
'#DEFFA1',
|
13
|
-
'#DEFFA1',
|
14
|
-
'#DEFFA1',
|
15
|
-
'#362F2B',
|
16
|
-
'#BFD657',
|
17
|
-
'#FF6131',
|
18
|
-
'#FFFF9D',
|
19
|
-
'#BEEB9F',
|
20
|
-
'#79BD8F',
|
21
|
-
'#00A388'
|
22
|
-
].reverse();
|
23
|
-
|
24
|
-
var customPalette = new Rickshaw.Color.Palette( { scheme: pastel } );
|
25
|
-
var spectrum14Palette = new Rickshaw.Color.Palette( { scheme: "spectrum14" } );
|
26
|
-
|
27
|
-
function addColorToSeries(data, palette) {
|
28
|
-
var result = [];
|
29
|
-
$.each(data, function(k, v){
|
30
|
-
v.color = palette.color();
|
31
|
-
result.push(v);
|
32
|
-
});
|
33
|
-
return result;
|
34
|
-
};
|
35
|
-
|
36
|
-
graph = new Rickshaw.Graph( {
|
37
|
-
element: document.getElementById("graph-<%= params[:time] %>"),
|
38
|
-
// width: 320,
|
39
|
-
// height: 200,
|
40
|
-
renderer: 'line',
|
41
|
-
series: addColorToSeries(data, spectrum14Palette)
|
42
|
-
} );
|
43
|
-
|
44
|
-
function timeUnit(time) {
|
45
|
-
var timeFixture = new Rickshaw.Fixtures.Time();
|
46
|
-
var minuteCustom = {
|
47
|
-
name: 'minute',
|
48
|
-
seconds: 60,
|
49
|
-
formatter: function(d) { return d.getUTCHours()+':'+d.getUTCMinutes()+'h'}
|
50
|
-
};
|
51
|
-
var hourCustom = {
|
52
|
-
name: 'hour',
|
53
|
-
seconds: 60*15,
|
54
|
-
formatter: function(d) { return d.getUTCHours()+':'+d.getUTCMinutes()+'h'}
|
55
|
-
};
|
56
|
-
var dayCustom = {
|
57
|
-
name: 'day',
|
58
|
-
seconds: 60*60*2,
|
59
|
-
formatter: function(d) { return d.getUTCHours()+'h'}
|
60
|
-
};
|
61
|
-
var weekCustom = {
|
62
|
-
name: 'week',
|
63
|
-
seconds: 60*60*2*7*2,
|
64
|
-
formatter: function(d) { return d.getUTCDate()+'. '+d.getUTCMonth()+'.'}
|
65
|
-
};
|
66
|
-
|
67
|
-
switch(time){
|
68
|
-
case 'minute': return minuteCustom; break;
|
69
|
-
case 'hour': return hourCustom; break;
|
70
|
-
case 'day': return dayCustom; break;
|
71
|
-
case 'week': return weekCustom; break;
|
72
|
-
};
|
73
|
-
};
|
74
|
-
|
75
|
-
var x_axis = new Rickshaw.Graph.Axis.Time( {
|
76
|
-
graph: graph,
|
77
|
-
timeUnit: timeUnit("<%= params[:time] %>")
|
78
|
-
} );
|
79
|
-
|
80
|
-
var y_axis = new Rickshaw.Graph.Axis.Y( {
|
81
|
-
graph: graph,
|
82
|
-
orientation: 'left',
|
83
|
-
tickFormat: Rickshaw.Fixtures.Number.formatKMBT,
|
84
|
-
element: document.getElementById('y-axis-<%= params[:time] %>'),
|
85
|
-
} );
|
86
|
-
|
87
|
-
graph.render();
|
88
|
-
|
89
|
-
var hoverDetail = new Rickshaw.Graph.HoverDetail( {
|
90
|
-
graph: graph
|
91
|
-
} );
|
92
|
-
|
93
|
-
</script>
|
File without changes
|
@@ -1,138 +0,0 @@
|
|
1
|
-
<html lang="en">
|
2
|
-
<head>
|
3
|
-
<meta charset="utf-8">
|
4
|
-
<title>SimpleMetrics</title>
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
-
<meta name="description" content="">
|
7
|
-
<meta name="author" content="">
|
8
|
-
|
9
|
-
<link rel='stylesheet' href='/css/bootstrap.min.css' type='text/css' media="screen, projection">
|
10
|
-
<link rel='stylesheet' href='/css/bootstrap-responsive.min.css' type='text/css' media="screen, projection">
|
11
|
-
<link rel='stylesheet' href='/css/rickshaw.min.css' type='text/css' media="screen, projection">
|
12
|
-
<link rel='stylesheet' href='/css/graph.css' type='text/css' media="screen, projection">
|
13
|
-
|
14
|
-
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
15
|
-
<!--[if lt IE 9]>
|
16
|
-
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
17
|
-
<![endif]-->
|
18
|
-
|
19
|
-
<style type="text/css">
|
20
|
-
body {
|
21
|
-
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
|
22
|
-
}
|
23
|
-
</style>
|
24
|
-
|
25
|
-
<script id="graph" type="text/x-handlebars.template">
|
26
|
-
<h3>{{time}}</h3></br>
|
27
|
-
<div class="graph"/>
|
28
|
-
<div class="y-axis"/>
|
29
|
-
</script>
|
30
|
-
|
31
|
-
<script id="metric-list" type="text/x-handlebars-template">
|
32
|
-
<ul class="breadcrumb">
|
33
|
-
<li>
|
34
|
-
<a href="#metrics">Metrics</a> <span class="divider">/</span>
|
35
|
-
</li>
|
36
|
-
<li class="active">{{name}}</li>
|
37
|
-
</ul>
|
38
|
-
|
39
|
-
<table class="table table-striped" style="font-size: 13px">
|
40
|
-
<thead>
|
41
|
-
<tr>
|
42
|
-
<th>Name</th>
|
43
|
-
<th>Total</th>
|
44
|
-
<th>Last Modified</th>
|
45
|
-
<th>Created At</th>
|
46
|
-
</tr>
|
47
|
-
</thead>
|
48
|
-
<tbody>
|
49
|
-
{{#each metrics}}
|
50
|
-
<tr>
|
51
|
-
<td><a href="#metrics/{{name}}">{{name}}</a></td>
|
52
|
-
<td>{{total}}</td>
|
53
|
-
<td>{{dateFormat updated_at}}</td>
|
54
|
-
<td>{{dateFormat created_at}}</td>
|
55
|
-
</tr>
|
56
|
-
{{/each}}
|
57
|
-
</tbody>
|
58
|
-
</table>
|
59
|
-
</script>
|
60
|
-
|
61
|
-
<script id="metric-details" type="text/x-handlebars-template">
|
62
|
-
{{#with metric}}
|
63
|
-
<ul class="breadcrumb">
|
64
|
-
<li>
|
65
|
-
<a href="#metrics">Metrics</a> <span class="divider">/</span>
|
66
|
-
</li>
|
67
|
-
<li class="active">{{name}}</li>
|
68
|
-
</ul>
|
69
|
-
|
70
|
-
<div class="row-fluid">
|
71
|
-
<div class="span12">
|
72
|
-
<div style="margin-bottom:2em" class="row-fluid">
|
73
|
-
<div id="graph-container-minute" class="span6"></div>
|
74
|
-
<div id="graph-container-hour" class="span6"></div>
|
75
|
-
</div>
|
76
|
-
<div class="row-fluid">
|
77
|
-
<div id="graph-container-day" class="span6"></div>
|
78
|
-
<div id="graph-container-week" class="span6"></div>
|
79
|
-
</div>
|
80
|
-
</div>
|
81
|
-
</div>
|
82
|
-
|
83
|
-
{{/with}}
|
84
|
-
</script>
|
85
|
-
|
86
|
-
</head>
|
87
|
-
|
88
|
-
<body>
|
89
|
-
<div class="navbar navbar-fixed-top">
|
90
|
-
<div class="navbar-inner">
|
91
|
-
<div class="container">
|
92
|
-
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
|
93
|
-
<span class="icon-bar"></span>
|
94
|
-
<span class="icon-bar"></span>
|
95
|
-
<span class="icon-bar"></span>
|
96
|
-
</a>
|
97
|
-
<a class="brand" href="/">SimpleMetrics</a>
|
98
|
-
<div class="nav-collapse">
|
99
|
-
<ul class="nav">
|
100
|
-
<li class="active"><a href="/">Metrics</a></li>
|
101
|
-
<li><a href="/dashboard">Dashboards</a></li>
|
102
|
-
<li><a href="/about">About</a></li>
|
103
|
-
</ul>
|
104
|
-
</div><!--/.nav-collapse -->
|
105
|
-
</div>
|
106
|
-
</div>
|
107
|
-
</div>
|
108
|
-
|
109
|
-
<div class="container">
|
110
|
-
<div id="main"></div>
|
111
|
-
</div> <!-- /container -->
|
112
|
-
|
113
|
-
<script src="js/lib/jquery-1.7.1.min.js" type="text/javascript"></script>
|
114
|
-
<script src="js/lib/bootstrap.min.js" type="text/javascript"></script>
|
115
|
-
<script src="js/lib/underscore-1.3.1.min.js" type="text/javascript"></script>
|
116
|
-
<script src="js/lib/backbone-0.9.2.min.js" type="text/javascript"></script>
|
117
|
-
<script src="js/lib/handlebars-1.0.0.beta.6.js" type="text/javascript"></script>
|
118
|
-
<script src="js/lib/d3.v2.min.js" type="text/javascript"></script>
|
119
|
-
<script src="js/lib/rickshaw.min.js" type="text/javascript"></script>
|
120
|
-
<script src="js/lib/moment.min.js" type="text/javascript"></script>
|
121
|
-
|
122
|
-
<script src="js/app.js" type="text/javascript"></script>
|
123
|
-
<script src="js/router.js" type="text/javascript"></script>
|
124
|
-
<script src="js/helpers.js" type="text/javascript"></script>
|
125
|
-
|
126
|
-
<script src="js/models/metric.js" type="text/javascript"></script>
|
127
|
-
<script src="js/models/graph.js" type="text/javascript"></script>
|
128
|
-
|
129
|
-
<script src="js/collections/metric.js" type="text/javascript"></script>
|
130
|
-
<script src="js/collections/graph.js" type="text/javascript"></script>
|
131
|
-
|
132
|
-
<script src="js/views/app.js" type="text/javascript"></script>
|
133
|
-
<script src="js/views/metric.js" type="text/javascript"></script>
|
134
|
-
<script src="js/views/metrics.js" type="text/javascript"></script>
|
135
|
-
<script src="js/views/graph.js" type="text/javascript"></script>
|
136
|
-
|
137
|
-
</body>
|
138
|
-
</html>
|
@@ -1,31 +0,0 @@
|
|
1
|
-
|
2
|
-
<ul class="breadcrumb">
|
3
|
-
<li>
|
4
|
-
<a href="/">Available Metrics</a> <span class="divider">/</span>
|
5
|
-
</li>
|
6
|
-
<li class="active"><%= params[:target].join(', ') %></li>
|
7
|
-
</ul>
|
8
|
-
|
9
|
-
<div class="row-fluid">
|
10
|
-
<div class="span12">
|
11
|
-
<div style="margin-bottom:2em" class="row-fluid">
|
12
|
-
<div id="graph-container-minute" class="span6"></div>
|
13
|
-
<div id="graph-container-hour" class="span6"></div>
|
14
|
-
</div>
|
15
|
-
<div class="row-fluid">
|
16
|
-
<div id="graph-container-day" class="span6"></div>
|
17
|
-
<div id="graph-container-week" class="span6"></div>
|
18
|
-
</div>
|
19
|
-
</div>
|
20
|
-
</div>
|
21
|
-
|
22
|
-
<script>
|
23
|
-
|
24
|
-
$(function() {
|
25
|
-
$("#graph-container-minute").load("/graph?target[]=<%= params[:target].first %>&time=minute");
|
26
|
-
$("#graph-container-hour").load("/graph?target[]=<%= params[:target].first %>&time=hour");
|
27
|
-
$("#graph-container-day").load("/graph?target[]=<%= params[:target].first %>&time=day");
|
28
|
-
$("#graph-container-week").load("/graph?target[]=<%= params[:target].first %>&time=week");
|
29
|
-
});
|
30
|
-
|
31
|
-
</script>
|
@@ -1,77 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
module SimpleMetrics
|
5
|
-
|
6
|
-
describe DataPointRepository do
|
7
|
-
|
8
|
-
before do
|
9
|
-
DataPointRepository.truncate_collections
|
10
|
-
DataPointRepository.ensure_collections_exist
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:ts) do
|
14
|
-
Time.now.utc.to_i
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:repository) do
|
18
|
-
DataPointRepository.for_retention('stats_per_10s')
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#save" do
|
22
|
-
it "saves data point correctly" do
|
23
|
-
dp = DataPoint::Counter.new(:name => "key", :ts => ts)
|
24
|
-
repository.save(dp)
|
25
|
-
|
26
|
-
results = repository.find_all_at_ts(ts)
|
27
|
-
results.should have(1).data_point
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#find_all_at_ts" do
|
32
|
-
it "returns all data points at given time stamp" do
|
33
|
-
dp1 = DataPoint::Counter.new(:name => "key1", :ts => ts)
|
34
|
-
dp2 = DataPoint::Counter.new(:name => "key1", :ts => ts + 10)
|
35
|
-
repository.save(dp1)
|
36
|
-
repository.save(dp2)
|
37
|
-
|
38
|
-
results = repository.find_all_at_ts(ts)
|
39
|
-
results.should have(1).data_point
|
40
|
-
results.first.name.should == "key1"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "#find_all_in_ts_range_by_name" do
|
45
|
-
it "returns all data points in given time stamp range by name" do
|
46
|
-
dp1 = DataPoint::Counter.new(:name => "key1", :ts => ts)
|
47
|
-
dp2 = DataPoint::Counter.new(:name => "key2", :ts => ts + 10)
|
48
|
-
dp3 = DataPoint::Counter.new(:name => "key3", :ts => ts + 20)
|
49
|
-
repository.save(dp1)
|
50
|
-
repository.save(dp2)
|
51
|
-
repository.save(dp3)
|
52
|
-
|
53
|
-
results = repository.find_all_in_ts_range_by_name(ts, ts+10, "key1")
|
54
|
-
results.should have(1).data_point
|
55
|
-
results.first.name.should == "key1"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "#find_all_in_ts_range_by_wildcard" do
|
60
|
-
it "returns all data points in given time stamp range by wildcard" do
|
61
|
-
dp1 = DataPoint::Counter.new(:name => "test.key1", :ts => ts)
|
62
|
-
dp2 = DataPoint::Counter.new(:name => "test.key2", :ts => ts + 10)
|
63
|
-
dp3 = DataPoint::Counter.new(:name => "test.key3", :ts => ts + 20)
|
64
|
-
repository.save(dp1)
|
65
|
-
repository.save(dp2)
|
66
|
-
repository.save(dp3)
|
67
|
-
|
68
|
-
results = repository.find_all_in_ts_range_by_wildcard(ts, ts+10, "test.*")
|
69
|
-
results.should have(2).data_point2
|
70
|
-
results.first.name.should == "test.key1"
|
71
|
-
results.last.name.should == "test.key2"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
data/spec/importer_spec.rb
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
module SimpleMetrics
|
5
|
-
|
6
|
-
describe Importer do
|
7
|
-
|
8
|
-
let(:bucket) do
|
9
|
-
Bucket.first
|
10
|
-
end
|
11
|
-
|
12
|
-
let(:ts) do
|
13
|
-
Time.now.utc.to_i
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "#aggregate_coarse_buckets" do
|
17
|
-
before do
|
18
|
-
DataPointRepository.truncate_collections
|
19
|
-
DataPointRepository.ensure_collections_exist
|
20
|
-
end
|
21
|
-
|
22
|
-
it "aggregates all counter data points" do
|
23
|
-
stats1a = DataPoint::Counter.new(:name => "key1", :value => 5)
|
24
|
-
stats1b = DataPoint::Counter.new(:name => "key1", :value => 7)
|
25
|
-
stats2 = DataPoint::Counter.new(:name => "key2", :value => 3)
|
26
|
-
|
27
|
-
bucket2 = Bucket[1]
|
28
|
-
ts_at_insert = bucket2.previous_ts_bucket(ts)
|
29
|
-
bucket.save(stats1a, ts_at_insert)
|
30
|
-
Importer.aggregate_coarse_buckets(stats1a)
|
31
|
-
bucket.save(stats1b, ts_at_insert)
|
32
|
-
Importer.aggregate_coarse_buckets(stats1b)
|
33
|
-
bucket.save(stats2, ts_at_insert)
|
34
|
-
Importer.aggregate_coarse_buckets(stats2)
|
35
|
-
|
36
|
-
results = bucket2.find_all_at_ts(ts_at_insert)
|
37
|
-
results.should have(2).items
|
38
|
-
|
39
|
-
key1_result = results.find {|stat| stat.name == "key1"}
|
40
|
-
key1_result.value.should == 12
|
41
|
-
key1_result.should be_counter
|
42
|
-
|
43
|
-
key2_result = results.find {|stat| stat.name == "key2"}
|
44
|
-
key2_result.value.should == 3
|
45
|
-
key2_result.should be_counter
|
46
|
-
end
|
47
|
-
|
48
|
-
it "aggregates all gauge data points" do
|
49
|
-
stats1a = DataPoint::Gauge.new(:name => "key1", :value => 5)
|
50
|
-
stats1b = DataPoint::Gauge.new(:name => "key1", :value => 7)
|
51
|
-
stats2 = DataPoint::Gauge.new(:name => "key2", :value => 3)
|
52
|
-
|
53
|
-
bucket2 = Bucket[1]
|
54
|
-
ts_at_insert = bucket2.previous_ts_bucket(ts)
|
55
|
-
bucket.save(stats1a, ts_at_insert)
|
56
|
-
Importer.aggregate_coarse_buckets(stats1a)
|
57
|
-
bucket.save(stats1b, ts_at_insert)
|
58
|
-
Importer.aggregate_coarse_buckets(stats1b)
|
59
|
-
bucket.save(stats2, ts_at_insert)
|
60
|
-
Importer.aggregate_coarse_buckets(stats2)
|
61
|
-
|
62
|
-
results = bucket2.find_all_at_ts(ts_at_insert)
|
63
|
-
results.should have(2).items
|
64
|
-
|
65
|
-
key1_result = results.find {|stat| stat.name == "key1"}
|
66
|
-
key1_result.value.should == 6
|
67
|
-
key1_result.should be_gauge
|
68
|
-
|
69
|
-
key2_result = results.find {|stat| stat.name == "key2"}
|
70
|
-
key2_result.value.should == 3
|
71
|
-
key2_result.should be_gauge
|
72
|
-
end
|
73
|
-
|
74
|
-
end # describe "#aggregate_all"
|
75
|
-
|
76
|
-
describe "#flush_data_points" do
|
77
|
-
before do
|
78
|
-
DataPointRepository.truncate_collections
|
79
|
-
DataPointRepository.ensure_collections_exist
|
80
|
-
MetricRepository.truncate_collections
|
81
|
-
|
82
|
-
stats1 = DataPoint::Counter.new(:name => "key1", :value => 5)
|
83
|
-
stats2 = DataPoint::Counter.new(:name => "key1", :value => 7)
|
84
|
-
stats3 = DataPoint::Counter.new(:name => "key2", :value => 3)
|
85
|
-
@stats = [stats1, stats2, stats3]
|
86
|
-
end
|
87
|
-
|
88
|
-
it "saves all stats in finest/first bucket" do
|
89
|
-
Importer.flush_data_points(@stats)
|
90
|
-
|
91
|
-
results = bucket.find_all_at_ts(ts)
|
92
|
-
results.should have(2).items
|
93
|
-
end
|
94
|
-
|
95
|
-
it "saves all stats and aggregate if duplicates found" do
|
96
|
-
Importer.flush_data_points(@stats)
|
97
|
-
|
98
|
-
results = bucket.find_all_at_ts(ts)
|
99
|
-
results.should have(2).items
|
100
|
-
results.first.name.should == "key1"
|
101
|
-
results.last.name.should == "key2"
|
102
|
-
results.first.value == 12
|
103
|
-
results.last.value == 3
|
104
|
-
end
|
105
|
-
|
106
|
-
it "raises error if name matches but type does not" do
|
107
|
-
stats4 = DataPoint::Gauge.new(:name => "key1", :value => 3)
|
108
|
-
input = @stats + [stats4]
|
109
|
-
expect { Importer.flush_data_points(input) }.to raise_error(SimpleMetrics::DataPoint::NonMatchingTypesError)
|
110
|
-
end
|
111
|
-
|
112
|
-
it "increments metrics counter" do
|
113
|
-
Importer.flush_data_points(@stats)
|
114
|
-
key1 = MetricRepository.find_one_by_name("key1")
|
115
|
-
key1.name.should == "key1"
|
116
|
-
key1.total.should == 2
|
117
|
-
key2 = MetricRepository.find_one_by_name("key2")
|
118
|
-
key2.name.should == "key2"
|
119
|
-
key2.total.should == 1
|
120
|
-
end
|
121
|
-
|
122
|
-
end # describe "#flush_data_points"
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
end
|