latias-influxdb 0.2.1 → 1.1.1
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 +143 -21
- data/lib/latias/influxdb.rb +2 -0
- data/lib/latias/influxdb/action_bucket/base.rb +50 -0
- data/lib/latias/influxdb/bucket.rb +17 -38
- data/lib/latias/influxdb/configuration.rb +8 -3
- data/lib/latias/influxdb/version.rb +1 -1
- data/lib/rails/generators/latias/influxdb/install_generator.rb +19 -0
- data/lib/rails/generators/latias/influxdb/templates/initializer.rb +7 -1
- metadata +11 -18
- data/app/assets/config/latias_influxdb_manifest.js +0 -1
- data/app/assets/stylesheets/latias/influxdb/application.css +0 -15
- data/app/controllers/latias/influxdb/application_controller.rb +0 -6
- data/app/helpers/latias/influxdb/application_helper.rb +0 -6
- data/app/jobs/latias/influxdb/application_job.rb +0 -6
- data/app/mailers/latias/influxdb/application_mailer.rb +0 -8
- data/app/models/latias/influxdb/application_record.rb +0 -7
- data/app/views/layouts/latias/influxdb/application.html.erb +0 -15
- data/lib/rails/generators/latias/influxdb/influxdb_generator.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc3e3a6225c4dcd1014d3fa9e7f6dfea88c06d67a29e0e0b2f9ae251e69891d6
|
4
|
+
data.tar.gz: 5dbc46576db10856c87812309fa326bf9b4c35d9fa079b194a0393ece51412a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c398d6da63502e753d75a273cf50d1961a50fecc38ca6616c96133accea9e585d78b7af8ec050d9dfc440b9214b42d35c056937d8710208e1935e196d08c5a2
|
7
|
+
data.tar.gz: e2693590650f6cffb0548c155c2d00175bf85b9db023b34714cca5211d98e26d370b110011532420b41678bd8db5f328c1e363f36081c3c46b9158590347e58b
|
data/README.md
CHANGED
@@ -2,12 +2,81 @@
|
|
2
2
|
|
3
3
|
Ruby lib for use influxdb version 2 on Ruby language
|
4
4
|
|
5
|
-
##
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'latias-influxdb'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
$ gem install latias-influxdb
|
23
|
+
```
|
24
|
+
|
25
|
+
Check version
|
26
|
+
|
27
|
+
```bash
|
28
|
+
rails latias:influxdb:verion
|
29
|
+
```
|
30
|
+
|
31
|
+
## Configuration & Usage
|
32
|
+
|
33
|
+
### Configuration
|
34
|
+
|
35
|
+
First generating config file
|
36
|
+
|
37
|
+
```bash
|
38
|
+
rails g latias:influxdb:install
|
39
|
+
```
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
# config/initializers/latias_influxdb
|
43
|
+
Latias::Influxdb.configure do |config|
|
44
|
+
# default
|
45
|
+
# config.url = 'http://localhost:8086'
|
46
|
+
# config.token = 'token'
|
47
|
+
# config.bucket = 'bucket'
|
48
|
+
# config.org = 'org'
|
49
|
+
# config.use_ssl = false
|
50
|
+
# config.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
### Usage
|
55
|
+
|
56
|
+
You can use
|
57
|
+
|
58
|
+
<!--
|
59
|
+
|
60
|
+
# config.url = 'http://188.166.252.165:8086'
|
61
|
+
# config.token = 'YyD4UGu4_Xn0CIVsycFdjaQVd7m1g5wRp0z2BCfBSyNL6-GHqqyZRePGy46B2m8Zg6jgqHAN_J6jyhCmvGeQRA=='
|
62
|
+
# config.bucket = 'MDBEnergy'
|
63
|
+
# config.org = 'MDBEnergy'
|
64
|
+
|
65
|
+
-->
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
bucket = Latias::Influxdb::Bucket.new
|
69
|
+
bucket.client_connection
|
70
|
+
# or bucket = Latias::Influxdb::Bucket.new.client_connection
|
71
|
+
bucket.range('start: -1m').filter('fn: (r) => r["_measurement"] == "cpu"')
|
72
|
+
bucket.call
|
73
|
+
```
|
74
|
+
|
75
|
+
Or use with model
|
6
76
|
|
7
77
|
<!-- ```ruby
|
8
78
|
class MdbEnergyBucket < Latias::Influxdb::Bucket
|
9
79
|
def initialize
|
10
|
-
super
|
11
80
|
@url = 'http://188.166.252.165:8086'
|
12
81
|
@token = 'YyD4UGu4_Xn0CIVsycFdjaQVd7m1g5wRp0z2BCfBSyNL6-GHqqyZRePGy46B2m8Zg6jgqHAN_J6jyhCmvGeQRA=='
|
13
82
|
@bucket = 'MDBEnergy'
|
@@ -25,7 +94,6 @@ mdb_energy_bucket.call
|
|
25
94
|
```ruby
|
26
95
|
class MdbEnergyBucket < Latias::Influxdb::Bucket
|
27
96
|
def initialize
|
28
|
-
super
|
29
97
|
@url = 'http://localhost:8086'
|
30
98
|
@token = 'your token'
|
31
99
|
@bucket = 'MDBEnergy'
|
@@ -40,36 +108,90 @@ mdb_energy_bucket.range('start: -1m').filter('fn: (r) => r["_measurement"] == "c
|
|
40
108
|
mdb_energy_bucket.call
|
41
109
|
```
|
42
110
|
|
43
|
-
|
44
|
-
|
45
|
-
Add this line to your application's Gemfile:
|
111
|
+
And you can add methods in model
|
46
112
|
|
47
113
|
```ruby
|
48
|
-
gem 'latias-influxdb'
|
49
|
-
```
|
50
114
|
|
51
|
-
|
115
|
+
class MdbEnergyBucket < Latias::Influxdb::Bucket
|
116
|
+
def initialize
|
117
|
+
@url = 'http://localhost:8086'
|
118
|
+
@token = 'your token'
|
119
|
+
@bucket = 'MDBEnergy'
|
120
|
+
@org = 'MDBEnergy'
|
121
|
+
@use_ssl = false
|
122
|
+
client_connection
|
123
|
+
end
|
52
124
|
|
53
|
-
|
54
|
-
|
55
|
-
|
125
|
+
def one_minute_before
|
126
|
+
range('start: -1m')
|
127
|
+
end
|
56
128
|
|
57
|
-
|
129
|
+
def find_cpu
|
130
|
+
filter('fn: (r) => r["_measurement"] == "cpu"')
|
131
|
+
end
|
58
132
|
|
59
|
-
|
60
|
-
|
133
|
+
def my_cpu_value
|
134
|
+
one_minute_before.find_cpu.call
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
mdb_energy_bucket = MdbEnergyBucket.new
|
139
|
+
mdb_energy_bucket.one_minute_before.find_cpu.call
|
140
|
+
# OR
|
141
|
+
mdb_energy_bucket.my_cpu_value
|
61
142
|
```
|
62
143
|
|
63
|
-
|
144
|
+
## Method
|
64
145
|
|
65
|
-
```
|
66
|
-
|
67
|
-
|
146
|
+
```ruby
|
147
|
+
def yield(query)
|
148
|
+
merge_query('yield', query)
|
149
|
+
end
|
150
|
+
|
151
|
+
def range(query)
|
152
|
+
merge_query('range', query)
|
153
|
+
end
|
154
|
+
|
155
|
+
def filter(query)
|
156
|
+
merge_query('filter', query)
|
157
|
+
end
|
158
|
+
|
159
|
+
def duplicate(query)
|
160
|
+
merge_query('duplicate', query)
|
161
|
+
end
|
162
|
+
|
163
|
+
def merge_query(key, query)
|
164
|
+
raw_function "#{key}(#{query})"
|
165
|
+
end
|
166
|
+
|
167
|
+
def raw_function(function)
|
168
|
+
raw_query "#{new_command} #{function}"
|
169
|
+
end
|
170
|
+
|
171
|
+
def raw_query(query)
|
172
|
+
@query += query
|
173
|
+
self
|
174
|
+
end
|
175
|
+
|
176
|
+
def client_reconnection
|
177
|
+
client_connection
|
178
|
+
end
|
179
|
+
|
180
|
+
# And
|
68
181
|
|
69
|
-
|
182
|
+
def execute(query)
|
183
|
+
@query = query
|
184
|
+
end
|
70
185
|
|
71
|
-
|
186
|
+
```
|
72
187
|
|
73
188
|
## License
|
74
189
|
|
75
190
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
191
|
+
|
192
|
+
## Build and push GEM
|
193
|
+
|
194
|
+
```bash
|
195
|
+
gem build latias-influxdb.gemspec
|
196
|
+
gem push latias-influxdb-xx.xx.xx.gem
|
197
|
+
```
|
data/lib/latias/influxdb.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'influxdb-client'
|
4
|
+
|
5
|
+
module Latias
|
6
|
+
# Influxdb
|
7
|
+
module Influxdb
|
8
|
+
# Bucket
|
9
|
+
module ActionBucket
|
10
|
+
# base
|
11
|
+
class Base
|
12
|
+
attr_reader :url, :token, :bucket, :org, :use_ssl, :verify_mode, :precision, :query, :client
|
13
|
+
|
14
|
+
def execute(query)
|
15
|
+
@query = query
|
16
|
+
end
|
17
|
+
|
18
|
+
def call
|
19
|
+
all_query = "from(bucket: \"#{use_value('bucket')}\") #{@query}"
|
20
|
+
@query = ''
|
21
|
+
@client.create_query_api.query(query: all_query, org: use_value('org'))
|
22
|
+
end
|
23
|
+
|
24
|
+
def client_connection
|
25
|
+
@query = ''
|
26
|
+
@client = InfluxDB2::Client.new(use_value('url'), use_value('token'),
|
27
|
+
use_ssl: use_value('use_ssl'),
|
28
|
+
verify_mode: use_value('verify_mode'),
|
29
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def use_value(key)
|
36
|
+
b = get_binding("self")
|
37
|
+
b.eval("@#{key}") || Latias::Influxdb.configuration.send(key)
|
38
|
+
end
|
39
|
+
|
40
|
+
def new_command
|
41
|
+
'|> '
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_binding(param)
|
45
|
+
binding
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,64 +1,43 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "latias/influxdb/action_bucket/base"
|
4
4
|
|
5
5
|
module Latias
|
6
6
|
# Influxdb
|
7
7
|
module Influxdb
|
8
8
|
# Bucket
|
9
|
-
class Bucket
|
10
|
-
attr_reader :url, :token, :bucket, :org, :use_ssl, :verify_mode, :precision
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
set_default
|
14
|
-
end
|
15
|
-
|
16
|
-
def call
|
17
|
-
all_query = "from(bucket: \"#{@bucket}\") #{@query}"
|
18
|
-
@query = ''
|
19
|
-
@client.create_query_api.query(query: all_query, org: @org)
|
20
|
-
end
|
21
|
-
|
9
|
+
class Bucket < Latias::Influxdb::ActionBucket::Base
|
22
10
|
def yield(query)
|
23
|
-
|
24
|
-
self
|
11
|
+
merge_query('yield', query)
|
25
12
|
end
|
26
13
|
|
27
14
|
def range(query)
|
28
|
-
|
29
|
-
self
|
15
|
+
merge_query('range', query)
|
30
16
|
end
|
31
17
|
|
32
18
|
def filter(query)
|
33
|
-
|
34
|
-
self
|
19
|
+
merge_query('filter', query)
|
35
20
|
end
|
36
21
|
|
37
|
-
def
|
38
|
-
|
22
|
+
def duplicate(query)
|
23
|
+
merge_query('duplicate', query)
|
39
24
|
end
|
40
25
|
|
41
|
-
|
26
|
+
def merge_query(key, query)
|
27
|
+
raw_function "#{key}(#{query})"
|
28
|
+
end
|
42
29
|
|
43
|
-
def
|
44
|
-
|
45
|
-
@url = 'http://localhost:8086'
|
46
|
-
@token = 'token'
|
47
|
-
@bucket = 'bucket'
|
48
|
-
@org = 'org'
|
49
|
-
@use_ssl = false
|
50
|
-
@verify_mode = OpenSSL::SSL::VERIFY_NONE
|
30
|
+
def raw_function(function)
|
31
|
+
raw_query "#{new_command} #{function}"
|
51
32
|
end
|
52
33
|
|
53
|
-
def
|
54
|
-
|
34
|
+
def raw_query(query)
|
35
|
+
@query += query
|
36
|
+
self
|
55
37
|
end
|
56
38
|
|
57
|
-
def
|
58
|
-
|
59
|
-
use_ssl: @use_ssl,
|
60
|
-
verify_mode: @verify_mode.present? ? @verify_mode : OpenSSL::SSL::VERIFY_NONE,
|
61
|
-
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
39
|
+
def client_reconnection
|
40
|
+
client_connection
|
62
41
|
end
|
63
42
|
end
|
64
43
|
end
|
@@ -5,14 +5,19 @@ module Latias
|
|
5
5
|
module Influxdb
|
6
6
|
# Configuration
|
7
7
|
class Configuration
|
8
|
-
attr_accessor :
|
8
|
+
attr_accessor :url, :token, :bucket, :org, :use_ssl, :verify_mode, :precision
|
9
9
|
|
10
10
|
def initialize
|
11
|
-
@
|
11
|
+
@query = ''
|
12
|
+
@url = 'http://localhost:8086'
|
13
|
+
@token = 'token'
|
14
|
+
@bucket = 'bucket'
|
15
|
+
@org = 'org'
|
16
|
+
@use_ssl = false
|
17
|
+
@verify_mode = OpenSSL::SSL::VERIFY_NONE
|
12
18
|
end
|
13
19
|
end
|
14
20
|
|
15
|
-
# Borrow syntax from Clearance: https://github.com/thoughtbot/clearance/blob/master/lib/clearance/configuration.rb
|
16
21
|
def self.configuration
|
17
22
|
@configuration ||= Configuration.new
|
18
23
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Latias
|
4
|
+
module Influxdb
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
desc "Description:\n This creates a Rails initializer for latias::InfluxDB::Rails."
|
7
|
+
|
8
|
+
source_root File.expand_path('templates', __dir__)
|
9
|
+
|
10
|
+
def copy_initializer_file
|
11
|
+
template 'initializer.rb', 'config/initializers/latias_influxdb.rb'
|
12
|
+
end
|
13
|
+
|
14
|
+
def install
|
15
|
+
# nothing to do here
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,3 +1,9 @@
|
|
1
1
|
Latias::Influxdb.configure do |config|
|
2
|
-
#
|
2
|
+
# default
|
3
|
+
# config.url = 'http://localhost:8086'
|
4
|
+
# config.token = 'token'
|
5
|
+
# config.bucket = 'bucket'
|
6
|
+
# config.org = 'org'
|
7
|
+
# config.use_ssl = false
|
8
|
+
# config.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
3
9
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: latias-influxdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nattanon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: influxdb-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.16.0.pre.2890
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.16.0.pre.2890
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
34
|
-
type: :
|
33
|
+
version: 6.1.4
|
34
|
+
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 6.1.4
|
41
41
|
description:
|
42
42
|
email:
|
43
43
|
- nattanon@hospital-os.com
|
@@ -48,21 +48,14 @@ files:
|
|
48
48
|
- MIT-LICENSE
|
49
49
|
- README.md
|
50
50
|
- Rakefile
|
51
|
-
- app/assets/config/latias_influxdb_manifest.js
|
52
|
-
- app/assets/stylesheets/latias/influxdb/application.css
|
53
|
-
- app/controllers/latias/influxdb/application_controller.rb
|
54
|
-
- app/helpers/latias/influxdb/application_helper.rb
|
55
|
-
- app/jobs/latias/influxdb/application_job.rb
|
56
|
-
- app/mailers/latias/influxdb/application_mailer.rb
|
57
|
-
- app/models/latias/influxdb/application_record.rb
|
58
|
-
- app/views/layouts/latias/influxdb/application.html.erb
|
59
51
|
- config/routes.rb
|
60
52
|
- lib/latias/influxdb.rb
|
53
|
+
- lib/latias/influxdb/action_bucket/base.rb
|
61
54
|
- lib/latias/influxdb/bucket.rb
|
62
55
|
- lib/latias/influxdb/configuration.rb
|
63
56
|
- lib/latias/influxdb/engine.rb
|
64
57
|
- lib/latias/influxdb/version.rb
|
65
|
-
- lib/rails/generators/latias/influxdb/
|
58
|
+
- lib/rails/generators/latias/influxdb/install_generator.rb
|
66
59
|
- lib/rails/generators/latias/influxdb/templates/initializer.rb
|
67
60
|
- lib/tasks/latias/influxdb_tasks.rake
|
68
61
|
homepage: https://gitlab.opensource-technology.com/nattanon/latias-influxdb
|
@@ -1 +0,0 @@
|
|
1
|
-
//= link_directory ../stylesheets/latias/influxdb .css
|
@@ -1,15 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
-
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
-
* It is generally better to create a new file per style scope.
|
12
|
-
*
|
13
|
-
*= require_tree .
|
14
|
-
*= require_self
|
15
|
-
*/
|
@@ -1,15 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>Latias influxdb</title>
|
5
|
-
<%= csrf_meta_tags %>
|
6
|
-
<%= csp_meta_tag %>
|
7
|
-
|
8
|
-
<%= stylesheet_link_tag "latias/influxdb/application", media: "all" %>
|
9
|
-
</head>
|
10
|
-
<body>
|
11
|
-
|
12
|
-
<%= yield %>
|
13
|
-
|
14
|
-
</body>
|
15
|
-
</html>
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
|
3
|
-
class InfluxdbGenerator < Rails::Generators::Base
|
4
|
-
desc "Description:\n This creates a Rails initializer for latias::InfluxDB::Rails."
|
5
|
-
|
6
|
-
source_root File.expand_path('templates', __dir__)
|
7
|
-
|
8
|
-
def copy_initializer_file
|
9
|
-
template 'initializer.rb', 'config/initializers/latias_influxdb.rb'
|
10
|
-
end
|
11
|
-
|
12
|
-
def install
|
13
|
-
# nothing to do here
|
14
|
-
end
|
15
|
-
end
|