better_fx 0.1.1 → 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 +11 -0
- data/better_fx.gemspec +6 -2
- data/lib/better_fx/client.rb +24 -1
- data/lib/better_fx/version.rb +4 -0
- data/spec/better_fx/client_spec.rb +55 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff923b091c09a0c2e4f23274f3d4189d32775e5c
|
4
|
+
data.tar.gz: 0c84f088ff4c5b4030a90ba2f7dce02065894ef3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b72084b4f6cffd71bb56240378ecf9dd187a9cae630491efff48a1b4f880a16b37a3fa857eac1dbecdeea59c5723aa75f991790949799259bbf349056cf41ec
|
7
|
+
data.tar.gz: d2ce91f3eced03a85f5995ac35963270619f0f02cfce94dbabc14adaef5b04e490fd1ec7a9b68d78490971dd9ae8850f2cc5cb6e2ce33917ea49cf2290b33ba4
|
data/README.md
CHANGED
@@ -13,6 +13,17 @@ bfx = BetterFx::Client.new
|
|
13
13
|
bfx.increment_counter :beans
|
14
14
|
```
|
15
15
|
|
16
|
+
Or you might want to report the value of a measurement you've taken
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
require "better_fx"
|
20
|
+
bfx = BetterFx::Client.new
|
21
|
+
# This will send the value 11 to the SignalFx gauge metric named
|
22
|
+
# "soccer_ball_air_pressure" with the current unix timestamp and vanilla
|
23
|
+
# metadata dimensions
|
24
|
+
bfx.gauge :soccer_ball_air_pressure, value: 11
|
25
|
+
```
|
26
|
+
|
16
27
|
## Configuration
|
17
28
|
|
18
29
|
To use BetterFx with the least amount of code, just set the environment variable
|
data/better_fx.gemspec
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "better_fx/version"
|
4
|
+
|
1
5
|
Gem::Specification.new do |s|
|
2
6
|
s.name = "better_fx"
|
3
|
-
s.version =
|
7
|
+
s.version = BetterFx::VERSION
|
8
|
+
s.date = BetterFx::VERSION_DATE
|
4
9
|
s.license = "MIT"
|
5
|
-
s.date = "2016-05-17"
|
6
10
|
s.summary = "A more idiomatic interface to SignalFx."
|
7
11
|
s.description = "A convenient gem for developers to interact with SignalFx with a trivial amount of effort"
|
8
12
|
s.authors = ["Courtland Caldwell"]
|
data/lib/better_fx/client.rb
CHANGED
@@ -15,7 +15,7 @@ module BetterFx
|
|
15
15
|
# @params dimensions [Array<Hash>] the metadata dimensions to be associated with the counter
|
16
16
|
def increment_counter(counter_name, value: 1, timestamp: nil, dimensions: [])
|
17
17
|
return unless configuration.supported_environments.include? configuration.current_environment
|
18
|
-
timestamp ||=
|
18
|
+
timestamp ||= default_timestamp
|
19
19
|
dimensions << { env: configuration.current_environment } if dimensions.empty?
|
20
20
|
signalfx_client.bf_xmit(counters: [
|
21
21
|
metric: counter_name.to_s,
|
@@ -25,8 +25,31 @@ module BetterFx
|
|
25
25
|
])
|
26
26
|
end
|
27
27
|
|
28
|
+
# Send a gauge measurement to SignalFx (if the current environment supports using SignalFx)
|
29
|
+
#
|
30
|
+
# @params gauge_name [Symbol, String] the name of the gauge to send a measurement of
|
31
|
+
# @params value [Fixnum] the measured value
|
32
|
+
# @params timestamp [Fixnum, String] the timestamp, in milliseconds since the unix epoch (defaults to the timestamp
|
33
|
+
# on the host running your code)
|
34
|
+
# @params dimensions [Array<Hash>] the metadata dimensions to be associated with the gauge measurement
|
35
|
+
def gauge(gauge_name, value: nil, timestamp: nil, dimensions: [])
|
36
|
+
return unless configuration.supported_environments.include? configuration.current_environment
|
37
|
+
timestamp ||= default_timestamp
|
38
|
+
dimensions << { env: configuration.current_environment } if dimensions.empty?
|
39
|
+
signalfx_client.bf_xmit(gauges: [
|
40
|
+
metric: gauge_name.to_s,
|
41
|
+
value: value,
|
42
|
+
timestamp: timestamp.to_s,
|
43
|
+
dimensions: dimensions,
|
44
|
+
])
|
45
|
+
end
|
46
|
+
|
28
47
|
private
|
29
48
|
|
49
|
+
def default_timestamp
|
50
|
+
1000 * Time.now.to_i
|
51
|
+
end
|
52
|
+
|
30
53
|
def signalfx_client
|
31
54
|
SignalFx.new configuration.signalfx_api_token
|
32
55
|
end
|
@@ -3,16 +3,64 @@ require "spec_helper"
|
|
3
3
|
describe BetterFx::Client do
|
4
4
|
subject { described_class.new }
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
let(:value) { 1 }
|
7
|
+
let(:timestamp) { 12_345 }
|
8
|
+
let(:dimensions) { [{ env: BetterFx.configuration.current_environment }] }
|
9
|
+
let(:mock_fx_client) { FxMocks::MockFxClient.new }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(SignalFx).to receive(:new).and_return mock_fx_client
|
13
|
+
end
|
11
14
|
|
12
|
-
|
13
|
-
|
15
|
+
describe "#gauge" do
|
16
|
+
it "sends the value to SignalFx for the specified gauge" do
|
17
|
+
expect(mock_fx_client).
|
18
|
+
to receive(:bf_xmit).
|
19
|
+
with(gauges: [
|
20
|
+
hash_including(
|
21
|
+
metric: "sample_gauge",
|
22
|
+
value: value
|
23
|
+
),
|
24
|
+
])
|
25
|
+
subject.gauge :sample_gauge, value: value
|
14
26
|
end
|
15
27
|
|
28
|
+
describe "specifying the timestamp" do
|
29
|
+
let(:timestamp) { 1111 }
|
30
|
+
it "sends the user specified timestamp as a string" do
|
31
|
+
expect(mock_fx_client).
|
32
|
+
to receive(:bf_xmit).
|
33
|
+
with(gauges: [
|
34
|
+
hash_including(
|
35
|
+
metric: "sample_gauge",
|
36
|
+
value: value,
|
37
|
+
timestamp: timestamp.to_s
|
38
|
+
),
|
39
|
+
])
|
40
|
+
|
41
|
+
subject.gauge :sample_gauge, value: value, timestamp: timestamp
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "specifying dimensional metadata" do
|
46
|
+
let(:dimensions) { [{ size: "Large" }] }
|
47
|
+
it "sends the user specified dimensional metadata" do
|
48
|
+
expect(mock_fx_client).
|
49
|
+
to receive(:bf_xmit).
|
50
|
+
with(gauges: [
|
51
|
+
hash_including(
|
52
|
+
metric: "sample_gauge",
|
53
|
+
value: value,
|
54
|
+
dimensions: dimensions
|
55
|
+
),
|
56
|
+
])
|
57
|
+
|
58
|
+
subject.gauge :sample_gauge, value: value, dimensions: dimensions
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "#increment_counter" do
|
16
64
|
it "sends the default incremental value to SignalFx for the specified counter" do
|
17
65
|
expect(mock_fx_client).
|
18
66
|
to receive(:bf_xmit).
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: better_fx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Courtland Caldwell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: signalfx
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- lib/better_fx.rb
|
111
111
|
- lib/better_fx/client.rb
|
112
112
|
- lib/better_fx/configuration.rb
|
113
|
+
- lib/better_fx/version.rb
|
113
114
|
- spec/better_fx/client_spec.rb
|
114
115
|
- spec/better_fx_spec.rb
|
115
116
|
- spec/simplecov_custom_profile.rb
|