embulk-input-prometheus 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 170ee87debf53972d5a8d689c8e4b03e3e13717f9a4a488bd9933878c0ea1dc2
4
+ data.tar.gz: 0ee4dd4d3394701e2a2bb4d7e1980bd475998ed41d4018870f2a6a0ecb6a0532
5
+ SHA512:
6
+ metadata.gz: 07d093c170fa64feb26631d015634733309f7ead915401824b53de5bb1723eb09dc17783631b1fa97dd727f5c0abe690f98345a50ad1c0c24aa08eea853738dc
7
+ data.tar.gz: c75e3d61b4280d3e993297e2b4846df3006d4b58804194a4f51bc6386a0900e529be2ae564b4233ee692d5b575e43f2514d3f9b7ebe8c4226b9e74be8b886101
@@ -0,0 +1,5 @@
1
+ *~
2
+ /pkg/
3
+ /tmp/
4
+ /.bundle/
5
+ /Gemfile.lock
@@ -0,0 +1 @@
1
+ jruby-9.1.13.0
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec
@@ -0,0 +1,21 @@
1
+
2
+ MIT License
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ # Prometheus input plugin for Embulk
2
+
3
+ Load from prometheus time series data.
4
+
5
+ ## Configuration
6
+
7
+ ```yaml
8
+ in:
9
+ type: prometheus
10
+ url: https://example.com
11
+ query: "(100 * (1 - avg by(instance, consul_dc)(irate(node_cpu_seconds_total{job=~\".*node.exporter\",mode='idle'}[1m]))))"
12
+ since: 86400 # sec
13
+ step: 3600 #sec
14
+ tls:
15
+ cert_path: "/path/to/api.crt"
16
+ key_path: "/path/to/api.key"
17
+ ca_path: "/path/to/api.ca"
18
+ ```
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task default: :build
@@ -0,0 +1,18 @@
1
+
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "embulk-input-prometheus"
4
+ spec.version = "0.1.0"
5
+ spec.authors = ["pyama86"]
6
+ spec.summary = "Prometheus input plugin for Embulk"
7
+ spec.description = "Loads records from Prometheus."
8
+ spec.email = ["pyama@pepabo.com"]
9
+ spec.licenses = ["MIT"]
10
+ spec.homepage = "https://github.com/pyama86/embulk-input-prometheus"
11
+ spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
12
+ spec.test_files = spec.files.grep(%r{^(test|spec)/})
13
+ spec.require_paths = ["lib"]
14
+ spec.add_dependency 'prometheus-api-client'
15
+ spec.add_development_dependency 'embulk', ['>= 0.8.39']
16
+ spec.add_development_dependency 'bundler', ['>= 1.10.6']
17
+ spec.add_development_dependency 'rake', ['>= 10.0']
18
+ end
@@ -0,0 +1,81 @@
1
+ require 'prometheus/api_client'
2
+ require 'openssl'
3
+ require 'json'
4
+ require 'pp'
5
+
6
+ module Embulk
7
+ module Input
8
+
9
+ class Prometheus < InputPlugin
10
+ Plugin.register_input("prometheus", self)
11
+ def self.transaction(config, &control)
12
+ task = {
13
+ "url" => config.param("url", :string, default: 'http://localhost:9090/api/v1/'),
14
+ "query" => config.param("query", :string),
15
+ "since" => config.param("since", :integer),
16
+ "step" => config.param("step", :integer),
17
+ "element_key" => config.param("element_key", :string, default: 'instance'),
18
+ "tls" => config.param("tls", :hash, default: nil),
19
+ "token" => config.param("token", :string, default: nil),
20
+ "timeout" => config.param("timeout", :interger, default: 60),
21
+ "open_timeout" => config.param("open_timeout", :interger, default: 10),
22
+ }
23
+
24
+ columns = [
25
+ Column.new(0, "name", :string),
26
+ Column.new(1, "time", :double),
27
+ Column.new(2, "value", :double),
28
+ ]
29
+
30
+ resume(task, columns, 1, &control)
31
+ end
32
+
33
+ def self.resume(task, columns, count, &control)
34
+ task_reports = yield(task, columns, count)
35
+
36
+ next_config_diff = {}
37
+ return next_config_diff
38
+ end
39
+
40
+ def run
41
+ params = {
42
+ url: task['url'],
43
+ options: {},
44
+ ssl: {},
45
+ credentials: {},
46
+ }
47
+
48
+ params[:ssl][:client_cert] = OpenSSL::X509::Certificate.new(File.read(task["tls"]["cert_path"])) if task["tls"]["cert_path"]
49
+ params[:ssl][:client_key] = OpenSSL::PKey::RSA.new(File.read(task["tls"]["key_path"])) if task["tls"]["key_path"]
50
+ params[:ssl][:ca_file] = task["tls"]["ca_path"] if task["tls"]["ca_path"]
51
+
52
+ params[:credentials][:token] = task["token"] if task["token"]
53
+
54
+ %w(
55
+ open_timeout
56
+ timeout
57
+ ).each do |n|
58
+ params[:options][n.to_sym] = task[n] if task[n]
59
+ end
60
+
61
+ result = JSON.parse(::Prometheus::ApiClient.client(params).get(
62
+ 'query_range',
63
+ query: task['query'],
64
+ start: (Time.now - task['since']).strftime("%Y-%m-%dT%H:%M:%S.%LZ"),
65
+ end: Time.now.strftime("%Y-%m-%dT%H:%M:%S.%LZ"),
66
+ step: "#{task['step']}s",
67
+ ).body)
68
+
69
+ result['data']['result'].each do |r|
70
+ r["values"].each do |v|
71
+ page_builder.add([r["metric"][task["element_key"]], v[0], v[1]])
72
+ end
73
+ end if result['status'] == 'success'
74
+
75
+ page_builder.finish
76
+ task_report = {}
77
+ return task_report
78
+ end
79
+ end
80
+ end
81
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-input-prometheus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - pyama86
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prometheus-api-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: embulk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.39
34
+ version_requirements: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: 0.8.39
39
+ prerelease: false
40
+ type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.10.6
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.10.6
53
+ prerelease: false
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '10.0'
67
+ prerelease: false
68
+ type: :development
69
+ description: Loads records from Prometheus.
70
+ email:
71
+ - pyama@pepabo.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".ruby-version"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - embulk-input-prometheus.gemspec
83
+ - lib/embulk/input/prometheus.rb
84
+ homepage: https://github.com/pyama86/embulk-input-prometheus
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.6.13
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Prometheus input plugin for Embulk
108
+ test_files: []