flexmetric 0.5.1__tar.gz → 0.5.2__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.1 → flexmetric-0.5.2}/PKG-INFO +2 -1
  2. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric/metric_process/database_connections.py +45 -1
  3. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric/metric_process/database_processing.py +10 -4
  4. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric/metric_process/queries_execution.py +16 -0
  5. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric.egg-info/PKG-INFO +2 -1
  6. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric.egg-info/requires.txt +1 -0
  7. {flexmetric-0.5.1 → flexmetric-0.5.2}/setup.py +3 -2
  8. {flexmetric-0.5.1 → flexmetric-0.5.2}/README.md +0 -0
  9. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric/__init__.py +0 -0
  10. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric/config/__init__.py +0 -0
  11. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric/config/configuration.py +0 -0
  12. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric/file_recognition/__init__.py +0 -0
  13. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric/file_recognition/exec_file.py +0 -0
  14. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric/logging_module/__init__.py +0 -0
  15. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric/logging_module/logger.py +0 -0
  16. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric/metric_process/__init__.py +0 -0
  17. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric/metric_process/expiring_queue.py +0 -0
  18. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric/metric_process/process_commands.py +0 -0
  19. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric/metric_process/prometheus_agent.py +0 -0
  20. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric/metric_process/views.py +0 -0
  21. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric.egg-info/SOURCES.txt +0 -0
  22. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric.egg-info/dependency_links.txt +0 -0
  23. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric.egg-info/entry_points.txt +0 -0
  24. {flexmetric-0.5.1 → flexmetric-0.5.2}/flexmetric.egg-info/top_level.txt +0 -0
  25. {flexmetric-0.5.1 → flexmetric-0.5.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexmetric
3
- Version: 0.5.1
3
+ Version: 0.5.2
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
@@ -21,6 +21,7 @@ Requires-Dist: wheel
21
21
  Requires-Dist: twine
22
22
  Requires-Dist: flask
23
23
  Requires-Dist: clickhouse-connect
24
+ Requires-Dist: psycopg2-binary
24
25
  Dynamic: author
25
26
  Dynamic: classifier
26
27
  Dynamic: description
@@ -2,11 +2,55 @@ import clickhouse_connect
2
2
  import sqlite3
3
3
  from flexmetric.logging_module.logger import get_logger
4
4
  import os
5
+ import psycopg2
5
6
 
6
- logger = get_logger(__name__)
7
7
 
8
+ logger = get_logger(__name__)
8
9
  logger.info("database logs")
9
10
 
11
+ def create_postgres_client(db_conf: dict):
12
+ host = db_conf.get('host', 'localhost')
13
+ port = db_conf.get('port', 5432)
14
+ database = db_conf.get('database')
15
+ username = db_conf.get('username', 'postgres')
16
+ password = db_conf.get('password', '')
17
+
18
+ sslmode = db_conf.get('sslmode', 'prefer')
19
+ sslcert = db_conf.get('client_cert')
20
+ sslkey = db_conf.get('client_key')
21
+ sslrootcert = db_conf.get('ca_cert')
22
+
23
+ if not database:
24
+ raise ValueError("Missing 'database' name in PostgreSQL configuration")
25
+
26
+ conn_params = {
27
+ 'host': host,
28
+ 'port': port,
29
+ 'dbname': database,
30
+ 'user': username,
31
+ 'password': password,
32
+ 'sslmode': sslmode
33
+ }
34
+
35
+ if sslcert and sslkey and sslrootcert:
36
+ if not (os.path.isfile(sslcert) and os.path.isfile(sslkey) and os.path.isfile(sslrootcert)):
37
+ raise FileNotFoundError("One or more SSL certificate files not found.")
38
+ conn_params.update({
39
+ 'sslcert': sslcert,
40
+ 'sslkey': sslkey,
41
+ 'sslrootcert': sslrootcert,
42
+ 'sslmode': 'verify-full'
43
+ })
44
+
45
+ try:
46
+ conn = psycopg2.connect(**conn_params)
47
+ logger.info(f"PostgreSQL connection to '{database}' established successfully (SSL: {'Yes' if 'sslcert' in conn_params else 'No'})")
48
+ return conn
49
+
50
+ except Exception as e:
51
+ logger.error(f"Failed to create PostgreSQL client: {e}")
52
+ raise
53
+
10
54
  def create_clickhouse_client(db_conf):
11
55
  id = db_conf.get('id')
12
56
  host = db_conf.get('host', 'localhost')
@@ -1,7 +1,7 @@
1
1
  import yaml
2
2
  import re
3
- from flexmetric.metric_process.database_connections import create_clickhouse_client,create_sqlite_client
4
- from flexmetric.metric_process.queries_execution import execute_clickhouse_command,execute_sqlite_query
3
+ from flexmetric.metric_process.database_connections import create_clickhouse_client,create_sqlite_client,create_postgres_client
4
+ from flexmetric.metric_process.queries_execution import execute_clickhouse_command,execute_sqlite_query,execute_postgres_query
5
5
  from flexmetric.logging_module.logger import get_logger
6
6
  logger = get_logger(__name__)
7
7
 
@@ -59,7 +59,10 @@ def create_clients_from_config(config_file: str):
59
59
  client = create_sqlite_client(db_conf)
60
60
  clients[db_id] = client
61
61
  logger.info(clients)
62
-
62
+ elif db_type == 'postgres':
63
+ client = create_postgres_client(db_conf)
64
+ clients[db_id] = client
65
+ logger.info(clients)
63
66
  else:
64
67
  logger.info(f"Unsupported database type: {db_type}")
65
68
 
@@ -123,10 +126,13 @@ def execute_commands(clients: dict, commands_file: str):
123
126
  response ,column_names = execute_sqlite_query(client,query)
124
127
  result = process_and_get_value(cmd,response,column_names)
125
128
  results.append(result)
129
+ elif db_type == 'postgres':
130
+ response ,column_names = execute_postgres_query(client,query)
131
+ result = process_and_get_value(cmd,response,column_names)
132
+ results.append(result)
126
133
  else:
127
134
  logger.info(f"Unknown type '{db_type}' in command '{cmd_id}'")
128
135
  continue
129
-
130
136
  except Exception as e:
131
137
  logger.error(f"Command '{cmd_id}' failed: {e}")
132
138
  return results
@@ -21,4 +21,20 @@ def execute_sqlite_query(conn, query):
21
21
  return rows, column_names
22
22
  except Exception as ex:
23
23
  logger.error(f"Exception during SQLite query: {ex}")
24
+ return [], []
25
+
26
+ def execute_postgres_query(conn, query):
27
+ try:
28
+ cursor = conn.cursor()
29
+ cursor.execute(query)
30
+
31
+ rows = cursor.fetchall()
32
+ column_names = [desc[0] for desc in cursor.description]
33
+
34
+ logger.info(f"Query executed successfully. Rows fetched: {len(rows)}")
35
+
36
+ return rows, column_names
37
+
38
+ except Exception as ex:
39
+ logger.error(f"Exception during Postgres query: {ex}")
24
40
  return [], []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexmetric
3
- Version: 0.5.1
3
+ Version: 0.5.2
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
@@ -21,6 +21,7 @@ Requires-Dist: wheel
21
21
  Requires-Dist: twine
22
22
  Requires-Dist: flask
23
23
  Requires-Dist: clickhouse-connect
24
+ Requires-Dist: psycopg2-binary
24
25
  Dynamic: author
25
26
  Dynamic: classifier
26
27
  Dynamic: description
@@ -6,3 +6,4 @@ wheel
6
6
  twine
7
7
  flask
8
8
  clickhouse-connect
9
+ psycopg2-binary
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="flexmetric",
5
- version="0.5.1",
5
+ version="0.5.2",
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(),
@@ -23,7 +23,8 @@ setup(
23
23
  "wheel",
24
24
  "twine",
25
25
  "flask",
26
- "clickhouse-connect"
26
+ "clickhouse-connect",
27
+ "psycopg2-binary"
27
28
  ],
28
29
  entry_points={
29
30
  "console_scripts": [
File without changes
File without changes