atsd 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -2
- data/atsd.gemspec +2 -2
- data/lib/atsd/client.rb +40 -34
- data/lib/atsd/services/alerts_service.rb +1 -32
- data/lib/atsd/services/properties_service.rb +19 -13
- data/lib/atsd/services/series_service.rb +13 -2
- data/lib/atsd/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb6d450775a1e2535c2784af0377e160899f2bc1
|
4
|
+
data.tar.gz: a5b7413629c45872b82d571ac0c2608aedf0c525
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 634955edbc7dd7e51050591afac40796d24603be5a41aed533686e605ce466b7294dbfaef955d1e4e38080837e942ea073788befa777be88a3be98c7a57996d9
|
7
|
+
data.tar.gz: 4d0b69e1b4961a08cb69004797d6828d4819e2473c65ddaaeba6095d4c6a0698b3105d48e163bb99f70020a088ac479337ed4f2874638ea8d501698fcbf39fda
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
The ATSD Client for Ruby enables Ruby developers
|
4
4
|
to easily read and write statistics and metadata
|
5
|
-
from Axibase Time
|
5
|
+
from Axibase Time Series Database.
|
6
6
|
|
7
7
|
API documentation: https://github.com/axibase/atsd-docs/blob/master/api/README.md
|
8
8
|
|
@@ -251,6 +251,21 @@ Inserting CSV data from file:
|
|
251
251
|
series_service.csv_insert('sensor-1', File.read('/path/to/data.csv'), { :user => 'beta' })
|
252
252
|
```
|
253
253
|
|
254
|
+
Retrieving series values CSV and JSON format:
|
255
|
+
|
256
|
+
```ruby
|
257
|
+
series_service.url_query('json','nurswgvml007','cpu_busy', :startDate => 'previous_minute')
|
258
|
+
# => {"series"=>
|
259
|
+
# [{"entity"=>"nurswgvml007",
|
260
|
+
# "metric"=>"cpu_busy",
|
261
|
+
# "tags"=>{},
|
262
|
+
# "type"=>"HISTORY",
|
263
|
+
# "aggregate"=>{"type"=>"DETAIL"},
|
264
|
+
# "data"=>[{"t"=>1464688814000, "v"=>3.03}, {"t"=>1464688830000, "v"=>5}, {"t"=>1464688846000, "v"=>9}, {"t"=>1464688862000, "v"=>4.04}, {"t"=>1464688878000, "v"=>5.05}]}]}
|
265
|
+
series_service.url_query('csv','nurswgvml007','cpu_busy', :startDate => 'previous_minute')
|
266
|
+
=> "time,entity,metric,value\r\n1464688862000,nurswgvml007,cpu_busy,4.04\r\n1464688878000,nurswgvml007,cpu_busy,5.05\r\n1464688894000,nurswgvml007,cpu_busy,10.2\r\n1464688910000,nurswgvml007,cpu_busy,45.95\r\n1464688926000,nurswgvml007,cpu_busy,21.36\r\n1464688942000,nurswgvml007,cpu_busy,4.04\r\n"
|
267
|
+
```
|
268
|
+
|
254
269
|
#### Properties Service
|
255
270
|
|
256
271
|
```ruby
|
@@ -268,8 +283,22 @@ properties_service.query('sensor-1', 'sensor_type', :start_date => "2015-11-17T1
|
|
268
283
|
# :key=>{"id"=>"ch-15"}}]
|
269
284
|
|
270
285
|
properties_service.delete(property)
|
271
|
-
properties_service.query('sensor-1', 'sensor_type', :start_date =>
|
286
|
+
properties_service.query('sensor-1', 'sensor_type', :start_date => '2015-11-17T17:00:00Z').execute
|
272
287
|
# => []
|
288
|
+
|
289
|
+
properties_service.type_query('sensor-1')
|
290
|
+
# => ["com.axibase.config",
|
291
|
+
# "configuration",
|
292
|
+
# "cpu",
|
293
|
+
# "disk",
|
294
|
+
# "sw.vmw.vm",
|
295
|
+
# "system",
|
296
|
+
|
297
|
+
properties_service.url_query('nurswgvml007','network')
|
298
|
+
# => [{"type"=>"network", "entity"=>"nurswgvml007", "key"=>{"id"=>"eth1"}, "tags"=>{"network_i/o.read-kb/s"=>"261.9", "network_i/o.write-kb/s"=>"209.9", "network_packets.read/s"=>"354.4", "network_packets.write/s"=>"339.4"}, "timestamp"=>1464680627000},
|
299
|
+
# {"type"=>"network", "entity"=>"nurswgvml007", "key"=>{"id"=>"lo"}, "tags"=>{"network_i/o.read-kb/s"=>"2.7", "network_i/o.write-kb/s"=>"2.7", "network_packets.read/s"=>"6.7", "network_packets.write/s"=>"6.7"}, "timestamp"=>1464680627000}]
|
300
|
+
|
301
|
+
|
273
302
|
```
|
274
303
|
|
275
304
|
#### Alerts Service
|
data/atsd.gemspec
CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ['Axibase Corporation']
|
11
11
|
spec.email = ['atsd-api@axibase.com']
|
12
12
|
|
13
|
-
spec.summary = %q{Axibase Time
|
14
|
-
spec.description = %q{Axibase Time
|
13
|
+
spec.summary = %q{Axibase Time Series Database Client for Ruby.}
|
14
|
+
spec.description = %q{Axibase Time Series Database Client for Ruby is an easy-to-use client for interfacing with ATSD metadata and data REST API services.}
|
15
15
|
spec.homepage = 'https://github.com/axibase/atsd-api-ruby/'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
data/lib/atsd/client.rb
CHANGED
@@ -3,7 +3,7 @@ require 'active_support/core_ext/hash/keys'
|
|
3
3
|
|
4
4
|
module ATSD
|
5
5
|
|
6
|
-
# HTTP(S) Client for Axibase Time
|
6
|
+
# HTTP(S) Client for Axibase Time Series Database. Implements all REST methods
|
7
7
|
# of the API in a straightforward manner.
|
8
8
|
class Client
|
9
9
|
|
@@ -47,6 +47,21 @@ module ATSD
|
|
47
47
|
response.body
|
48
48
|
end
|
49
49
|
|
50
|
+
# Retrieve series values for the specified entity, metric, and optional series tags in CSV and JSON format
|
51
|
+
#
|
52
|
+
# @param [String] format
|
53
|
+
# @param [String] entity
|
54
|
+
# @param [String] metric
|
55
|
+
# @param [Hash] parameters other query parameters
|
56
|
+
# @return [Array<Hash>] time series
|
57
|
+
# @raise [APIError]
|
58
|
+
def series_url_query(format, entity, metric, parameters)
|
59
|
+
url = "series/#{format}/#{entity}/#{metric}?"
|
60
|
+
parameters.each { |k, v| url << "&#{k}=#{v}" }
|
61
|
+
response = @connection.get url
|
62
|
+
response.body
|
63
|
+
end
|
64
|
+
|
50
65
|
# Insert time series
|
51
66
|
#
|
52
67
|
# @param [Hash, Array<Hash>] series series or array of series
|
@@ -95,37 +110,27 @@ module ATSD
|
|
95
110
|
# @return [Array<Hash>] array of properties
|
96
111
|
# @raise [APIError]
|
97
112
|
def properties_for_entity_and_type(entity, type)
|
98
|
-
response = @connection.get "properties
|
113
|
+
response = @connection.get "properties/#{entity}/types/#{type}"
|
99
114
|
response.body
|
100
115
|
end
|
101
116
|
|
102
|
-
#
|
117
|
+
# Returns array of property types for the entity.
|
103
118
|
#
|
104
|
-
# @param [
|
105
|
-
# @return
|
119
|
+
# @param [String] type
|
120
|
+
# @return [Array<Hash>] array of properties
|
106
121
|
# @raise [APIError]
|
107
|
-
def
|
108
|
-
@connection.
|
109
|
-
|
122
|
+
def properties_for_entity(entity)
|
123
|
+
response = @connection.get "properties/#{entity}/types"
|
124
|
+
response.body
|
110
125
|
end
|
111
126
|
|
112
|
-
# Insert
|
127
|
+
# Insert properties
|
113
128
|
#
|
114
|
-
# @param [Hash, Array<Hash>]
|
115
|
-
# @param [Hash, Array<Hash>] delete delete an array of properties for entity,
|
116
|
-
# type, and optionally for specified keys
|
117
|
-
# @param [Hash, Array<Hash>] delete_matchers delete rows that partially match the specified key.
|
118
|
-
# 'createdBeforeTime’ specifies an optional time condition. The server should delete all keys
|
119
|
-
# that have been created before the specified time. 'createdBeforeTime’ is specified in unix
|
120
|
-
# milliseconds.
|
129
|
+
# @param [Hash, Array<Hash>] properties property or array of properties
|
121
130
|
# @return true
|
122
131
|
# @raise [APIError]
|
123
|
-
def
|
124
|
-
@connection.
|
125
|
-
{ :action => 'insert', :properties => Utils.ensure_array(insert) },
|
126
|
-
{ :action => 'delete', :properties => Utils.ensure_array(delete) },
|
127
|
-
{ :action => 'delete-match', :matchers => Utils.ensure_array(delete_matchers) }
|
128
|
-
].select { |action| (action[:properties] || action[:matchers]).count > 0 }
|
132
|
+
def properties_insert(properties)
|
133
|
+
@connection.post 'properties/insert', Utils.ensure_array(properties)
|
129
134
|
true
|
130
135
|
end
|
131
136
|
|
@@ -135,16 +140,7 @@ module ATSD
|
|
135
140
|
# @return true
|
136
141
|
# @raise [APIError]
|
137
142
|
def properties_delete(properties)
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
# Delete rows that partially match the specified key
|
142
|
-
#
|
143
|
-
# @param [Hash, Array<Hash>] matchers
|
144
|
-
# @return true
|
145
|
-
# @raise [APIError]
|
146
|
-
def properties_delete_match(matchers)
|
147
|
-
properties_batch [], [], matchers
|
143
|
+
@connection.post 'properties/delete', Utils.ensure_array(properties)
|
148
144
|
end
|
149
145
|
|
150
146
|
# Query alerts
|
@@ -157,13 +153,23 @@ module ATSD
|
|
157
153
|
response.body
|
158
154
|
end
|
159
155
|
|
160
|
-
# (De-)acknowledge
|
156
|
+
# (De-)acknowledge alerts
|
161
157
|
#
|
162
158
|
# @param [Hash, Array<Hash>] actions action or array of actions
|
163
159
|
# @return [true]
|
164
160
|
# @raise [APIError]
|
165
161
|
def alerts_update(actions)
|
166
|
-
@connection.
|
162
|
+
@connection.post 'alerts/update', Utils.ensure_array(actions)
|
163
|
+
true
|
164
|
+
end
|
165
|
+
|
166
|
+
# Delete alerts
|
167
|
+
#
|
168
|
+
# @param [Hash, Array<Hash>] actions action or array of actions
|
169
|
+
# @return [true]
|
170
|
+
# @raise [APIError]
|
171
|
+
def alerts_delete(actions)
|
172
|
+
@connection.post 'alerts/delete', Utils.ensure_array(actions)
|
167
173
|
true
|
168
174
|
end
|
169
175
|
|
@@ -16,24 +16,6 @@ module ATSD
|
|
16
16
|
query
|
17
17
|
end
|
18
18
|
|
19
|
-
# Acknowledge alerts
|
20
|
-
#
|
21
|
-
# @param [Array<Hash, Alert, Integer>, Hash, Alert, Integer] alerts
|
22
|
-
# @return [self]
|
23
|
-
# @raise [APIError]
|
24
|
-
def acknowledge(alerts)
|
25
|
-
alerts_acknowledge alerts, true
|
26
|
-
end
|
27
|
-
|
28
|
-
# De-acknowledge alerts
|
29
|
-
#
|
30
|
-
# @param [Array<Hash, Alert, Integer>, Hash, Alert, Integer] alerts
|
31
|
-
# @return [self]
|
32
|
-
# @raise [APIError]
|
33
|
-
def de_acknowledge(alerts)
|
34
|
-
alerts_acknowledge alerts, false
|
35
|
-
end
|
36
|
-
|
37
19
|
# Delete alerts
|
38
20
|
#
|
39
21
|
# @param [Array<Hash, Alert>, Hash, Alert] alerts
|
@@ -44,8 +26,7 @@ module ATSD
|
|
44
26
|
{ :id => id_for_alert(alert) }
|
45
27
|
end
|
46
28
|
return if alerts.count == 0
|
47
|
-
@client.
|
48
|
-
:alerts => alerts
|
29
|
+
@client.alerts_delete alerts
|
49
30
|
end
|
50
31
|
|
51
32
|
# Create query builder for alert history.
|
@@ -60,18 +41,6 @@ module ATSD
|
|
60
41
|
|
61
42
|
private
|
62
43
|
|
63
|
-
def alerts_acknowledge(alerts, acknowledge)
|
64
|
-
alerts = Utils.ensure_array(alerts).map do |alert|
|
65
|
-
alert[:acknowledged] = acknowledge if alert.is_a? Hash
|
66
|
-
{ :id => id_for_alert(alert) }
|
67
|
-
end
|
68
|
-
return if alerts.count == 0
|
69
|
-
@client.alerts_update :action => 'update',
|
70
|
-
:fields => {:acknowledge => acknowledge},
|
71
|
-
:alerts => alerts
|
72
|
-
self
|
73
|
-
end
|
74
|
-
|
75
44
|
def id_for_alert(alert)
|
76
45
|
case alert
|
77
46
|
when Integer
|
@@ -33,6 +33,25 @@ module ATSD
|
|
33
33
|
self
|
34
34
|
end
|
35
35
|
|
36
|
+
# Returns an array of property types for the entity.
|
37
|
+
#
|
38
|
+
# @param [String] entity
|
39
|
+
# @return [self]
|
40
|
+
# @raise [APIError]
|
41
|
+
def type_query(entity)
|
42
|
+
@client.properties_for_entity(entity)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Retrieve property records for the specified entity and type.
|
46
|
+
#
|
47
|
+
# @param [String] entity
|
48
|
+
# @param [String] type
|
49
|
+
# @return [self]
|
50
|
+
# @raise [APIError]
|
51
|
+
def url_query(entity, type)
|
52
|
+
@client.properties_for_entity_and_type(entity,type)
|
53
|
+
end
|
54
|
+
|
36
55
|
# Delete properties.
|
37
56
|
#
|
38
57
|
# @param [Array<Property, Hash>, Property, Hash] properties
|
@@ -46,18 +65,5 @@ module ATSD
|
|
46
65
|
@client.properties_delete(properties)
|
47
66
|
self
|
48
67
|
end
|
49
|
-
|
50
|
-
# Delete rows that partially match the specified key
|
51
|
-
#
|
52
|
-
# @param [Hash, Array<Hash>] matchers
|
53
|
-
# @return [self]
|
54
|
-
# @raise [APIError]
|
55
|
-
def delete_match(matchers)
|
56
|
-
matchers = Utils.ensure_array(matchers).map do |m|
|
57
|
-
m.camelize_keys
|
58
|
-
end
|
59
|
-
@client.properties_delete_match matchers
|
60
|
-
self
|
61
|
-
end
|
62
68
|
end
|
63
69
|
end
|
@@ -23,6 +23,17 @@ module ATSD
|
|
23
23
|
query
|
24
24
|
end
|
25
25
|
|
26
|
+
# Retrieve series values for the specified entity, metric, and optional series tags in CSV and JSON format.
|
27
|
+
#
|
28
|
+
# @param [String] format. Supported formats are csv and json
|
29
|
+
# @param [String] entity
|
30
|
+
# @param [String] metric
|
31
|
+
# @param [Hash] parameters other query parameters
|
32
|
+
# @return [Array<Hash>] time series
|
33
|
+
def url_query(format, entity, metric, parameters={})
|
34
|
+
@client.series_url_query(format, entity, metric, parameters)
|
35
|
+
end
|
36
|
+
|
26
37
|
# Insert time series.
|
27
38
|
#
|
28
39
|
# @param [Array<Series, Hash>, Series, Hash] series
|
@@ -59,9 +70,9 @@ module ATSD
|
|
59
70
|
# @param [String] payload Body - ready to be parsed by ATSD server
|
60
71
|
# @return [Faraday::Response]
|
61
72
|
# @raise [APIError]
|
62
|
-
def self.post_payload(config,payload)
|
73
|
+
def self.post_payload(config, payload)
|
63
74
|
url = config[:url]
|
64
|
-
login, password = config[:login],config[:password]
|
75
|
+
login, password = config[:login], config[:password]
|
65
76
|
|
66
77
|
@connection = Faraday.new url do |builder|
|
67
78
|
builder.headers['User-Agent'] = "ATSD Ruby Client v#{VERSION}"
|
data/lib/atsd/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atsd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Axibase Corporation
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -192,7 +192,7 @@ dependencies:
|
|
192
192
|
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '4.0'
|
195
|
-
description: Axibase Time
|
195
|
+
description: Axibase Time Series Database Client for Ruby is an easy-to-use client
|
196
196
|
for interfacing with ATSD metadata and data REST API services.
|
197
197
|
email:
|
198
198
|
- atsd-api@axibase.com
|
@@ -259,6 +259,6 @@ rubyforge_project:
|
|
259
259
|
rubygems_version: 2.6.4
|
260
260
|
signing_key:
|
261
261
|
specification_version: 4
|
262
|
-
summary: Axibase Time
|
262
|
+
summary: Axibase Time Series Database Client for Ruby.
|
263
263
|
test_files: []
|
264
264
|
has_rdoc:
|