atsd 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +32 -43
- data/lib/atsd/client.rb +6 -6
- data/lib/atsd/models/base_model.rb +4 -4
- data/lib/atsd/models/series.rb +9 -13
- data/lib/atsd/queries/alerts_history_query.rb +5 -5
- data/lib/atsd/queries/base_query.rb +3 -3
- data/lib/atsd/queries/properties_query.rb +5 -5
- data/lib/atsd/queries/series_query.rb +2 -2
- data/lib/atsd/services/entities_service.rb +4 -4
- data/lib/atsd/services/series_service.rb +4 -4
- data/lib/atsd/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0166a8f99dff59d83cfb254463d9bdbacb48281
|
4
|
+
data.tar.gz: ffd582313131f72cfbdbe783445d2d3dd559f7bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7971fd36026b618b11c71648d286fe90b945f66ed50fe86fa7cc22322ebd865dcaebc7067211b0b57a5aedced796908b259a838d040e3aa7b7c20b1924858a53
|
7
|
+
data.tar.gz: 2e23baf470fc966dc4876716dd9cbacdda922cc2ecc3344b0e9d34caec287c3b2240eeebd34cce58b3a941c03c4bc6107f784e3dc282c5dd4af0babdff651d66
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# Axibase Time
|
1
|
+
# Axibase Time Series Database Client for Ruby
|
2
2
|
|
3
3
|
The ATSD Client for Ruby enables Ruby developers
|
4
4
|
to easily read and write statistics and metadata
|
5
5
|
from Axibase Time-Series Database.
|
6
6
|
|
7
|
-
API documentation: https://
|
7
|
+
API documentation: https://github.com/axibase/atsd-docs/blob/master/api/README.md
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -120,8 +120,8 @@ Basic query:
|
|
120
120
|
require 'time'
|
121
121
|
series_service = atsd.series_service
|
122
122
|
# => #<ATSD::SeriesService:0x007f82a4446c08
|
123
|
-
query = series_service.query('sensor-1', 'temperature',
|
124
|
-
# => {:entity=>"sensor-1", :metric=>"temperature", :
|
123
|
+
query = series_service.query('sensor-1', 'temperature', "2015-11-17T12:00:00Z", "2015-11-17T19:00:00Z")
|
124
|
+
# => {:entity=>"sensor-1", :metric=>"temperature", :start_date=>"2015-11-17T12:00:00Z", :end_date=>"2015-11-17T19:00:00Z"}
|
125
125
|
|
126
126
|
query.class
|
127
127
|
# => ATSD::SeriesQuery
|
@@ -169,11 +169,11 @@ Query with Versions:
|
|
169
169
|
```ruby
|
170
170
|
query = atsd.series_service.query("sensor-2", "pressure", Time.parse("2015-11-17T12:00:00Z"), Time.parse("2015-11-17T19:00:00Z"), {:versioned => true})
|
171
171
|
query.execute
|
172
|
-
template = "%
|
173
|
-
output = sprintf(template, "
|
172
|
+
template = "%24s, %13s, %24s, %17s, %17s\n"
|
173
|
+
output = sprintf(template, "sample_date", "sample_value", "version_date", "version_source", "version_status")
|
174
174
|
query.result.each do |data|
|
175
|
-
samples = data.data.sort_by{|sample| sample["version"]["
|
176
|
-
samples.each {|sample| output << sprintf(template,
|
175
|
+
samples = data.data.sort_by{|sample| sample["version"]["d"]}
|
176
|
+
samples.each {|sample| output << sprintf(template, sample["d"], sample["v"], sample["version"]["d"], sample["version"]["source"], sample["version"]["status"]) }
|
177
177
|
end
|
178
178
|
puts output
|
179
179
|
sample_time, sample_value, version_time, version_source, version_status
|
@@ -205,7 +205,7 @@ Inserting series:
|
|
205
205
|
s = Series.new
|
206
206
|
s.entity = 'sensor-1'
|
207
207
|
s.metric = 'temperature'
|
208
|
-
s.data = [ {
|
208
|
+
s.data = [ {d: Time.now.iso8601, v: 22} ]
|
209
209
|
atsd.series_service.insert(s)
|
210
210
|
```
|
211
211
|
|
@@ -215,7 +215,7 @@ Inserting series using Sample class:
|
|
215
215
|
s = Series.new
|
216
216
|
s.entity = 'sensor-1'
|
217
217
|
s.metric = 'pressure'
|
218
|
-
sample = Sample.new :
|
218
|
+
sample = Sample.new :date => "2015-11-17T17:00:00Z", :value => 7, :version => {:status => "normal", :source => "gateway-1"}
|
219
219
|
s.data = [ sample ]
|
220
220
|
series_service.insert(s)
|
221
221
|
```
|
@@ -223,8 +223,8 @@ series_service.insert(s)
|
|
223
223
|
Inserting Series with Versions:
|
224
224
|
|
225
225
|
```ruby
|
226
|
-
sample_1 = Sample.new :
|
227
|
-
sample_2 = Sample.new :
|
226
|
+
sample_1 = Sample.new :date => Time.parse("2015-11-17T17:00:00Z"), :value => 7, :version => {:status => "normal", :source => "gateway-1"}
|
227
|
+
sample_2 = Sample.new :date => Time.parse("2015-11-17T18:00:00Z"), :value => 17, :version => {:status => "error", :source => "gateway-1"}
|
228
228
|
series = Series.new :entity => "sensor-1", :metric => "pressure", :data => [sample_1, sample_2]
|
229
229
|
atsd.series_service.insert(series)
|
230
230
|
```
|
@@ -257,22 +257,18 @@ series_service.csv_insert('sensor-1', File.read('/path/to/data.csv'), { :user =>
|
|
257
257
|
properties_service = atsd.properties_service
|
258
258
|
# => #<ATSD::PropertiesService:0x007f82a456e6f8
|
259
259
|
|
260
|
-
property = Property.new
|
261
|
-
property.entity = 'sensor-1'
|
262
|
-
property.type = 'sensor_type'
|
263
|
-
property.tags = {"location":"NUR","site":"building-1"}
|
264
|
-
property.keys = {"id": "ch-15"}
|
260
|
+
property = Property.new :entity => 'sensor-1', :type => 'sensor_type', :tags => {"location":"NUR","site":"building-1"}, :key => {"id": "ch-15"}
|
265
261
|
properties_service.insert(property)
|
266
262
|
|
267
|
-
properties_service.query('sensor-1', 'sensor_type').execute
|
263
|
+
properties_service.query('sensor-1', 'sensor_type', :start_date => "2015-11-17T17:00:00Z").execute
|
268
264
|
# => [{:type=>"sensor_type",
|
269
265
|
# :entity=>"sensor-1",
|
270
266
|
# :tags=>{"location"=>"NUR", "site"=>"building-1"},
|
271
|
-
# :
|
272
|
-
# :
|
267
|
+
# :d=>"2016-05-30T12:16:31Z",
|
268
|
+
# :key=>{"id"=>"ch-15"}}]
|
273
269
|
|
274
270
|
properties_service.delete(property)
|
275
|
-
properties_service.query('sensor-1', 'sensor_type').execute
|
271
|
+
properties_service.query('sensor-1', 'sensor_type', :start_date => "2015-11-17T17:00:00Z").execute
|
276
272
|
# => []
|
277
273
|
```
|
278
274
|
|
@@ -282,28 +278,21 @@ properties_service.query('sensor-1', 'sensor_type').execute
|
|
282
278
|
alerts_service = atsd.alerts_service
|
283
279
|
# => #<ATSD::AlertsService:0x007faf7c0efdc0
|
284
280
|
|
281
|
+
alerts_service.query(:entity => "sensor-1", :metrics => ["meminfo.active"], :start_date => "2015-11-17T17:00:00Z").execute
|
285
282
|
alerts_service.query.execute
|
286
|
-
# => [{
|
287
|
-
#
|
288
|
-
#
|
289
|
-
#
|
290
|
-
#
|
291
|
-
#
|
292
|
-
#
|
293
|
-
#
|
294
|
-
#
|
295
|
-
#
|
296
|
-
#
|
297
|
-
#
|
298
|
-
#
|
299
|
-
# {:value=>447660.0,
|
300
|
-
# :id=>6,
|
301
|
-
# :text_value=>"447660",
|
302
|
-
# :tags=>{},
|
303
|
-
# :metric=>"meminfo.active",
|
304
|
-
# :entity=>"sensor-1",
|
305
|
-
# :severity=>3,
|
306
|
-
# ...
|
283
|
+
# => [{"entity"=>"sensor-1",
|
284
|
+
# "tags"=>{},
|
285
|
+
# "repeatCount"=>79,
|
286
|
+
# "textValue"=>"21.9",
|
287
|
+
# "metric"=>"meminfo.active",
|
288
|
+
# "severity"=>3,
|
289
|
+
# "rule"=>"memory info",
|
290
|
+
# "openDate"=>"2016-05-30T12:33:07Z",
|
291
|
+
# "lastEventDate"=>"2016-05-30T13:52:11Z",
|
292
|
+
# "acknowledged"=>false,
|
293
|
+
# "openValue"=>100.0,
|
294
|
+
# :v=>21.9,
|
295
|
+
# "id"=>8}]
|
307
296
|
```
|
308
297
|
#### Metrics Service
|
309
298
|
|
@@ -311,7 +300,7 @@ alerts_service.query.execute
|
|
311
300
|
metrics_service = atsd.metrics_service
|
312
301
|
# => #<ATSD::MetricsService:0x007fbb548d9548
|
313
302
|
|
314
|
-
metrics_service.list
|
303
|
+
metrics_service.list(:limit => 10)
|
315
304
|
# => [{:name=>"activemq_metrics_count",
|
316
305
|
# :enabled=>true,
|
317
306
|
# :data_type=>"FLOAT",
|
data/lib/atsd/client.rb
CHANGED
@@ -43,8 +43,8 @@ module ATSD
|
|
43
43
|
# @return [Array<Hash>] time series
|
44
44
|
# @raise [APIError]
|
45
45
|
def series_query(queries)
|
46
|
-
response = @connection.post 'series',
|
47
|
-
response.body
|
46
|
+
response = @connection.post 'series/query', Utils.ensure_array(queries)
|
47
|
+
response.body
|
48
48
|
end
|
49
49
|
|
50
50
|
# Insert time series
|
@@ -84,7 +84,7 @@ module ATSD
|
|
84
84
|
# @return [Array<Hash>] array of properties
|
85
85
|
# @raise [APIError]
|
86
86
|
def properties_query(queries = nil)
|
87
|
-
response = @connection.post 'properties',
|
87
|
+
response = @connection.post 'properties/query', Utils.ensure_array(queries)
|
88
88
|
response.body
|
89
89
|
end
|
90
90
|
|
@@ -95,7 +95,7 @@ module ATSD
|
|
95
95
|
# @return [Array<Hash>] array of properties
|
96
96
|
# @raise [APIError]
|
97
97
|
def properties_for_entity_and_type(entity, type)
|
98
|
-
response = @connection.get "properties/#{entity}/types#{type}"
|
98
|
+
response = @connection.get "properties/query/#{entity}/types#{type}"
|
99
99
|
response.body
|
100
100
|
end
|
101
101
|
|
@@ -153,7 +153,7 @@ module ATSD
|
|
153
153
|
# @return [Array<Hash>] alerts
|
154
154
|
# @raise [APIError]
|
155
155
|
def alerts_query(queries = nil)
|
156
|
-
response = @connection.post 'alerts',
|
156
|
+
response = @connection.post 'alerts/query', Utils.ensure_array(queries)
|
157
157
|
response.body
|
158
158
|
end
|
159
159
|
|
@@ -173,7 +173,7 @@ module ATSD
|
|
173
173
|
# @return [Array<Hash>] history records
|
174
174
|
# @raise [APIError]
|
175
175
|
def alerts_history_query(queries = nil)
|
176
|
-
response = @connection.post 'alerts/history',
|
176
|
+
response = @connection.post 'alerts/history/query', Utils.ensure_array(queries)
|
177
177
|
response.body
|
178
178
|
end
|
179
179
|
|
@@ -24,13 +24,13 @@ module ATSD
|
|
24
24
|
# Converts time and value keys as t and v respectively
|
25
25
|
# for the rest operates as a superclass method
|
26
26
|
def []=(key,value)
|
27
|
-
if key.to_s == '
|
28
|
-
key = :
|
27
|
+
if key.to_s == 'date'
|
28
|
+
key = :d
|
29
29
|
case value
|
30
30
|
when Time
|
31
|
-
value = value.
|
31
|
+
value = value.iso8601
|
32
32
|
else
|
33
|
-
value = value
|
33
|
+
value = value
|
34
34
|
end
|
35
35
|
end
|
36
36
|
key = :v if key.to_s == 'value'
|
data/lib/atsd/models/series.rb
CHANGED
@@ -7,24 +7,20 @@ module ATSD
|
|
7
7
|
|
8
8
|
class Sample < BaseModel
|
9
9
|
|
10
|
-
def
|
11
|
-
self[
|
12
|
-
end
|
13
|
-
|
14
|
-
def get_time()
|
15
|
-
self.send("t")
|
10
|
+
def set_date(date)
|
11
|
+
self['d'] = date
|
16
12
|
end
|
17
13
|
|
18
14
|
def get_date()
|
19
|
-
|
15
|
+
self.send('d')
|
20
16
|
end
|
21
17
|
|
22
18
|
def set_value(value)
|
23
|
-
self[
|
19
|
+
self['v'] = value
|
24
20
|
end
|
25
21
|
|
26
22
|
def get_value()
|
27
|
-
self.send(
|
23
|
+
self.send('v')
|
28
24
|
end
|
29
25
|
|
30
26
|
end
|
@@ -32,19 +28,19 @@ module ATSD
|
|
32
28
|
class Version < BaseModel
|
33
29
|
|
34
30
|
def set_source(source)
|
35
|
-
self[
|
31
|
+
self['source'] = source
|
36
32
|
end
|
37
33
|
|
38
34
|
def get_source()
|
39
|
-
self.send(
|
35
|
+
self.send('source')
|
40
36
|
end
|
41
37
|
|
42
38
|
def set_status(status)
|
43
|
-
self[
|
39
|
+
self['status'] = status
|
44
40
|
end
|
45
41
|
|
46
42
|
def get_status()
|
47
|
-
self.send(
|
43
|
+
self.send('status')
|
48
44
|
end
|
49
45
|
end
|
50
46
|
end
|
@@ -4,17 +4,17 @@ module ATSD
|
|
4
4
|
# Class for building and executing Alerts History Query
|
5
5
|
# @see https://axibase.com/atsd/api/#alerts:-history-query
|
6
6
|
class AlertsHistoryQuery < BaseQuery
|
7
|
-
|
7
|
+
TO_ISO_LAMBDA = ->(v) do
|
8
8
|
case v
|
9
9
|
when Time
|
10
|
-
v.
|
10
|
+
v.iso8601
|
11
11
|
else
|
12
|
-
v
|
12
|
+
v
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
coerce_key :
|
17
|
-
coerce_key :
|
16
|
+
coerce_key :end_date, TO_ISO_LAMBDA
|
17
|
+
coerce_key :start_date, TO_ISO_LAMBDA
|
18
18
|
|
19
19
|
# @return [Array<AlertHistory>]
|
20
20
|
def result
|
@@ -18,12 +18,12 @@ module ATSD
|
|
18
18
|
# @param [String] type see {Type} for possible values
|
19
19
|
# @return [self]
|
20
20
|
|
21
|
-
|
21
|
+
TO_ISO_LAMBDA = ->(v) do
|
22
22
|
case v
|
23
23
|
when Time
|
24
|
-
v.
|
24
|
+
v.iso8601
|
25
25
|
else
|
26
|
-
v
|
26
|
+
v
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -4,17 +4,17 @@ module ATSD
|
|
4
4
|
# Class for building and executing Properties Query
|
5
5
|
# @see https://axibase.com/atsd/api/#properties:-query
|
6
6
|
class PropertiesQuery < BaseQuery
|
7
|
-
|
7
|
+
TO_ISO_LAMBDA = ->(v) do
|
8
8
|
case v
|
9
9
|
when Time
|
10
|
-
v.
|
10
|
+
v.iso8601
|
11
11
|
else
|
12
|
-
v
|
12
|
+
v
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
coerce_key :
|
17
|
-
coerce_key :
|
16
|
+
coerce_key :end_date, TO_ISO_LAMBDA
|
17
|
+
coerce_key :start_date, TO_ISO_LAMBDA
|
18
18
|
|
19
19
|
# @return [Array<Property>]
|
20
20
|
def result
|
@@ -5,8 +5,8 @@ module ATSD
|
|
5
5
|
# @see https://axibase.com/atsd/api/#series:-query
|
6
6
|
class SeriesQuery < BaseQuery
|
7
7
|
|
8
|
-
coerce_key :
|
9
|
-
coerce_key :
|
8
|
+
coerce_key :end_date, TO_ISO_LAMBDA
|
9
|
+
coerce_key :start_date, TO_ISO_LAMBDA
|
10
10
|
|
11
11
|
# @return [Array<Series>]
|
12
12
|
def result
|
@@ -82,13 +82,13 @@ module ATSD
|
|
82
82
|
# Returns an array of property types for the entity.
|
83
83
|
#
|
84
84
|
# @param [String, Hash, Entity] entity
|
85
|
-
# @param [Integer, Time]
|
85
|
+
# @param [Integer, Time] start_date
|
86
86
|
# Return only property types that have been collected after the specified time.
|
87
87
|
# @return [Array<String>]
|
88
88
|
# @raise [APIError]
|
89
|
-
def property_types(entity,
|
90
|
-
|
91
|
-
params =
|
89
|
+
def property_types(entity, start_date = nil)
|
90
|
+
start_date = start_date.iso8601 if start_date.is_a? Time
|
91
|
+
params = start_date ? { :start_date => start_date } : {}
|
92
92
|
@client.entities_property_types(name_for_entity(entity), params)
|
93
93
|
end
|
94
94
|
|
@@ -10,15 +10,15 @@ module ATSD
|
|
10
10
|
#
|
11
11
|
# @param [String, Entity] entity
|
12
12
|
# @param [String, Metric] metric
|
13
|
-
# @param [
|
14
|
-
# @param [
|
13
|
+
# @param [String] start_date
|
14
|
+
# @param [String] end_date
|
15
15
|
# @param [Hash] options other query parameters
|
16
16
|
# @return [SeriesQuery]
|
17
|
-
def query(entity, metric,
|
17
|
+
def query(entity, metric, start_date, end_date, options = {})
|
18
18
|
query = SeriesQuery.new @client
|
19
19
|
entity = entity.name if entity.is_a? Entity
|
20
20
|
metric = metric.name if metric.is_a? Metric
|
21
|
-
options.merge! entity: entity, metric: metric,
|
21
|
+
options.merge! entity: entity, metric: metric, start_date: start_date, end_date: end_date
|
22
22
|
options.each { |option, value| query[option] = value }
|
23
23
|
query
|
24
24
|
end
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Axibase Corporation
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -256,7 +256,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
256
256
|
version: '0'
|
257
257
|
requirements: []
|
258
258
|
rubyforge_project:
|
259
|
-
rubygems_version: 2.4
|
259
|
+
rubygems_version: 2.6.4
|
260
260
|
signing_key:
|
261
261
|
specification_version: 4
|
262
262
|
summary: Axibase Time-Series Database Client for Ruby.
|