mackerel-client 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -1
- data/VERSION +1 -1
- data/lib/mackerel/client.rb +11 -20
- 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: 2e799a9480a0e5d7aedac5bb1da46e437116d32b
|
4
|
+
data.tar.gz: 983fc43a29cf948e287fb3555cee7a4a7d53641d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5247a6aaf7aac23f618ae5ed85e9eb3d23efff0d746aa487dd6c907c9b86cd4b0b94d91f947d99f584f4147bc28b9aaeeed225f3cf2aefed134308c6bb67a93
|
7
|
+
data.tar.gz: 072e3ec8be41ec97f03a62e51f6bd8badc0b4d59df3180f2721eee3592f585f81d2508840b70973126b4596a7d4e5cdf834619afc9e71c52f100a8c1ad8e981f
|
data/README.md
CHANGED
@@ -1,7 +1,14 @@
|
|
1
|
-
# mackerel-client [![Build Status](https://travis-ci.org/mackerelio/mackerel-client-ruby.svg?branch=master)](https://travis-ci.org/mackerelio/mackerel-client-ruby)
|
1
|
+
# mackerel-client [![Build Status](https://travis-ci.org/mackerelio/mackerel-client-ruby.svg?branch=master)](https://travis-ci.org/mackerelio/mackerel-client-ruby) [![Gem Version](https://badge.fury.io/rb/mackerel-client.png)](http://badge.fury.io/rb/mackerel-client)
|
2
2
|
|
3
3
|
mackerel-client is a ruby library to access Mackerel (https://mackerel.io/). CLI tool `mkr` is also provided.
|
4
4
|
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
@mackerel = Mackerel::Client.new(:mackerel_api_key => "<Put your API key")
|
9
|
+
host = @mackerel.get_host("<hostId>")
|
10
|
+
```
|
11
|
+
|
5
12
|
# CLI
|
6
13
|
|
7
14
|
## Host
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/lib/mackerel/client.rb
CHANGED
@@ -16,14 +16,12 @@ module Mackerel
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def get_host(host_id)
|
19
|
-
client = http_client
|
20
|
-
|
21
19
|
response = client.get "/api/v0/hosts/#{host_id}" do |req|
|
22
20
|
req.headers['X-Api-Key'] = @api_key
|
23
21
|
end
|
24
22
|
|
25
23
|
unless response.success?
|
26
|
-
raise "GET /api/v0/hosts/#{host_id}
|
24
|
+
raise "GET /api/v0/hosts/#{host_id} failed: #{response.status}"
|
27
25
|
end
|
28
26
|
|
29
27
|
data = JSON.parse(response.body)
|
@@ -35,8 +33,6 @@ module Mackerel
|
|
35
33
|
raise "no such status: #{status}"
|
36
34
|
end
|
37
35
|
|
38
|
-
client = http_client
|
39
|
-
|
40
36
|
response = client.post "/api/v0/hosts/#{host_id}/status" do |req|
|
41
37
|
req.headers['X-Api-Key'] = @api_key
|
42
38
|
req.headers['Content-Type'] = 'application/json'
|
@@ -44,15 +40,13 @@ module Mackerel
|
|
44
40
|
end
|
45
41
|
|
46
42
|
unless response.success?
|
47
|
-
raise "POST /api/v0/hosts/#{host_id}/status
|
43
|
+
raise "POST /api/v0/hosts/#{host_id}/status failed: #{response.status}"
|
48
44
|
end
|
49
45
|
|
50
46
|
data = JSON.parse(response.body)
|
51
47
|
end
|
52
48
|
|
53
49
|
def retire_host(host_id)
|
54
|
-
client = http_client
|
55
|
-
|
56
50
|
response = client.post "/api/v0/hosts/#{host_id}/retire" do |req|
|
57
51
|
req.headers['X-Api-Key'] = @api_key
|
58
52
|
req.headers['Content-Type'] = 'application/json'
|
@@ -60,15 +54,13 @@ module Mackerel
|
|
60
54
|
end
|
61
55
|
|
62
56
|
unless response.success?
|
63
|
-
raise "POST /api/v0/hosts/#{host_id}/retire
|
57
|
+
raise "POST /api/v0/hosts/#{host_id}/retire failed: #{response.status}"
|
64
58
|
end
|
65
59
|
|
66
60
|
data = JSON.parse(response.body)
|
67
61
|
end
|
68
62
|
|
69
63
|
def post_metrics(metrics)
|
70
|
-
client = http_client
|
71
|
-
|
72
64
|
response = client.post '/api/v0/tsdb' do |req|
|
73
65
|
req.headers['X-Api-Key'] = @api_key
|
74
66
|
req.headers['Content-Type'] = 'application/json'
|
@@ -76,7 +68,7 @@ module Mackerel
|
|
76
68
|
end
|
77
69
|
|
78
70
|
unless response.success?
|
79
|
-
raise "POST /api/v0/tsdb
|
71
|
+
raise "POST /api/v0/tsdb failed: #{response.status}"
|
80
72
|
end
|
81
73
|
|
82
74
|
data = JSON.parse(response.body)
|
@@ -86,13 +78,12 @@ module Mackerel
|
|
86
78
|
query = (hostIds.map{ |hostId| "hostId=#{hostId}" } +
|
87
79
|
names.map{ |name| "name=#{name}" }).join('&')
|
88
80
|
|
89
|
-
client = http_client
|
90
81
|
response = client.get "/api/v0/tsdb/latest?#{query}" do |req|
|
91
82
|
req.headers['X-Api-Key'] = @api_key
|
92
83
|
end
|
93
84
|
|
94
85
|
unless response.success?
|
95
|
-
raise "/api/v0/tsdb/latest?#{query}
|
86
|
+
raise "/api/v0/tsdb/latest?#{query} failed: #{response.status}"
|
96
87
|
end
|
97
88
|
|
98
89
|
data = JSON.parse(response.body)
|
@@ -100,8 +91,6 @@ module Mackerel
|
|
100
91
|
end
|
101
92
|
|
102
93
|
def post_service_metrics(service_name, metrics)
|
103
|
-
client = http_client
|
104
|
-
|
105
94
|
response = client.post "/api/v0/services/#{service_name}/tsdb" do |req|
|
106
95
|
req.headers['X-Api-Key'] = @api_key
|
107
96
|
req.headers['Content-Type'] = 'application/json'
|
@@ -109,15 +98,13 @@ module Mackerel
|
|
109
98
|
end
|
110
99
|
|
111
100
|
unless response.success?
|
112
|
-
raise "POST /api/v0/services/#{service_name}/tsdb
|
101
|
+
raise "POST /api/v0/services/#{service_name}/tsdb failed: #{response.status}"
|
113
102
|
end
|
114
103
|
|
115
104
|
data = JSON.parse(response.body)
|
116
105
|
end
|
117
106
|
|
118
107
|
def get_hosts(opts = {})
|
119
|
-
client = http_client
|
120
|
-
|
121
108
|
response = client.get '/api/v0/hosts.json' do |req|
|
122
109
|
req.headers['X-Api-Key'] = @api_key
|
123
110
|
req.params['service'] = opts[:service] if opts[:service]
|
@@ -126,7 +113,7 @@ module Mackerel
|
|
126
113
|
end
|
127
114
|
|
128
115
|
unless response.success?
|
129
|
-
raise "GET /api/v0/hosts.json
|
116
|
+
raise "GET /api/v0/hosts.json failed: #{response.status}"
|
130
117
|
end
|
131
118
|
|
132
119
|
data = JSON.parse(response.body)
|
@@ -135,6 +122,10 @@ module Mackerel
|
|
135
122
|
|
136
123
|
private
|
137
124
|
|
125
|
+
def client
|
126
|
+
@client ||= http_client
|
127
|
+
end
|
128
|
+
|
138
129
|
def http_client
|
139
130
|
Faraday.new(:url => @origin) do |faraday|
|
140
131
|
faraday.response :logger if ENV['DEBUG']
|
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.6
|
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:
|
11
|
+
date: 2015-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|