garf-prometheus 0.0.1__tar.gz

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,88 @@
1
+ Metadata-Version: 2.4
2
+ Name: garf-prometheus
3
+ Version: 0.0.1
4
+ Summary: Garf implementation for Prometheus API
5
+ Author-email: Andrei Markin <amarkin@google.com>, "Google Inc. (gTech gPS CSE team)" <no-reply@google.com>
6
+ License: Apache 2.0
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Programming Language :: Python
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: garf-core[pandas]>=1.1.2
12
+ Requires-Dist: garf-io>=1.0.0
13
+ Provides-Extra: test
14
+ Requires-Dist: pytest; extra == "test"
15
+ Requires-Dist: pytest-cov; extra == "test"
16
+ Requires-Dist: pytest-mock; extra == "test"
17
+ Requires-Dist: python-dotenv; extra == "test"
18
+
19
+ # `garf` for Prometheus HTTP API
20
+
21
+ [![PyPI](https://img.shields.io/pypi/v/garf-prometheus?logo=pypi&logoColor=white&style=flat-square)](https://pypi.org/project/garf-prometheus)
22
+ [![Downloads PyPI](https://img.shields.io/pypi/dw/garf-prometheus?logo=pypi)](https://pypi.org/project/garf-prometheus/)
23
+
24
+ `garf-prometheus` simplifies fetching data from Prometheus HTTP API using SQL-like queries.
25
+
26
+ ## Prerequisites
27
+
28
+ * Running Prometheus instance
29
+
30
+ ## Installation
31
+
32
+ `pip install garf-prometheus`
33
+
34
+ ## Usage
35
+
36
+ ### Run as a library
37
+ ```
38
+ import os
39
+
40
+ from garf.io import writer
41
+ from garf.community.prometheus import PrometheusApiReportFetcher
42
+
43
+ query = """
44
+ SELECT
45
+ timestamp,
46
+ instance,
47
+ job,
48
+ value
49
+ FROM query
50
+ WHERE query = up
51
+ """
52
+
53
+ fetched_report = (
54
+ PrometheusApiReportFetcher(
55
+ endpoint='http://localhost:9090'
56
+ )
57
+ .fetch(query)
58
+ )
59
+
60
+ console_writer = writer.create_writer('console')
61
+ console_writer.write(fetched_report, 'query')
62
+ ```
63
+
64
+ ### Run via CLI
65
+
66
+ > Install `garf-executors` package to run queries via CLI (`pip install garf-executors`).
67
+
68
+ ```
69
+ garf <PATH_TO_QUERIES> --source prometheus \
70
+ --output <OUTPUT_TYPE> \
71
+ --prometheus.endpoint=http://localhost:9090
72
+ ```
73
+
74
+ where:
75
+
76
+ * `PATH_TO_QUERIES` - local or remove files containing queries
77
+ * `output` - output supported by [`garf-io` library](https://google.github.io/garf/usage/writers/).
78
+ * `SOURCE_PARAMETER=VALUE` - key-value pairs to refine fetching, check [available source parameters](#available-source-parameters).
79
+
80
+ ### Available source parameters
81
+
82
+ | name | values| comments |
83
+ |----- | ----- | -------- |
84
+ | `endpoint` | Base URL when Prometheus is running (`http://localhost:9090` by default) |
85
+
86
+ ## Documentation
87
+
88
+ You can find a documentation on `garf-prometheus` [here](https://google.github.io/garf/fetchers/prometheus/).
@@ -0,0 +1,70 @@
1
+ # `garf` for Prometheus HTTP API
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/garf-prometheus?logo=pypi&logoColor=white&style=flat-square)](https://pypi.org/project/garf-prometheus)
4
+ [![Downloads PyPI](https://img.shields.io/pypi/dw/garf-prometheus?logo=pypi)](https://pypi.org/project/garf-prometheus/)
5
+
6
+ `garf-prometheus` simplifies fetching data from Prometheus HTTP API using SQL-like queries.
7
+
8
+ ## Prerequisites
9
+
10
+ * Running Prometheus instance
11
+
12
+ ## Installation
13
+
14
+ `pip install garf-prometheus`
15
+
16
+ ## Usage
17
+
18
+ ### Run as a library
19
+ ```
20
+ import os
21
+
22
+ from garf.io import writer
23
+ from garf.community.prometheus import PrometheusApiReportFetcher
24
+
25
+ query = """
26
+ SELECT
27
+ timestamp,
28
+ instance,
29
+ job,
30
+ value
31
+ FROM query
32
+ WHERE query = up
33
+ """
34
+
35
+ fetched_report = (
36
+ PrometheusApiReportFetcher(
37
+ endpoint='http://localhost:9090'
38
+ )
39
+ .fetch(query)
40
+ )
41
+
42
+ console_writer = writer.create_writer('console')
43
+ console_writer.write(fetched_report, 'query')
44
+ ```
45
+
46
+ ### Run via CLI
47
+
48
+ > Install `garf-executors` package to run queries via CLI (`pip install garf-executors`).
49
+
50
+ ```
51
+ garf <PATH_TO_QUERIES> --source prometheus \
52
+ --output <OUTPUT_TYPE> \
53
+ --prometheus.endpoint=http://localhost:9090
54
+ ```
55
+
56
+ where:
57
+
58
+ * `PATH_TO_QUERIES` - local or remove files containing queries
59
+ * `output` - output supported by [`garf-io` library](https://google.github.io/garf/usage/writers/).
60
+ * `SOURCE_PARAMETER=VALUE` - key-value pairs to refine fetching, check [available source parameters](#available-source-parameters).
61
+
62
+ ### Available source parameters
63
+
64
+ | name | values| comments |
65
+ |----- | ----- | -------- |
66
+ | `endpoint` | Base URL when Prometheus is running (`http://localhost:9090` by default) |
67
+
68
+ ## Documentation
69
+
70
+ You can find a documentation on `garf-prometheus` [here](https://google.github.io/garf/fetchers/prometheus/).
@@ -0,0 +1,17 @@
1
+ # Copyright 2026 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Library for interacting with Prometheus Query API via garf."""
16
+
17
+ __version__ = '0.0.1'
@@ -0,0 +1,66 @@
1
+ # Copyright 2026 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Handles to Prometheus HTTP API querying."""
16
+
17
+ import requests
18
+ from garf.community.prometheus import exceptions, query_editor
19
+ from garf.core import api_clients
20
+
21
+
22
+ class PrometheusApiClientError(exceptions.PrometheusApiError):
23
+ """Prometheus HTTP API specific error."""
24
+
25
+
26
+ class PrometheusApiClient(api_clients.RestApiClient):
27
+ """Specifies client for interacting with Prometheus HTTP API."""
28
+
29
+ def get_response(
30
+ self,
31
+ request: query_editor.PrometheusApiQuery,
32
+ **kwargs: str,
33
+ ) -> api_clients.GarfApiResponse:
34
+ url = f'{self.endpoint}/api/v1/{request.resource_name}'
35
+ params = {}
36
+ for field in request.fields:
37
+ if field == 'timestamp':
38
+ continue
39
+ params['query'] = field
40
+ for element in request.filters:
41
+ key, value = element.split(' = ')
42
+ params[key.strip()] = value.strip().replace(' ', '')
43
+ headers = {k: v for k, v in kwargs.items() if not isinstance(v, bool)}
44
+ response = requests.get(url, params=params, headers=headers)
45
+ if response.status_code == self.OK:
46
+ results = response.json()
47
+ if request.resource_name == 'query_range':
48
+ results = results.get('data').get('result')
49
+ final_results = []
50
+ for r in results:
51
+ labels = r.get('metric')
52
+ for row in r.get('values'):
53
+ values = dict(zip(['timestamp', 'value'], row))
54
+ final_results.append({**values, **labels})
55
+
56
+ if request.resource_name == 'query':
57
+ results = results.get('data').get('result')
58
+ final_results = []
59
+ for row in results:
60
+ values = dict(zip(['timestamp', 'value'], row.get('value')))
61
+ labels = row.get('metric')
62
+ final_results.append({**values, **labels})
63
+ return api_clients.GarfApiResponse(results=final_results)
64
+ raise PrometheusApiClientError(
65
+ 'Failed to get data from Prometheus HTTP API, reason: ', response.text
66
+ )
@@ -0,0 +1,19 @@
1
+ # Copyright 2026 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from garf.core import exceptions
16
+
17
+
18
+ class PrometheusApiError(exceptions.GarfError):
19
+ """Prometheus Query API error."""
@@ -0,0 +1,19 @@
1
+ # Copyright 2026 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from garf.core import query_editor
16
+
17
+
18
+ class PrometheusApiQuery(query_editor.QuerySpecification):
19
+ """Query to Prometheus API."""
@@ -0,0 +1,45 @@
1
+ # Copyright 2026 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import garf.core
16
+ from garf.community.prometheus import api_clients, query_editor
17
+
18
+
19
+ class PrometheusApiReportFetcher(garf.core.ApiReportFetcher):
20
+ """Defines report fetcher for Prometheus API."""
21
+
22
+ alias = 'prometheus'
23
+
24
+ def __init__(
25
+ self,
26
+ api_client: api_clients.PrometheusApiClient | None = None,
27
+ parser: garf.core.parsers.DictParser = (
28
+ garf.core.parsers.NumericConverterDictParser
29
+ ),
30
+ query_spec: query_editor.PrometheusApiQuery = (
31
+ query_editor.PrometheusApiQuery
32
+ ),
33
+ parallel_threshold: int = 10,
34
+ **kwargs: str,
35
+ ) -> None:
36
+ """Initializes PrometheusApiReportFetcher."""
37
+ if not api_client:
38
+ api_client = api_clients.PrometheusApiClient(**kwargs)
39
+ self.parallel_threshold = parallel_threshold
40
+ super().__init__(
41
+ api_client=api_client,
42
+ parser=parser,
43
+ query_specification_builder=query_spec,
44
+ **kwargs,
45
+ )
@@ -0,0 +1,17 @@
1
+ # Copyright 2026 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from opentelemetry import trace
16
+
17
+ tracer = trace.get_tracer(instrumenting_module_name='garf.community.prometheus')
@@ -0,0 +1,88 @@
1
+ Metadata-Version: 2.4
2
+ Name: garf-prometheus
3
+ Version: 0.0.1
4
+ Summary: Garf implementation for Prometheus API
5
+ Author-email: Andrei Markin <amarkin@google.com>, "Google Inc. (gTech gPS CSE team)" <no-reply@google.com>
6
+ License: Apache 2.0
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Programming Language :: Python
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: garf-core[pandas]>=1.1.2
12
+ Requires-Dist: garf-io>=1.0.0
13
+ Provides-Extra: test
14
+ Requires-Dist: pytest; extra == "test"
15
+ Requires-Dist: pytest-cov; extra == "test"
16
+ Requires-Dist: pytest-mock; extra == "test"
17
+ Requires-Dist: python-dotenv; extra == "test"
18
+
19
+ # `garf` for Prometheus HTTP API
20
+
21
+ [![PyPI](https://img.shields.io/pypi/v/garf-prometheus?logo=pypi&logoColor=white&style=flat-square)](https://pypi.org/project/garf-prometheus)
22
+ [![Downloads PyPI](https://img.shields.io/pypi/dw/garf-prometheus?logo=pypi)](https://pypi.org/project/garf-prometheus/)
23
+
24
+ `garf-prometheus` simplifies fetching data from Prometheus HTTP API using SQL-like queries.
25
+
26
+ ## Prerequisites
27
+
28
+ * Running Prometheus instance
29
+
30
+ ## Installation
31
+
32
+ `pip install garf-prometheus`
33
+
34
+ ## Usage
35
+
36
+ ### Run as a library
37
+ ```
38
+ import os
39
+
40
+ from garf.io import writer
41
+ from garf.community.prometheus import PrometheusApiReportFetcher
42
+
43
+ query = """
44
+ SELECT
45
+ timestamp,
46
+ instance,
47
+ job,
48
+ value
49
+ FROM query
50
+ WHERE query = up
51
+ """
52
+
53
+ fetched_report = (
54
+ PrometheusApiReportFetcher(
55
+ endpoint='http://localhost:9090'
56
+ )
57
+ .fetch(query)
58
+ )
59
+
60
+ console_writer = writer.create_writer('console')
61
+ console_writer.write(fetched_report, 'query')
62
+ ```
63
+
64
+ ### Run via CLI
65
+
66
+ > Install `garf-executors` package to run queries via CLI (`pip install garf-executors`).
67
+
68
+ ```
69
+ garf <PATH_TO_QUERIES> --source prometheus \
70
+ --output <OUTPUT_TYPE> \
71
+ --prometheus.endpoint=http://localhost:9090
72
+ ```
73
+
74
+ where:
75
+
76
+ * `PATH_TO_QUERIES` - local or remove files containing queries
77
+ * `output` - output supported by [`garf-io` library](https://google.github.io/garf/usage/writers/).
78
+ * `SOURCE_PARAMETER=VALUE` - key-value pairs to refine fetching, check [available source parameters](#available-source-parameters).
79
+
80
+ ### Available source parameters
81
+
82
+ | name | values| comments |
83
+ |----- | ----- | -------- |
84
+ | `endpoint` | Base URL when Prometheus is running (`http://localhost:9090` by default) |
85
+
86
+ ## Documentation
87
+
88
+ You can find a documentation on `garf-prometheus` [here](https://google.github.io/garf/fetchers/prometheus/).
@@ -0,0 +1,14 @@
1
+ README.md
2
+ pyproject.toml
3
+ garf/community/prometheus/__init__.py
4
+ garf/community/prometheus/api_clients.py
5
+ garf/community/prometheus/exceptions.py
6
+ garf/community/prometheus/query_editor.py
7
+ garf/community/prometheus/report_fetcher.py
8
+ garf/community/prometheus/telemetry.py
9
+ garf_prometheus.egg-info/PKG-INFO
10
+ garf_prometheus.egg-info/SOURCES.txt
11
+ garf_prometheus.egg-info/dependency_links.txt
12
+ garf_prometheus.egg-info/entry_points.txt
13
+ garf_prometheus.egg-info/requires.txt
14
+ garf_prometheus.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [garf]
2
+ prometheus = garf.community.prometheus.report_fetcher
@@ -0,0 +1,8 @@
1
+ garf-core[pandas]>=1.1.2
2
+ garf-io>=1.0.0
3
+
4
+ [test]
5
+ pytest
6
+ pytest-cov
7
+ pytest-mock
8
+ python-dotenv
@@ -0,0 +1,41 @@
1
+ [build-system]
2
+ requires = ["setuptools >= 61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "garf-prometheus"
7
+ dependencies = [
8
+ "garf-core[pandas]>=1.1.2",
9
+ "garf-io>=1.0.0",
10
+ ]
11
+ authors = [
12
+ {name = "Andrei Markin", email = "amarkin@google.com"},
13
+ {name = "Google Inc. (gTech gPS CSE team)", email = "no-reply@google.com"},
14
+ ]
15
+ license = {text = "Apache 2.0"}
16
+ requires-python = ">=3.9"
17
+ description = "Garf implementation for Prometheus API"
18
+ readme = "README.md"
19
+ classifiers = [
20
+ "Development Status :: 4 - Beta",
21
+ "Programming Language :: Python"
22
+ ]
23
+
24
+ dynamic=["version"]
25
+
26
+ [tool.setuptools.dynamic]
27
+ version = {attr = "garf.community.prometheus.__version__"}
28
+
29
+ [project.entry-points.garf]
30
+ prometheus = "garf.community.prometheus.report_fetcher"
31
+
32
+ [project.optional-dependencies]
33
+ test = [
34
+ "pytest",
35
+ "pytest-cov",
36
+ "pytest-mock",
37
+ "python-dotenv",
38
+ ]
39
+ [tool.setuptools.packages.find]
40
+ where = ["."]
41
+ include=["garf.*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+