flexmetric 0.4.0__tar.gz → 0.4.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.
Files changed (24) hide show
  1. {flexmetric-0.4.0 → flexmetric-0.4.1}/PKG-INFO +8 -5
  2. {flexmetric-0.4.0 → flexmetric-0.4.1}/README.md +7 -4
  3. flexmetric-0.4.1/flexmetric/metric_process/views.py +76 -0
  4. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric.egg-info/PKG-INFO +8 -5
  5. {flexmetric-0.4.0 → flexmetric-0.4.1}/setup.py +1 -1
  6. flexmetric-0.4.0/flexmetric/metric_process/views.py +0 -54
  7. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric/__init__.py +0 -0
  8. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric/config/__init__.py +0 -0
  9. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric/config/configuration.py +0 -0
  10. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric/file_recognition/__init__.py +0 -0
  11. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric/file_recognition/exec_file.py +0 -0
  12. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric/logging_module/__init__.py +0 -0
  13. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric/logging_module/logger.py +0 -0
  14. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric/metric_process/__init__.py +0 -0
  15. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric/metric_process/database_processing.py +0 -0
  16. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric/metric_process/expiring_queue.py +0 -0
  17. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric/metric_process/process_commands.py +0 -0
  18. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric/metric_process/prometheus_agent.py +0 -0
  19. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric.egg-info/SOURCES.txt +0 -0
  20. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric.egg-info/dependency_links.txt +0 -0
  21. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric.egg-info/entry_points.txt +0 -0
  22. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric.egg-info/requires.txt +0 -0
  23. {flexmetric-0.4.0 → flexmetric-0.4.1}/flexmetric.egg-info/top_level.txt +0 -0
  24. {flexmetric-0.4.0 → flexmetric-0.4.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexmetric
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: A secure flexible Prometheus exporter for commands, databases, functions, and scripts.
5
5
  Home-page: https://github.com/nikhillingadhal1999/flexmetric
6
6
  Author: Nikhil Lingadhal
@@ -138,15 +138,18 @@ https://localhost:5000/update_metric
138
138
 
139
139
  ### Submitting a Metric to the Flask API
140
140
  ```bash
141
- curl -k -X POST https://localhost:5000/update_metric \
141
+ curl -X POST http://localhost:5000/update_metric \
142
142
  -H "Content-Type: application/json" \
143
143
  -d '{
144
144
  "result": [
145
- { "label": "cpu_usage", "value": 42.5 }
145
+ {
146
+ "label": ["cpu", "core_1"],
147
+ "value": 42.5
148
+ }
146
149
  ],
147
- "labels": ["cpu"]
150
+ "labels": ["metric_type", "core"],
151
+ "main_label": "cpu_usage_metric"
148
152
  }'
149
-
150
153
  ```
151
154
 
152
155
  ### commands.yaml
@@ -105,15 +105,18 @@ https://localhost:5000/update_metric
105
105
 
106
106
  ### Submitting a Metric to the Flask API
107
107
  ```bash
108
- curl -k -X POST https://localhost:5000/update_metric \
108
+ curl -X POST http://localhost:5000/update_metric \
109
109
  -H "Content-Type: application/json" \
110
110
  -d '{
111
111
  "result": [
112
- { "label": "cpu_usage", "value": 42.5 }
112
+ {
113
+ "label": ["cpu", "core_1"],
114
+ "value": 42.5
115
+ }
113
116
  ],
114
- "labels": ["cpu"]
117
+ "labels": ["metric_type", "core"],
118
+ "main_label": "cpu_usage_metric"
115
119
  }'
116
-
117
120
  ```
118
121
 
119
122
  ### commands.yaml
@@ -0,0 +1,76 @@
1
+ from flask import Flask, request, jsonify, Response
2
+ from flexmetric.metric_process.expiring_queue import metric_queue
3
+ import argparse
4
+ from prometheus_client import generate_latest, REGISTRY, CONTENT_TYPE_LATEST
5
+
6
+ app = Flask(__name__)
7
+
8
+
9
+ @app.route('/metrics')
10
+ def metrics():
11
+ return Response(generate_latest(REGISTRY), mimetype=CONTENT_TYPE_LATEST)
12
+
13
+
14
+ def add_update_metric_route():
15
+ @app.route("/update_metric", methods=["POST"])
16
+ def update_metric():
17
+ try:
18
+ data = request.get_json(force=True)
19
+
20
+ # Top-level validation
21
+ if not isinstance(data, dict):
22
+ return jsonify({"status": "invalid structure", "error": "Top-level JSON must be an object"}), 400
23
+
24
+ required_keys = {"result", "labels", "main_label"}
25
+ if not required_keys.issubset(data):
26
+ return jsonify({"status": "invalid structure", "error": f"Missing keys: {required_keys - set(data)}"}), 400
27
+
28
+ result = data.get("result")
29
+ labels = data.get("labels")
30
+ main_label = data.get("main_label")
31
+
32
+ # Type validation
33
+ if not isinstance(result, list) or not all(isinstance(item, dict) for item in result):
34
+ return jsonify({"status": "invalid result", "error": "Result must be a list of dictionaries"}), 400
35
+
36
+ if not isinstance(labels, list) or not all(isinstance(label, str) for label in labels):
37
+ return jsonify({"status": "invalid labels", "error": "Labels must be a list of strings"}), 400
38
+
39
+ if not isinstance(main_label, str) or not main_label.strip():
40
+ return jsonify({"status": "invalid main_label", "error": "main_label must be a non-empty string"}), 400
41
+
42
+ for idx, item in enumerate(result):
43
+ if "label" not in item or "value" not in item:
44
+ return jsonify({"status": "invalid result item", "error": f"Item {idx} missing 'label' or 'value'"}), 400
45
+
46
+ label_values = item["label"]
47
+ value = item["value"]
48
+
49
+ if not isinstance(label_values, list) or not all(isinstance(lv, str) for lv in label_values):
50
+ return jsonify({"status": "invalid label", "error": f"Item {idx} 'label' must be list of strings"}), 400
51
+
52
+ if len(label_values) != len(labels):
53
+ return jsonify({
54
+ "status": "label count mismatch",
55
+ "error": f"Item {idx} label count ({len(label_values)}) does not match labels length ({len(labels)})"
56
+ }), 400
57
+
58
+ try:
59
+ float(value) # Validate numeric value
60
+ except (ValueError, TypeError):
61
+ return jsonify({"status": "invalid value", "error": f"Item {idx} value must be numeric"}), 400
62
+
63
+ # If all checks pass, queue the metric
64
+ metric_queue.put(data)
65
+ print("Queued:", data)
66
+
67
+ return jsonify({"status": "success"}), 200
68
+
69
+ except Exception as e:
70
+ return jsonify({"status": "error", "message": str(e)}), 500
71
+
72
+
73
+ def run_flask(host, port):
74
+ app.run(host=host, port=port)
75
+ def secure_flask_run(args):
76
+ app.run(host=args.host, port=args.port, ssl_context=(args.ssl_cert, args.ssl_key))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexmetric
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: A secure flexible Prometheus exporter for commands, databases, functions, and scripts.
5
5
  Home-page: https://github.com/nikhillingadhal1999/flexmetric
6
6
  Author: Nikhil Lingadhal
@@ -138,15 +138,18 @@ https://localhost:5000/update_metric
138
138
 
139
139
  ### Submitting a Metric to the Flask API
140
140
  ```bash
141
- curl -k -X POST https://localhost:5000/update_metric \
141
+ curl -X POST http://localhost:5000/update_metric \
142
142
  -H "Content-Type: application/json" \
143
143
  -d '{
144
144
  "result": [
145
- { "label": "cpu_usage", "value": 42.5 }
145
+ {
146
+ "label": ["cpu", "core_1"],
147
+ "value": 42.5
148
+ }
146
149
  ],
147
- "labels": ["cpu"]
150
+ "labels": ["metric_type", "core"],
151
+ "main_label": "cpu_usage_metric"
148
152
  }'
149
-
150
153
  ```
151
154
 
152
155
  ### commands.yaml
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="flexmetric",
5
- version="0.4.0",
5
+ version="0.4.1",
6
6
  author="Nikhil Lingadhal",
7
7
  description="A secure flexible Prometheus exporter for commands, databases, functions, and scripts.",
8
8
  long_description=open("README.md").read(),
@@ -1,54 +0,0 @@
1
- from flask import Flask, request, jsonify, Response
2
- from flexmetric.metric_process.expiring_queue import metric_queue
3
- import argparse
4
- from prometheus_client import generate_latest, REGISTRY, CONTENT_TYPE_LATEST
5
-
6
- app = Flask(__name__)
7
-
8
-
9
- @app.route('/metrics')
10
- def metrics():
11
- return Response(generate_latest(REGISTRY), mimetype=CONTENT_TYPE_LATEST)
12
-
13
-
14
- def add_update_metric_route():
15
- @app.route("/update_metric", methods=["POST"])
16
- def update_metric():
17
- try:
18
- data = request.get_json()
19
-
20
- # Validate top-level structure
21
- if not data or "result" not in data or "labels" not in data or "main_label" not in data:
22
- return jsonify({"status": "invalid structure"}), 400
23
-
24
- result = data["result"]
25
- labels = data["labels"]
26
- main_label = data["main_label"]
27
-
28
- # Validate types
29
- if not isinstance(result, list) or not isinstance(labels, list) or not isinstance(main_label, str):
30
- return jsonify({"status": "invalid types"}), 400
31
-
32
- for item in result:
33
- if "label" not in item or "value" not in item:
34
- return jsonify({"status": "invalid result item"}), 400
35
- if not isinstance(item["label"], list):
36
- return jsonify({"status": "label must be list"}), 400
37
-
38
- if len(item["label"]) != len(labels):
39
- return jsonify({"status": "label count mismatch"}), 400
40
-
41
- # If everything is valid, queue the data
42
- metric_queue.put(data)
43
- print(metric_queue)
44
-
45
- return jsonify({"status": "success"}), 200
46
-
47
- except Exception as e:
48
- return jsonify({"status": "error", "message": str(e)}), 500
49
-
50
-
51
- def run_flask(host, port):
52
- app.run(host=host, port=port)
53
- def secure_flask_run(args):
54
- app.run(host=args.host, port=args.port, ssl_context=(args.ssl_cert, args.ssl_key))
File without changes