flexmetric 0.5.2__tar.gz → 0.5.4__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.
Files changed (25) hide show
  1. {flexmetric-0.5.2 → flexmetric-0.5.4}/PKG-INFO +125 -40
  2. {flexmetric-0.5.2 → flexmetric-0.5.4}/README.md +123 -39
  3. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric/metric_process/prometheus_agent.py +4 -1
  4. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric.egg-info/PKG-INFO +125 -40
  5. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric.egg-info/requires.txt +1 -0
  6. {flexmetric-0.5.2 → flexmetric-0.5.4}/setup.py +3 -2
  7. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric/__init__.py +0 -0
  8. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric/config/__init__.py +0 -0
  9. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric/config/configuration.py +0 -0
  10. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric/file_recognition/__init__.py +0 -0
  11. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric/file_recognition/exec_file.py +0 -0
  12. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric/logging_module/__init__.py +0 -0
  13. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric/logging_module/logger.py +0 -0
  14. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric/metric_process/__init__.py +0 -0
  15. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric/metric_process/database_connections.py +0 -0
  16. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric/metric_process/database_processing.py +0 -0
  17. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric/metric_process/expiring_queue.py +0 -0
  18. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric/metric_process/process_commands.py +0 -0
  19. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric/metric_process/queries_execution.py +0 -0
  20. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric/metric_process/views.py +0 -0
  21. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric.egg-info/SOURCES.txt +0 -0
  22. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric.egg-info/dependency_links.txt +0 -0
  23. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric.egg-info/entry_points.txt +0 -0
  24. {flexmetric-0.5.2 → flexmetric-0.5.4}/flexmetric.egg-info/top_level.txt +0 -0
  25. {flexmetric-0.5.2 → flexmetric-0.5.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexmetric
3
- Version: 0.5.2
3
+ Version: 0.5.4
4
4
  Summary: A secure flexible Prometheus exporter for commands, databases, functions.
5
5
  Home-page: https://github.com/nikhillingadhal1999/flexmetric
6
6
  Author: Nikhil Lingadhal
@@ -22,6 +22,7 @@ Requires-Dist: twine
22
22
  Requires-Dist: flask
23
23
  Requires-Dist: clickhouse-connect
24
24
  Requires-Dist: psycopg2-binary
25
+ Requires-Dist: ollama
25
26
  Dynamic: author
26
27
  Dynamic: classifier
27
28
  Dynamic: description
@@ -33,25 +34,38 @@ Dynamic: requires-dist
33
34
  Dynamic: requires-python
34
35
  Dynamic: summary
35
36
 
36
- # FlexMetric
37
+ FlexMetric is a lightweight, pluggable, and extensible Prometheus exporter that helps you collect, expose, and visualize custom metrics with minimal setup and maximum flexibility.
37
38
 
38
- FlexMetric is a lightweight, flexible, and extensible Prometheus exporter that allows you to securely expose system metrics, database query results, Python function outputs, and externally submitted metrics—via an optional Flask API with HTTPS support—as Prometheus-compatible metrics, all with minimal setup and maximum customization.
39
+ With FlexMetric, you can:
39
40
 
40
- ---
41
+ Run system commands and expose their output as metrics
42
+
43
+ Execute SQL queries against databases like SQLite, PostgreSQL, and ClickHouse
41
44
 
42
- ## Features
45
+ Call custom Python functions and export their results
43
46
 
44
- - Run shell commands and expose the results as Prometheus metrics.
45
- ➔ **Harmful commands (e.g., file deletion, system shutdown) are blocked for safety.**
46
- - Execute SQL queries (e.g., SQLite) and monitor database statistics.
47
- ➔ **Potentially dangerous queries (e.g., `DROP`, `DELETE`, `TRUNCATE`) are not allowed.**
48
- - Automatically discover and expose Python function outputs as metrics.
49
- - Expose an optional **Flask API** (`/update_metric`) to receive external metrics dynamically.
50
- - Modular and easy to extend—add your own custom integrations.
51
- - Built-in Prometheus HTTP server (`/metrics`) with configurable port.
52
- - **Supports HTTPS** to securely expose both metrics and API endpoints.
53
- - **Input sanitization** is performed to ensure only safe commands and queries are executed.
47
+ Receive externally submitted metrics via a secure Flask-based API with optional HTTPS (TLS)
48
+
49
+ All metrics are exposed in Prometheus-compatible format, making them ready for visualization in Grafana or any Prometheus-based monitoring stack.
50
+ ---
54
51
 
52
+ Paste your rich text content here. You can paste directly from Word or other rich text sources.
53
+
54
+ * Run **shell commands** and expose the results as **Prometheus metrics**.
55
+ ➔ _Harmful commands (e.g., file deletion, system shutdown) are blocked for safety._
56
+
57
+ * Execute **SQL queries** and monitor database statistics:
58
+
59
+ * **SQLite** (lightweight, file-based databases)
60
+ * **PostgreSQL** (robust, production-grade relational databases)
61
+ * **ClickHouse** (high-performance, analytical databases)
62
+ * Potentially dangerous queries (e.g., `DROP`, `DELETE`, `TRUNCATE`) are blocked by default.
63
+ * Automatically discover and expose **Python function outputs** as metrics.
64
+ * Expose an optional **Flask API** (`/update_metric`) to receive and update external metrics **dynamically**.
65
+ * Modular and **easy to extend**—add your own **custom integrations** with minimal effort.
66
+ * Built-in **Prometheus-compatible HTTP server** (`/metrics`) with configurable port.
67
+ * Supports **HTTPS** to securely expose both the metrics endpoint and API.
68
+ * Input **sanitization and validation** ensure only safe commands and queries are executed.
55
69
 
56
70
  ---
57
71
 
@@ -128,7 +142,31 @@ curl -X POST http://localhost:5000/update_metric \
128
142
  "labels": ["metric_type", "core"],
129
143
  "main_label": "cpu_usage_metric"
130
144
  }'
145
+ ```
146
+ Python client
147
+ ```python
148
+ import requests
149
+ import json
150
+
151
+ url = "http://localhost:5000/update_metric"
152
+ headers = {
153
+ "Content-Type": "application/json"
154
+ }
155
+ data = {
156
+ "result": [
157
+ {
158
+ "label": ["cpu", "core_1"],
159
+ "value": 42.5
160
+ }
161
+ ],
162
+ "labels": ["metric_type", "core"],
163
+ "main_label": "cpu_usage_metric"
164
+ }
131
165
 
166
+ response = requests.post(url, headers=headers, data=json.dumps(data))
167
+
168
+ print(f"Status Code: {response.status_code}")
169
+ print("Response:", response.text)
132
170
  ```
133
171
 
134
172
  ### Using flex metrics in secure mode
@@ -190,52 +228,99 @@ Filesystem Size Used Avail Use% Mounted on
190
228
  | `timeout_seconds` | Maximum time (in seconds) to wait for the command to complete. If it exceeds this time, the command is aborted. |
191
229
 
192
230
  ## Database mode
231
+ ## 🔗 Supported Database Connections
232
+
233
+ FlexMetric supports fetching and exposing metrics from multiple databases using a simple YAML-based configuration. This allows you to monitor data directly from your existing data sources without writing custom code.
234
+
235
+ ### ✅ Currently Supported Databases:
236
+
237
+ | Database | Type Name | Description |
238
+ |--------------|---------------|--------------------------------------------------|
239
+ | **SQLite** | `sqlite` | Lightweight, file-based relational database |
240
+ | **PostgreSQL** | `postgres` | Robust, production-grade relational database |
241
+ | **ClickHouse** | `clickhouse` | High-performance, analytical columnar database |
242
+
243
+ ---
244
+
245
+ ### 📄 Example `database.yaml` Configuration:
193
246
  file - database.yaml
194
247
  ```yaml
195
248
  databases:
196
- - id: "active_user_count"
249
+ - id: "local_sqlite"
250
+ type: "sqlite"
251
+ db_connection: "/path/to/example.db"
252
+
253
+ - id: "analytics_pg"
254
+ type: "postgres"
255
+ host: "localhost"
256
+ port: 5432
257
+ database: "metricsdb"
258
+ username: "postgres"
259
+ password: "postgres_password"
260
+ sslmode: "disable"
261
+ client_cert: "/path/to/cert.pem"
262
+ client_key: "/path/to/key.pem"
263
+ ca_cert: "/path/to/ca.pem"
264
+
265
+ - id: "clickhouse_cluster"
197
266
  type: "clickhouse"
198
267
  host: "localhost"
199
- port: 8123
268
+ port: 8443
200
269
  username: "default"
201
- password: ""
202
- client_cert: ""
203
- client_key: ""
204
- ca_cert: ""
205
-
206
- - id: "userdb"
207
- type: "sqlite"
208
- db_connection: "/path/to/my.db"
270
+ password: "clickhouse_password"
271
+ secure: true
272
+ client_cert: "/path/to/cert.pem"
273
+ client_key: "/path/to/key.pem"
274
+ ca_cert: "/path/to/ca.pem"
209
275
  ```
210
- file - queries.yaml
276
+
277
+ ## Supported Query Configuration
278
+
279
+ FlexMetric allows you to define custom queries in a simple YAML format. Each query is linked to a database using the `database_id` and can expose the results as Prometheus metrics with flexible labeling and value extraction.
280
+
281
+ ### Example `queries.yaml` Configuration:
282
+
211
283
  ```yaml
212
284
  commands:
213
- - id: "active_user_count"
214
- type: "clickhouse"
215
- database_id: "active_user_count"
285
+ - id: "active_user_count_pg"
286
+ type: "postgres"
287
+ database_id: "analytics_pg"
216
288
  query: |
217
289
  SELECT
218
290
  country AS country_name,
219
- COUNT() AS active_user_count
291
+ COUNT(*) AS active_user_count
220
292
  FROM users
221
- WHERE is_active = 1
222
- GROUP BY country
293
+ WHERE is_active = true
294
+ GROUP BY country;
223
295
  main_label: "active_user_count"
224
296
  labels: ["country_name"]
225
297
  value_column: "active_user_count"
226
298
 
227
- - id: "list_all_users_sqlite"
299
+ - id: "total_user_count_sqlite"
228
300
  type: "sqlite"
229
- database_id: "userdb"
301
+ database_id: "local_sqlite"
230
302
  query: |
231
303
  SELECT
232
- id,
233
- name
304
+ 'all' AS user_group,
305
+ COUNT(*) AS total_user_count
306
+ FROM users;
307
+ main_label: "total_user_count"
308
+ labels: ["user_group"]
309
+ value_column: "total_user_count"
310
+
311
+ - id: "clickhouse_user_summary"
312
+ type: "clickhouse"
313
+ database_id: "clickhouse_cluster"
314
+ query: |
315
+ SELECT
316
+ region AS region_name,
317
+ COUNT() AS user_count
234
318
  FROM users
235
- main_label: "user_list"
236
- labels: ["id", "name"]
237
- value_column: "id"
238
-
319
+ WHERE status = 'active'
320
+ GROUP BY region;
321
+ main_label: "clickhouse_user_count"
322
+ labels: ["region_name"]
323
+ value_column: "user_count"
239
324
  ```
240
325
  ## Functions mode
241
326
 
@@ -1,22 +1,35 @@
1
- # FlexMetric
1
+ FlexMetric is a lightweight, pluggable, and extensible Prometheus exporter that helps you collect, expose, and visualize custom metrics with minimal setup and maximum flexibility.
2
2
 
3
- FlexMetric is a lightweight, flexible, and extensible Prometheus exporter that allows you to securely expose system metrics, database query results, Python function outputs, and externally submitted metrics—via an optional Flask API with HTTPS support—as Prometheus-compatible metrics, all with minimal setup and maximum customization.
3
+ With FlexMetric, you can:
4
4
 
5
- ---
5
+ Run system commands and expose their output as metrics
6
+
7
+ Execute SQL queries against databases like SQLite, PostgreSQL, and ClickHouse
6
8
 
7
- ## Features
9
+ Call custom Python functions and export their results
8
10
 
9
- - Run shell commands and expose the results as Prometheus metrics.
10
- ➔ **Harmful commands (e.g., file deletion, system shutdown) are blocked for safety.**
11
- - Execute SQL queries (e.g., SQLite) and monitor database statistics.
12
- ➔ **Potentially dangerous queries (e.g., `DROP`, `DELETE`, `TRUNCATE`) are not allowed.**
13
- - Automatically discover and expose Python function outputs as metrics.
14
- - Expose an optional **Flask API** (`/update_metric`) to receive external metrics dynamically.
15
- - Modular and easy to extend—add your own custom integrations.
16
- - Built-in Prometheus HTTP server (`/metrics`) with configurable port.
17
- - **Supports HTTPS** to securely expose both metrics and API endpoints.
18
- - **Input sanitization** is performed to ensure only safe commands and queries are executed.
11
+ Receive externally submitted metrics via a secure Flask-based API with optional HTTPS (TLS)
12
+
13
+ All metrics are exposed in Prometheus-compatible format, making them ready for visualization in Grafana or any Prometheus-based monitoring stack.
14
+ ---
19
15
 
16
+ Paste your rich text content here. You can paste directly from Word or other rich text sources.
17
+
18
+ * Run **shell commands** and expose the results as **Prometheus metrics**.
19
+ ➔ _Harmful commands (e.g., file deletion, system shutdown) are blocked for safety._
20
+
21
+ * Execute **SQL queries** and monitor database statistics:
22
+
23
+ * **SQLite** (lightweight, file-based databases)
24
+ * **PostgreSQL** (robust, production-grade relational databases)
25
+ * **ClickHouse** (high-performance, analytical databases)
26
+ * Potentially dangerous queries (e.g., `DROP`, `DELETE`, `TRUNCATE`) are blocked by default.
27
+ * Automatically discover and expose **Python function outputs** as metrics.
28
+ * Expose an optional **Flask API** (`/update_metric`) to receive and update external metrics **dynamically**.
29
+ * Modular and **easy to extend**—add your own **custom integrations** with minimal effort.
30
+ * Built-in **Prometheus-compatible HTTP server** (`/metrics`) with configurable port.
31
+ * Supports **HTTPS** to securely expose both the metrics endpoint and API.
32
+ * Input **sanitization and validation** ensure only safe commands and queries are executed.
20
33
 
21
34
  ---
22
35
 
@@ -93,7 +106,31 @@ curl -X POST http://localhost:5000/update_metric \
93
106
  "labels": ["metric_type", "core"],
94
107
  "main_label": "cpu_usage_metric"
95
108
  }'
109
+ ```
110
+ Python client
111
+ ```python
112
+ import requests
113
+ import json
114
+
115
+ url = "http://localhost:5000/update_metric"
116
+ headers = {
117
+ "Content-Type": "application/json"
118
+ }
119
+ data = {
120
+ "result": [
121
+ {
122
+ "label": ["cpu", "core_1"],
123
+ "value": 42.5
124
+ }
125
+ ],
126
+ "labels": ["metric_type", "core"],
127
+ "main_label": "cpu_usage_metric"
128
+ }
96
129
 
130
+ response = requests.post(url, headers=headers, data=json.dumps(data))
131
+
132
+ print(f"Status Code: {response.status_code}")
133
+ print("Response:", response.text)
97
134
  ```
98
135
 
99
136
  ### Using flex metrics in secure mode
@@ -155,52 +192,99 @@ Filesystem Size Used Avail Use% Mounted on
155
192
  | `timeout_seconds` | Maximum time (in seconds) to wait for the command to complete. If it exceeds this time, the command is aborted. |
156
193
 
157
194
  ## Database mode
195
+ ## 🔗 Supported Database Connections
196
+
197
+ FlexMetric supports fetching and exposing metrics from multiple databases using a simple YAML-based configuration. This allows you to monitor data directly from your existing data sources without writing custom code.
198
+
199
+ ### ✅ Currently Supported Databases:
200
+
201
+ | Database | Type Name | Description |
202
+ |--------------|---------------|--------------------------------------------------|
203
+ | **SQLite** | `sqlite` | Lightweight, file-based relational database |
204
+ | **PostgreSQL** | `postgres` | Robust, production-grade relational database |
205
+ | **ClickHouse** | `clickhouse` | High-performance, analytical columnar database |
206
+
207
+ ---
208
+
209
+ ### 📄 Example `database.yaml` Configuration:
158
210
  file - database.yaml
159
211
  ```yaml
160
212
  databases:
161
- - id: "active_user_count"
213
+ - id: "local_sqlite"
214
+ type: "sqlite"
215
+ db_connection: "/path/to/example.db"
216
+
217
+ - id: "analytics_pg"
218
+ type: "postgres"
219
+ host: "localhost"
220
+ port: 5432
221
+ database: "metricsdb"
222
+ username: "postgres"
223
+ password: "postgres_password"
224
+ sslmode: "disable"
225
+ client_cert: "/path/to/cert.pem"
226
+ client_key: "/path/to/key.pem"
227
+ ca_cert: "/path/to/ca.pem"
228
+
229
+ - id: "clickhouse_cluster"
162
230
  type: "clickhouse"
163
231
  host: "localhost"
164
- port: 8123
232
+ port: 8443
165
233
  username: "default"
166
- password: ""
167
- client_cert: ""
168
- client_key: ""
169
- ca_cert: ""
170
-
171
- - id: "userdb"
172
- type: "sqlite"
173
- db_connection: "/path/to/my.db"
234
+ password: "clickhouse_password"
235
+ secure: true
236
+ client_cert: "/path/to/cert.pem"
237
+ client_key: "/path/to/key.pem"
238
+ ca_cert: "/path/to/ca.pem"
174
239
  ```
175
- file - queries.yaml
240
+
241
+ ## Supported Query Configuration
242
+
243
+ FlexMetric allows you to define custom queries in a simple YAML format. Each query is linked to a database using the `database_id` and can expose the results as Prometheus metrics with flexible labeling and value extraction.
244
+
245
+ ### Example `queries.yaml` Configuration:
246
+
176
247
  ```yaml
177
248
  commands:
178
- - id: "active_user_count"
179
- type: "clickhouse"
180
- database_id: "active_user_count"
249
+ - id: "active_user_count_pg"
250
+ type: "postgres"
251
+ database_id: "analytics_pg"
181
252
  query: |
182
253
  SELECT
183
254
  country AS country_name,
184
- COUNT() AS active_user_count
255
+ COUNT(*) AS active_user_count
185
256
  FROM users
186
- WHERE is_active = 1
187
- GROUP BY country
257
+ WHERE is_active = true
258
+ GROUP BY country;
188
259
  main_label: "active_user_count"
189
260
  labels: ["country_name"]
190
261
  value_column: "active_user_count"
191
262
 
192
- - id: "list_all_users_sqlite"
263
+ - id: "total_user_count_sqlite"
193
264
  type: "sqlite"
194
- database_id: "userdb"
265
+ database_id: "local_sqlite"
195
266
  query: |
196
267
  SELECT
197
- id,
198
- name
268
+ 'all' AS user_group,
269
+ COUNT(*) AS total_user_count
270
+ FROM users;
271
+ main_label: "total_user_count"
272
+ labels: ["user_group"]
273
+ value_column: "total_user_count"
274
+
275
+ - id: "clickhouse_user_summary"
276
+ type: "clickhouse"
277
+ database_id: "clickhouse_cluster"
278
+ query: |
279
+ SELECT
280
+ region AS region_name,
281
+ COUNT() AS user_count
199
282
  FROM users
200
- main_label: "user_list"
201
- labels: ["id", "name"]
202
- value_column: "id"
203
-
283
+ WHERE status = 'active'
284
+ GROUP BY region;
285
+ main_label: "clickhouse_user_count"
286
+ labels: ["region_name"]
287
+ value_column: "user_count"
204
288
  ```
205
289
  ## Functions mode
206
290
 
@@ -218,7 +218,10 @@ def measure(args):
218
218
  # print(label_dict)
219
219
 
220
220
  try:
221
- gauge.labels(**label_dict).set(convert_to_data_type(result["value"]))
221
+ if len(label_dict) > 0:
222
+ gauge.labels(**label_dict).set(convert_to_data_type(result["value"]))
223
+ else:
224
+ gauge.set(result["value"])
222
225
  except Exception as ex:
223
226
  logger.error(f"Failed to set gauge for labels {label_dict}: {ex}")
224
227
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexmetric
3
- Version: 0.5.2
3
+ Version: 0.5.4
4
4
  Summary: A secure flexible Prometheus exporter for commands, databases, functions.
5
5
  Home-page: https://github.com/nikhillingadhal1999/flexmetric
6
6
  Author: Nikhil Lingadhal
@@ -22,6 +22,7 @@ Requires-Dist: twine
22
22
  Requires-Dist: flask
23
23
  Requires-Dist: clickhouse-connect
24
24
  Requires-Dist: psycopg2-binary
25
+ Requires-Dist: ollama
25
26
  Dynamic: author
26
27
  Dynamic: classifier
27
28
  Dynamic: description
@@ -33,25 +34,38 @@ Dynamic: requires-dist
33
34
  Dynamic: requires-python
34
35
  Dynamic: summary
35
36
 
36
- # FlexMetric
37
+ FlexMetric is a lightweight, pluggable, and extensible Prometheus exporter that helps you collect, expose, and visualize custom metrics with minimal setup and maximum flexibility.
37
38
 
38
- FlexMetric is a lightweight, flexible, and extensible Prometheus exporter that allows you to securely expose system metrics, database query results, Python function outputs, and externally submitted metrics—via an optional Flask API with HTTPS support—as Prometheus-compatible metrics, all with minimal setup and maximum customization.
39
+ With FlexMetric, you can:
39
40
 
40
- ---
41
+ Run system commands and expose their output as metrics
42
+
43
+ Execute SQL queries against databases like SQLite, PostgreSQL, and ClickHouse
41
44
 
42
- ## Features
45
+ Call custom Python functions and export their results
43
46
 
44
- - Run shell commands and expose the results as Prometheus metrics.
45
- ➔ **Harmful commands (e.g., file deletion, system shutdown) are blocked for safety.**
46
- - Execute SQL queries (e.g., SQLite) and monitor database statistics.
47
- ➔ **Potentially dangerous queries (e.g., `DROP`, `DELETE`, `TRUNCATE`) are not allowed.**
48
- - Automatically discover and expose Python function outputs as metrics.
49
- - Expose an optional **Flask API** (`/update_metric`) to receive external metrics dynamically.
50
- - Modular and easy to extend—add your own custom integrations.
51
- - Built-in Prometheus HTTP server (`/metrics`) with configurable port.
52
- - **Supports HTTPS** to securely expose both metrics and API endpoints.
53
- - **Input sanitization** is performed to ensure only safe commands and queries are executed.
47
+ Receive externally submitted metrics via a secure Flask-based API with optional HTTPS (TLS)
48
+
49
+ All metrics are exposed in Prometheus-compatible format, making them ready for visualization in Grafana or any Prometheus-based monitoring stack.
50
+ ---
54
51
 
52
+ Paste your rich text content here. You can paste directly from Word or other rich text sources.
53
+
54
+ * Run **shell commands** and expose the results as **Prometheus metrics**.
55
+ ➔ _Harmful commands (e.g., file deletion, system shutdown) are blocked for safety._
56
+
57
+ * Execute **SQL queries** and monitor database statistics:
58
+
59
+ * **SQLite** (lightweight, file-based databases)
60
+ * **PostgreSQL** (robust, production-grade relational databases)
61
+ * **ClickHouse** (high-performance, analytical databases)
62
+ * Potentially dangerous queries (e.g., `DROP`, `DELETE`, `TRUNCATE`) are blocked by default.
63
+ * Automatically discover and expose **Python function outputs** as metrics.
64
+ * Expose an optional **Flask API** (`/update_metric`) to receive and update external metrics **dynamically**.
65
+ * Modular and **easy to extend**—add your own **custom integrations** with minimal effort.
66
+ * Built-in **Prometheus-compatible HTTP server** (`/metrics`) with configurable port.
67
+ * Supports **HTTPS** to securely expose both the metrics endpoint and API.
68
+ * Input **sanitization and validation** ensure only safe commands and queries are executed.
55
69
 
56
70
  ---
57
71
 
@@ -128,7 +142,31 @@ curl -X POST http://localhost:5000/update_metric \
128
142
  "labels": ["metric_type", "core"],
129
143
  "main_label": "cpu_usage_metric"
130
144
  }'
145
+ ```
146
+ Python client
147
+ ```python
148
+ import requests
149
+ import json
150
+
151
+ url = "http://localhost:5000/update_metric"
152
+ headers = {
153
+ "Content-Type": "application/json"
154
+ }
155
+ data = {
156
+ "result": [
157
+ {
158
+ "label": ["cpu", "core_1"],
159
+ "value": 42.5
160
+ }
161
+ ],
162
+ "labels": ["metric_type", "core"],
163
+ "main_label": "cpu_usage_metric"
164
+ }
131
165
 
166
+ response = requests.post(url, headers=headers, data=json.dumps(data))
167
+
168
+ print(f"Status Code: {response.status_code}")
169
+ print("Response:", response.text)
132
170
  ```
133
171
 
134
172
  ### Using flex metrics in secure mode
@@ -190,52 +228,99 @@ Filesystem Size Used Avail Use% Mounted on
190
228
  | `timeout_seconds` | Maximum time (in seconds) to wait for the command to complete. If it exceeds this time, the command is aborted. |
191
229
 
192
230
  ## Database mode
231
+ ## 🔗 Supported Database Connections
232
+
233
+ FlexMetric supports fetching and exposing metrics from multiple databases using a simple YAML-based configuration. This allows you to monitor data directly from your existing data sources without writing custom code.
234
+
235
+ ### ✅ Currently Supported Databases:
236
+
237
+ | Database | Type Name | Description |
238
+ |--------------|---------------|--------------------------------------------------|
239
+ | **SQLite** | `sqlite` | Lightweight, file-based relational database |
240
+ | **PostgreSQL** | `postgres` | Robust, production-grade relational database |
241
+ | **ClickHouse** | `clickhouse` | High-performance, analytical columnar database |
242
+
243
+ ---
244
+
245
+ ### 📄 Example `database.yaml` Configuration:
193
246
  file - database.yaml
194
247
  ```yaml
195
248
  databases:
196
- - id: "active_user_count"
249
+ - id: "local_sqlite"
250
+ type: "sqlite"
251
+ db_connection: "/path/to/example.db"
252
+
253
+ - id: "analytics_pg"
254
+ type: "postgres"
255
+ host: "localhost"
256
+ port: 5432
257
+ database: "metricsdb"
258
+ username: "postgres"
259
+ password: "postgres_password"
260
+ sslmode: "disable"
261
+ client_cert: "/path/to/cert.pem"
262
+ client_key: "/path/to/key.pem"
263
+ ca_cert: "/path/to/ca.pem"
264
+
265
+ - id: "clickhouse_cluster"
197
266
  type: "clickhouse"
198
267
  host: "localhost"
199
- port: 8123
268
+ port: 8443
200
269
  username: "default"
201
- password: ""
202
- client_cert: ""
203
- client_key: ""
204
- ca_cert: ""
205
-
206
- - id: "userdb"
207
- type: "sqlite"
208
- db_connection: "/path/to/my.db"
270
+ password: "clickhouse_password"
271
+ secure: true
272
+ client_cert: "/path/to/cert.pem"
273
+ client_key: "/path/to/key.pem"
274
+ ca_cert: "/path/to/ca.pem"
209
275
  ```
210
- file - queries.yaml
276
+
277
+ ## Supported Query Configuration
278
+
279
+ FlexMetric allows you to define custom queries in a simple YAML format. Each query is linked to a database using the `database_id` and can expose the results as Prometheus metrics with flexible labeling and value extraction.
280
+
281
+ ### Example `queries.yaml` Configuration:
282
+
211
283
  ```yaml
212
284
  commands:
213
- - id: "active_user_count"
214
- type: "clickhouse"
215
- database_id: "active_user_count"
285
+ - id: "active_user_count_pg"
286
+ type: "postgres"
287
+ database_id: "analytics_pg"
216
288
  query: |
217
289
  SELECT
218
290
  country AS country_name,
219
- COUNT() AS active_user_count
291
+ COUNT(*) AS active_user_count
220
292
  FROM users
221
- WHERE is_active = 1
222
- GROUP BY country
293
+ WHERE is_active = true
294
+ GROUP BY country;
223
295
  main_label: "active_user_count"
224
296
  labels: ["country_name"]
225
297
  value_column: "active_user_count"
226
298
 
227
- - id: "list_all_users_sqlite"
299
+ - id: "total_user_count_sqlite"
228
300
  type: "sqlite"
229
- database_id: "userdb"
301
+ database_id: "local_sqlite"
230
302
  query: |
231
303
  SELECT
232
- id,
233
- name
304
+ 'all' AS user_group,
305
+ COUNT(*) AS total_user_count
306
+ FROM users;
307
+ main_label: "total_user_count"
308
+ labels: ["user_group"]
309
+ value_column: "total_user_count"
310
+
311
+ - id: "clickhouse_user_summary"
312
+ type: "clickhouse"
313
+ database_id: "clickhouse_cluster"
314
+ query: |
315
+ SELECT
316
+ region AS region_name,
317
+ COUNT() AS user_count
234
318
  FROM users
235
- main_label: "user_list"
236
- labels: ["id", "name"]
237
- value_column: "id"
238
-
319
+ WHERE status = 'active'
320
+ GROUP BY region;
321
+ main_label: "clickhouse_user_count"
322
+ labels: ["region_name"]
323
+ value_column: "user_count"
239
324
  ```
240
325
  ## Functions mode
241
326
 
@@ -7,3 +7,4 @@ twine
7
7
  flask
8
8
  clickhouse-connect
9
9
  psycopg2-binary
10
+ ollama
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="flexmetric",
5
- version="0.5.2",
5
+ version="0.5.4",
6
6
  author="Nikhil Lingadhal",
7
7
  description="A secure flexible Prometheus exporter for commands, databases, functions.",
8
8
  long_description=open("README.md").read(),
@@ -24,7 +24,8 @@ setup(
24
24
  "twine",
25
25
  "flask",
26
26
  "clickhouse-connect",
27
- "psycopg2-binary"
27
+ "psycopg2-binary",
28
+ "ollama"
28
29
  ],
29
30
  entry_points={
30
31
  "console_scripts": [
File without changes