alephant-logger 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -7
- data/lib/alephant/logger/cloudwatch_decorator.rb +11 -44
- data/lib/alephant/logger/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de780cad17918478c874e67e2b92f664e4be91ee
|
4
|
+
data.tar.gz: aaa9ae2aca771d382386706ada2cceb59171249e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dee305aad70a33dc38ac5f64e9ba51851298bb16e42d3be030b6827d14546bb951a492fcb0b93c98d342150b848a952191ce2019f9cd5f645c42e69c59d06cc
|
7
|
+
data.tar.gz: 41753b2edd992d33a8c330e75035deb733b514c16760bd7dd95b00f952230c3ff40a5d47d1975f185d48424dd93504977c8695d3e2197fee31cf643e4b5ce684
|
data/README.md
CHANGED
@@ -75,13 +75,9 @@ class Foo
|
|
75
75
|
logger.error "great error"
|
76
76
|
logger.warn "so warn"
|
77
77
|
logger.fatal "ooh fatal"
|
78
|
-
|
79
|
-
#
|
80
|
-
logger.metric({:name => "SomeMetricName", :unit => "Count", :value =>
|
81
|
-
|
82
|
-
# Notice that no :value key is specified, meaning we'll increment the last seen value
|
83
|
-
# If this metric hasn't been set within the last hour then we'll reset the value back to zero
|
84
|
-
logger.metric({:name => "SomeMetricName", :unit => "Count"})
|
78
|
+
|
79
|
+
# Without the CloudWatchDecorator the `metric` call is a no-op
|
80
|
+
logger.metric({:name => "SomeMetricName", :unit => "Count", :value => 1})
|
85
81
|
end
|
86
82
|
end
|
87
83
|
|
@@ -14,15 +14,17 @@ module Alephant
|
|
14
14
|
def metric(opts)
|
15
15
|
name, value, unit, dimensions = opts.values_at(:name, :value, :unit, :dimensions)
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
Thread.new do
|
18
|
+
cloudwatch.put_metric_data(
|
19
|
+
:namespace => namespace,
|
20
|
+
:metric_data => [{
|
21
|
+
:metric_name => name,
|
22
|
+
:value => value,
|
23
|
+
:unit => unit || "None",
|
24
|
+
:dimensions => parse(dimensions || {})
|
25
|
+
}]
|
26
|
+
)
|
27
|
+
end
|
26
28
|
end
|
27
29
|
|
28
30
|
# Ruby's Kernel implements a `warn` method
|
@@ -50,41 +52,6 @@ module Alephant
|
|
50
52
|
}
|
51
53
|
end
|
52
54
|
end
|
53
|
-
|
54
|
-
def determine(name, value)
|
55
|
-
value ? value : increment_metric_value(name)
|
56
|
-
end
|
57
|
-
|
58
|
-
def increment_metric_value(name)
|
59
|
-
stats = get_stats name
|
60
|
-
stats.datapoints.size == 0 ? 0 : stats.datapoints.last[:sum] += 1
|
61
|
-
end
|
62
|
-
|
63
|
-
def get_stats(name)
|
64
|
-
stats_for(filter_metric name).tap do |stats|
|
65
|
-
sort stats.datapoints if stats.datapoints.size > 0
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def filter_metric(name)
|
70
|
-
filter_namespace.filter("metric_name", name)
|
71
|
-
end
|
72
|
-
|
73
|
-
def filter_namespace
|
74
|
-
cloudwatch.metrics.filter("namespace", namespace)
|
75
|
-
end
|
76
|
-
|
77
|
-
def stats_for(metric)
|
78
|
-
metric.first.statistics({
|
79
|
-
:statistics => ["Sum"],
|
80
|
-
:start_time => Time.now - ONE_HOUR,
|
81
|
-
:end_time => Time.now
|
82
|
-
})
|
83
|
-
end
|
84
|
-
|
85
|
-
def sort(stats)
|
86
|
-
stats.sort! { |a, b| a[:timestamp] <=> b[:timestamp] }
|
87
|
-
end
|
88
55
|
end
|
89
56
|
end
|
90
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Kenny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|