lex-prometheus 0.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 +7 -0
- data/.github/workflows/ci.yml +16 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +53 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +11 -0
- data/README.md +50 -0
- data/lex-prometheus.gemspec +30 -0
- data/lib/legion/extensions/prometheus/client.rb +31 -0
- data/lib/legion/extensions/prometheus/helpers/client.rb +22 -0
- data/lib/legion/extensions/prometheus/runners/alerts.rb +21 -0
- data/lib/legion/extensions/prometheus/runners/queries.rb +44 -0
- data/lib/legion/extensions/prometheus/version.rb +9 -0
- data/lib/legion/extensions/prometheus.rb +15 -0
- metadata +72 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 3fc4cdaed40797a62e2fc0cde191e5acbb315af1de50282be97f7cbc8a371b28
|
|
4
|
+
data.tar.gz: 95a5f8f361ab7b758ca66cbe54798310a7a2122b9e25011b42c672e53c651d18
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 583532d31a1c2c3c8e409b73e9bdacc7804fb7a18efdc035731c16eaefabbe7dbfa2d19ceeacb11342e44ede0f83447626f359b0b969a56b508f57244785d486
|
|
7
|
+
data.tar.gz: f5ad9e1f0ae87248c479c3c5b9b18a4657b901bbf6a9ae1e9205da77421e353a81471c03c5e37dc8942499b6d2afdae906bbcd94ed63cf6a01d5e3bd3901d876
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [origin]
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
ci:
|
|
9
|
+
uses: LegionIO/.github/.github/workflows/ci.yml@main
|
|
10
|
+
|
|
11
|
+
release:
|
|
12
|
+
needs: ci
|
|
13
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/origin'
|
|
14
|
+
uses: LegionIO/.github/.github/workflows/release.yml@main
|
|
15
|
+
secrets:
|
|
16
|
+
rubygems-api-key: ${{ secrets.RUBYGEMS_API_KEY }}
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 3.4
|
|
3
|
+
NewCops: enable
|
|
4
|
+
SuggestExtensions: false
|
|
5
|
+
|
|
6
|
+
Layout/LineLength:
|
|
7
|
+
Max: 160
|
|
8
|
+
|
|
9
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
|
10
|
+
EnforcedStyle: space
|
|
11
|
+
|
|
12
|
+
Layout/HashAlignment:
|
|
13
|
+
EnforcedHashRocketStyle: table
|
|
14
|
+
EnforcedColonStyle: table
|
|
15
|
+
|
|
16
|
+
Metrics/MethodLength:
|
|
17
|
+
Max: 50
|
|
18
|
+
|
|
19
|
+
Metrics/ClassLength:
|
|
20
|
+
Max: 1500
|
|
21
|
+
|
|
22
|
+
Metrics/ModuleLength:
|
|
23
|
+
Max: 1500
|
|
24
|
+
|
|
25
|
+
Metrics/BlockLength:
|
|
26
|
+
Max: 40
|
|
27
|
+
Exclude:
|
|
28
|
+
- 'spec/**/*'
|
|
29
|
+
|
|
30
|
+
Metrics/ParameterLists:
|
|
31
|
+
Max: 10
|
|
32
|
+
|
|
33
|
+
Metrics/AbcSize:
|
|
34
|
+
Max: 60
|
|
35
|
+
|
|
36
|
+
Metrics/CyclomaticComplexity:
|
|
37
|
+
Max: 15
|
|
38
|
+
|
|
39
|
+
Metrics/PerceivedComplexity:
|
|
40
|
+
Max: 17
|
|
41
|
+
|
|
42
|
+
Style/Documentation:
|
|
43
|
+
Enabled: false
|
|
44
|
+
|
|
45
|
+
Style/SymbolArray:
|
|
46
|
+
Enabled: true
|
|
47
|
+
|
|
48
|
+
Style/FrozenStringLiteralComment:
|
|
49
|
+
Enabled: true
|
|
50
|
+
EnforcedStyle: always
|
|
51
|
+
|
|
52
|
+
Naming/FileName:
|
|
53
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.1.0] - 2026-03-21
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Initial release
|
|
7
|
+
- `Helpers::Client` — Faraday connection builder with optional Basic auth
|
|
8
|
+
- `Runners::Queries` — instant_query, range_query, series, labels, label_values
|
|
9
|
+
- `Runners::Alerts` — list_alerts, list_rules
|
|
10
|
+
- Standalone `Client` class for use outside the Legion framework
|
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# lex-prometheus
|
|
2
|
+
|
|
3
|
+
LegionIO extension for querying Prometheus via the HTTP API v1.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add to your Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'lex-prometheus'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Standalone Usage
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
require 'legion/extensions/prometheus'
|
|
17
|
+
|
|
18
|
+
client = Legion::Extensions::Prometheus::Client.new(
|
|
19
|
+
url: 'http://prometheus:9090',
|
|
20
|
+
username: 'admin', # optional
|
|
21
|
+
password: 'secret' # optional
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
# Instant query
|
|
25
|
+
client.instant_query(query: 'up')
|
|
26
|
+
client.instant_query(query: 'up', time: '2026-01-01T00:00:00Z')
|
|
27
|
+
|
|
28
|
+
# Range query
|
|
29
|
+
client.range_query(query: 'rate(http_requests_total[5m])', start: '2026-01-01T00:00:00Z', end_time: '2026-01-02T00:00:00Z', step: '1h')
|
|
30
|
+
|
|
31
|
+
# Series
|
|
32
|
+
client.series(match: 'up')
|
|
33
|
+
client.series(match: '{job="prometheus"}', start: '2026-01-01T00:00:00Z')
|
|
34
|
+
|
|
35
|
+
# Labels
|
|
36
|
+
client.labels
|
|
37
|
+
client.label_values(label_name: 'job')
|
|
38
|
+
|
|
39
|
+
# Alerts and rules
|
|
40
|
+
client.list_alerts
|
|
41
|
+
client.list_rules
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Authentication
|
|
45
|
+
|
|
46
|
+
Basic auth is optional. Pass `username:` and `password:` to the Client constructor if your Prometheus instance requires authentication.
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
MIT
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/legion/extensions/prometheus/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'lex-prometheus'
|
|
7
|
+
spec.version = Legion::Extensions::Prometheus::VERSION
|
|
8
|
+
spec.authors = ['Esity']
|
|
9
|
+
spec.email = ['matthewdiverson@gmail.com']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'LEX::Prometheus'
|
|
12
|
+
spec.description = 'Used to connect Legion to Prometheus'
|
|
13
|
+
spec.homepage = 'https://github.com/LegionIO/lex-prometheus'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = '>= 3.4'
|
|
16
|
+
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/LegionIO/lex-prometheus'
|
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/LegionIO/lex-prometheus/blob/main/CHANGELOG.md'
|
|
20
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
21
|
+
|
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
24
|
+
end
|
|
25
|
+
spec.bindir = 'exe'
|
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
27
|
+
spec.require_paths = ['lib']
|
|
28
|
+
|
|
29
|
+
spec.add_dependency 'faraday', '>= 2.0'
|
|
30
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'helpers/client'
|
|
4
|
+
require_relative 'runners/queries'
|
|
5
|
+
require_relative 'runners/alerts'
|
|
6
|
+
|
|
7
|
+
module Legion
|
|
8
|
+
module Extensions
|
|
9
|
+
module Prometheus
|
|
10
|
+
class Client
|
|
11
|
+
include Helpers::Client
|
|
12
|
+
include Runners::Queries
|
|
13
|
+
include Runners::Alerts
|
|
14
|
+
|
|
15
|
+
attr_reader :opts
|
|
16
|
+
|
|
17
|
+
def initialize(url:, username: nil, password: nil, **extra)
|
|
18
|
+
@opts = { url: url, username: username, password: password, **extra }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def settings
|
|
22
|
+
{ options: @opts }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def connection(**override)
|
|
26
|
+
super(**@opts, **override)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'faraday'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Prometheus
|
|
8
|
+
module Helpers
|
|
9
|
+
module Client
|
|
10
|
+
def connection(url: nil, username: nil, password: nil, **_opts)
|
|
11
|
+
base_url = url || 'http://prometheus:9090'
|
|
12
|
+
Faraday.new(url: base_url) do |conn|
|
|
13
|
+
conn.response :json, content_type: /\bjson$/
|
|
14
|
+
conn.request :authorization, :basic, username, password if username && password
|
|
15
|
+
conn.adapter Faraday.default_adapter
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Prometheus
|
|
6
|
+
module Runners
|
|
7
|
+
module Alerts
|
|
8
|
+
def list_alerts(**)
|
|
9
|
+
resp = connection(**).get('/api/v1/alerts')
|
|
10
|
+
{ alerts: resp.body }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def list_rules(**)
|
|
14
|
+
resp = connection(**).get('/api/v1/rules')
|
|
15
|
+
{ rules: resp.body }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Prometheus
|
|
6
|
+
module Runners
|
|
7
|
+
module Queries
|
|
8
|
+
def instant_query(query:, time: nil, **)
|
|
9
|
+
params = { query: query }
|
|
10
|
+
params[:time] = time if time
|
|
11
|
+
resp = connection(**).get('/api/v1/query', params)
|
|
12
|
+
{ result: resp.body }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def range_query(query:, step:, start: nil, end_time: nil, **)
|
|
16
|
+
params = { query: query, step: step }
|
|
17
|
+
params[:start] = start if start
|
|
18
|
+
params[:end] = end_time if end_time
|
|
19
|
+
resp = connection(**).get('/api/v1/query_range', params)
|
|
20
|
+
{ result: resp.body }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def series(match:, start: nil, end_time: nil, **)
|
|
24
|
+
params = { 'match[]' => match }
|
|
25
|
+
params[:start] = start if start
|
|
26
|
+
params[:end] = end_time if end_time
|
|
27
|
+
resp = connection(**).get('/api/v1/series', params)
|
|
28
|
+
{ series: resp.body }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def labels(**)
|
|
32
|
+
resp = connection(**).get('/api/v1/labels')
|
|
33
|
+
{ labels: resp.body }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def label_values(label_name:, **)
|
|
37
|
+
resp = connection(**).get("/api/v1/label/#{label_name}/values")
|
|
38
|
+
{ values: resp.body }
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/prometheus/version'
|
|
4
|
+
require 'legion/extensions/prometheus/helpers/client'
|
|
5
|
+
require 'legion/extensions/prometheus/runners/queries'
|
|
6
|
+
require 'legion/extensions/prometheus/runners/alerts'
|
|
7
|
+
require 'legion/extensions/prometheus/client'
|
|
8
|
+
|
|
9
|
+
module Legion
|
|
10
|
+
module Extensions
|
|
11
|
+
module Prometheus
|
|
12
|
+
extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: lex-prometheus
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Esity
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: faraday
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '2.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '2.0'
|
|
26
|
+
description: Used to connect Legion to Prometheus
|
|
27
|
+
email:
|
|
28
|
+
- matthewdiverson@gmail.com
|
|
29
|
+
executables: []
|
|
30
|
+
extensions: []
|
|
31
|
+
extra_rdoc_files: []
|
|
32
|
+
files:
|
|
33
|
+
- ".github/workflows/ci.yml"
|
|
34
|
+
- ".gitignore"
|
|
35
|
+
- ".rspec"
|
|
36
|
+
- ".rubocop.yml"
|
|
37
|
+
- CHANGELOG.md
|
|
38
|
+
- Gemfile
|
|
39
|
+
- README.md
|
|
40
|
+
- lex-prometheus.gemspec
|
|
41
|
+
- lib/legion/extensions/prometheus.rb
|
|
42
|
+
- lib/legion/extensions/prometheus/client.rb
|
|
43
|
+
- lib/legion/extensions/prometheus/helpers/client.rb
|
|
44
|
+
- lib/legion/extensions/prometheus/runners/alerts.rb
|
|
45
|
+
- lib/legion/extensions/prometheus/runners/queries.rb
|
|
46
|
+
- lib/legion/extensions/prometheus/version.rb
|
|
47
|
+
homepage: https://github.com/LegionIO/lex-prometheus
|
|
48
|
+
licenses:
|
|
49
|
+
- MIT
|
|
50
|
+
metadata:
|
|
51
|
+
homepage_uri: https://github.com/LegionIO/lex-prometheus
|
|
52
|
+
source_code_uri: https://github.com/LegionIO/lex-prometheus
|
|
53
|
+
changelog_uri: https://github.com/LegionIO/lex-prometheus/blob/main/CHANGELOG.md
|
|
54
|
+
rubygems_mfa_required: 'true'
|
|
55
|
+
rdoc_options: []
|
|
56
|
+
require_paths:
|
|
57
|
+
- lib
|
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '3.4'
|
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
requirements: []
|
|
69
|
+
rubygems_version: 3.6.9
|
|
70
|
+
specification_version: 4
|
|
71
|
+
summary: LEX::Prometheus
|
|
72
|
+
test_files: []
|