latias-influxdb 0.1.0 → 1.0.0.pre.bata
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +86 -23
- data/lib/latias/influxdb.rb +1 -0
- data/lib/latias/influxdb/bucket.rb +23 -35
- 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 +9 -0
- data/lib/tasks/latias/influxdb_tasks.rake +10 -4
- metadata +20 -12
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d81103797f4987e9edcf5d79d896d86536a617d76b75696fd0dab690b49d9cea
|
4
|
+
data.tar.gz: fba4af3dcc45f9e785b0dd3d641d35e968b61687d20b56ab7343c4c16644f14e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea0c14439f1a0281422fd39cef6998b6bcff89d93e09420d04438f1f1a2ff217f9d099025a7ec72925beb1502a226b98648ebbe1862ab9d9b68a8025f2b33cba
|
7
|
+
data.tar.gz: 11eeee42967286b77a0eaf535dc987d8019b52b01d989105af9dbc61cbe7b3897ba6fb8e632b721146dd6c9006637dd071eaa9d450c2f6195ab3b1d1f92660fe
|
data/README.md
CHANGED
@@ -2,27 +2,6 @@
|
|
2
2
|
|
3
3
|
Ruby lib for use influxdb version 2 on Ruby language
|
4
4
|
|
5
|
-
## Usage
|
6
|
-
|
7
|
-
```ruby
|
8
|
-
class MdbEnergyBucket < Latias::Influxdb::Bucket
|
9
|
-
def initialize
|
10
|
-
@url = 'http://localhost:8086'
|
11
|
-
@token = 'your token'
|
12
|
-
@bucket = 'MDBEnergy'
|
13
|
-
@org = 'MDBEnergy'
|
14
|
-
@use_ssl = false
|
15
|
-
@verify_mode = OpenSSL::SSL::VERIFY_NONE
|
16
|
-
@precision = InfluxDB2::WritePrecision::NANOSECOND
|
17
|
-
@client = client
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
mdb_energy_bucket = MdbEnergyBucket.new
|
22
|
-
mdb_energy_bucket.range('start: -1m').filter('fn: (r) => r["_measurement"] == "cpu"')
|
23
|
-
mdb_energy_bucket.call
|
24
|
-
```
|
25
|
-
|
26
5
|
## Installation
|
27
6
|
|
28
7
|
Add this line to your application's Gemfile:
|
@@ -43,9 +22,93 @@ Or install it yourself as:
|
|
43
22
|
$ gem install latias-influxdb
|
44
23
|
```
|
45
24
|
|
46
|
-
|
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
|
47
76
|
|
48
|
-
|
77
|
+
<!-- ```ruby
|
78
|
+
class MdbEnergyBucket < Latias::Influxdb::Bucket
|
79
|
+
def initialize
|
80
|
+
super
|
81
|
+
@url = 'http://188.166.252.165:8086'
|
82
|
+
@token = 'YyD4UGu4_Xn0CIVsycFdjaQVd7m1g5wRp0z2BCfBSyNL6-GHqqyZRePGy46B2m8Zg6jgqHAN_J6jyhCmvGeQRA=='
|
83
|
+
@bucket = 'MDBEnergy'
|
84
|
+
@org = 'MDBEnergy'
|
85
|
+
@use_ssl = false
|
86
|
+
client_connection
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
mdb_energy_bucket = MdbEnergyBucket.new
|
91
|
+
mdb_energy_bucket.range('start: -1m').filter('fn: (r) => r["_measurement"] == "cpu"')
|
92
|
+
mdb_energy_bucket.call
|
93
|
+
``` -->
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
class MdbEnergyBucket < Latias::Influxdb::Bucket
|
97
|
+
def initialize
|
98
|
+
super
|
99
|
+
@url = 'http://localhost:8086'
|
100
|
+
@token = 'your token'
|
101
|
+
@bucket = 'MDBEnergy'
|
102
|
+
@org = 'MDBEnergy'
|
103
|
+
@use_ssl = false
|
104
|
+
client_connection
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
mdb_energy_bucket = MdbEnergyBucket.new
|
109
|
+
mdb_energy_bucket.range('start: -1m').filter('fn: (r) => r["_measurement"] == "cpu"')
|
110
|
+
mdb_energy_bucket.call
|
111
|
+
```
|
49
112
|
|
50
113
|
## License
|
51
114
|
|
data/lib/latias/influxdb.rb
CHANGED
@@ -11,70 +11,58 @@ module Latias
|
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
@query = ''
|
14
|
-
@url = 'http://localhost:8086'
|
15
|
-
@token = 'token'
|
16
|
-
@bucket = 'bucket'
|
17
|
-
@org = 'org'
|
18
|
-
@use_ssl = false
|
19
|
-
@verify_mode = OpenSSL::SSL::VERIFY_NONE
|
20
14
|
end
|
21
15
|
|
22
16
|
def call
|
23
|
-
all_query = "from(bucket: \"#{
|
17
|
+
all_query = "from(bucket: \"#{use_value('bucket')}\") #{@query}"
|
24
18
|
@query = ''
|
25
|
-
@client.create_query_api.query(query: all_query, org:
|
19
|
+
@client.create_query_api.query(query: all_query, org: use_value('org'))
|
26
20
|
end
|
27
21
|
|
28
|
-
# old code
|
29
|
-
# def call
|
30
|
-
# all_query = "from(bucket: \"#{@bucket}\")" \
|
31
|
-
# '|> range(start: -1m)
|
32
|
-
# |> filter(fn: (r) => r["_measurement"] == "cpu")
|
33
|
-
# |> filter(fn: (r) => r["_field"] == "usage_user")
|
34
|
-
# |> filter(fn: (r) => r["cpu"] == "cpu-total" or r["cpu"] == "cpu0" or r["cpu"] == "cpu1")
|
35
|
-
# |> yield(name: "sum")'
|
36
|
-
|
37
|
-
# @client.create_query_api.query(query: all_query, org: @org)
|
38
|
-
# end
|
39
|
-
|
40
22
|
def yield(query)
|
41
|
-
@query +=
|
23
|
+
@query += "#{new_command} yield(#{query})"
|
42
24
|
self
|
43
25
|
end
|
44
26
|
|
45
27
|
def range(query)
|
46
|
-
@query +=
|
28
|
+
@query += "#{new_command} range(#{query})"
|
47
29
|
self
|
48
30
|
end
|
49
31
|
|
50
32
|
def filter(query)
|
51
|
-
@query +=
|
33
|
+
@query += "#{new_command} filter(#{query})"
|
52
34
|
self
|
53
35
|
end
|
54
36
|
|
55
|
-
|
37
|
+
def real_query(query)
|
38
|
+
@query += query
|
39
|
+
end
|
56
40
|
|
57
|
-
def
|
58
|
-
|
41
|
+
def client_connection
|
42
|
+
@client = InfluxDB2::Client.new(use_value('url'), use_value('token'),
|
43
|
+
use_ssl: use_value('use_ssl'),
|
44
|
+
verify_mode: use_value('verify_mode'),
|
45
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
46
|
+
self
|
59
47
|
end
|
60
48
|
|
61
|
-
def
|
62
|
-
|
49
|
+
def client_reconnection
|
50
|
+
client_connection
|
63
51
|
end
|
64
52
|
|
65
|
-
|
66
|
-
|
53
|
+
private
|
54
|
+
|
55
|
+
def use_value(key)
|
56
|
+
b = get_binding("self")
|
57
|
+
b.eval("@#{key}") || Latias::Influxdb.configuration.send(key)
|
67
58
|
end
|
68
59
|
|
69
60
|
def new_command
|
70
61
|
'|> '
|
71
62
|
end
|
72
63
|
|
73
|
-
def
|
74
|
-
|
75
|
-
use_ssl: @use_ssl,
|
76
|
-
verify_mode: @verify_mode.present? ? @verify_mode : OpenSSL::SSL::VERIFY_NONE,
|
77
|
-
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
64
|
+
def get_binding(param)
|
65
|
+
binding
|
78
66
|
end
|
79
67
|
end
|
80
68
|
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,4 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require 'latias/influxdb/version'
|
2
|
+
|
3
|
+
namespace :latias do
|
4
|
+
namespace :influxdb do
|
5
|
+
desc 'check lib varsion'
|
6
|
+
task verion: :environment do
|
7
|
+
puts "Version: #{Latias::Influxdb::VERSION}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: latias-influxdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.pre.bata
|
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-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: influxdb-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.16.0.pre.2765
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.16.0.pre.2765
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rails
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -34,20 +48,14 @@ files:
|
|
34
48
|
- MIT-LICENSE
|
35
49
|
- README.md
|
36
50
|
- Rakefile
|
37
|
-
- app/assets/config/latias_influxdb_manifest.js
|
38
|
-
- app/assets/stylesheets/latias/influxdb/application.css
|
39
|
-
- app/controllers/latias/influxdb/application_controller.rb
|
40
|
-
- app/helpers/latias/influxdb/application_helper.rb
|
41
|
-
- app/jobs/latias/influxdb/application_job.rb
|
42
|
-
- app/mailers/latias/influxdb/application_mailer.rb
|
43
|
-
- app/models/latias/influxdb/application_record.rb
|
44
|
-
- app/views/layouts/latias/influxdb/application.html.erb
|
45
51
|
- config/routes.rb
|
46
52
|
- lib/latias/influxdb.rb
|
47
53
|
- lib/latias/influxdb/bucket.rb
|
48
54
|
- lib/latias/influxdb/configuration.rb
|
49
55
|
- lib/latias/influxdb/engine.rb
|
50
56
|
- lib/latias/influxdb/version.rb
|
57
|
+
- lib/rails/generators/latias/influxdb/install_generator.rb
|
58
|
+
- lib/rails/generators/latias/influxdb/templates/initializer.rb
|
51
59
|
- lib/tasks/latias/influxdb_tasks.rake
|
52
60
|
homepage: https://gitlab.opensource-technology.com/nattanon/latias-influxdb
|
53
61
|
licenses:
|
@@ -66,9 +74,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
74
|
version: '0'
|
67
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
76
|
requirements:
|
69
|
-
- - "
|
77
|
+
- - ">"
|
70
78
|
- !ruby/object:Gem::Version
|
71
|
-
version:
|
79
|
+
version: 1.3.1
|
72
80
|
requirements: []
|
73
81
|
rubygems_version: 3.2.6
|
74
82
|
signing_key:
|
@@ -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>
|