mackerel-client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/mackerel/client.rb +16 -0
- data/spec/mackerel/client_spec.rb +39 -0
- 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: 91ab71f2c21720288ec7c6c1d44079f4d98326d5
|
4
|
+
data.tar.gz: 3e6e4f6bc08ad6c72949538141eacf94d16407d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd2297ae218d4c491c51c0a82e5985aa7f7674b0bed2d22ed0246f919155d0e96a8a6fca22b31fc4f81bf49be10057c992988e27543521a1a765f2e874e0292c
|
7
|
+
data.tar.gz: 98363c727e49f46c2250dc30ab730fb53d852eb150c5342cf590697cf91709f4daab37360fa0427cf2e8f725ebfe5db5b2e6878c7ad6adf5d2c6f7e589d5e926
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/mackerel/client.rb
CHANGED
@@ -80,6 +80,22 @@ module Mackerel
|
|
80
80
|
data = JSON.parse(response.body)
|
81
81
|
end
|
82
82
|
|
83
|
+
def post_service_metrics(service_name, metrics)
|
84
|
+
client = http_client
|
85
|
+
|
86
|
+
response = client.post "/api/v0/services/#{service_name}/tsdb" do |req|
|
87
|
+
req.headers['X-Api-Key'] = @api_key
|
88
|
+
req.headers['Content-Type'] = 'application/json'
|
89
|
+
req.body = metrics.to_json
|
90
|
+
end
|
91
|
+
|
92
|
+
unless response.success?
|
93
|
+
raise "POST /api/v0/services/#{service_name}/tsdb faild: #{response.status}"
|
94
|
+
end
|
95
|
+
|
96
|
+
data = JSON.parse(response.body)
|
97
|
+
end
|
98
|
+
|
83
99
|
def get_hosts(opts = {})
|
84
100
|
client = http_client
|
85
101
|
|
@@ -168,6 +168,45 @@ describe Mackerel::Client do
|
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
171
|
+
describe '#post_service_metrics' do
|
172
|
+
let(:stubbed_response) {
|
173
|
+
[
|
174
|
+
200,
|
175
|
+
{},
|
176
|
+
JSON.dump(response_object)
|
177
|
+
]
|
178
|
+
}
|
179
|
+
|
180
|
+
let(:test_client) {
|
181
|
+
Faraday.new do |builder|
|
182
|
+
builder.adapter :test do |stubs|
|
183
|
+
stubs.post(api_path) { stubbed_response }
|
184
|
+
end
|
185
|
+
end
|
186
|
+
}
|
187
|
+
|
188
|
+
let(:service_name) { 'service_name' }
|
189
|
+
|
190
|
+
let(:api_path) { "/api/v0/services/#{service_name}/tsdb" }
|
191
|
+
|
192
|
+
let(:response_object) {
|
193
|
+
{ 'success' => true }
|
194
|
+
}
|
195
|
+
|
196
|
+
let(:metrics) { [
|
197
|
+
{ 'name' => 'custom.metrics.latency', 'time' => 1401537844, 'value' => 0.5 },
|
198
|
+
{ 'name' => 'custom.metrics.uptime', 'time' => 1401537844, 'value' => 500 },
|
199
|
+
] }
|
200
|
+
|
201
|
+
before do
|
202
|
+
allow(client).to receive(:http_client).and_return(test_client)
|
203
|
+
end
|
204
|
+
|
205
|
+
it "successfully post metrics" do
|
206
|
+
expect(client.post_service_metrics(service_name, metrics)).to eq(response_object)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
171
210
|
describe '#get_hosts' do
|
172
211
|
let(:stubbed_response) {
|
173
212
|
[
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mackerel-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mackerel developer team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|