flexmetric 0.4.0__tar.gz → 0.4.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.
- {flexmetric-0.4.0 → flexmetric-0.4.2}/PKG-INFO +13 -6
- {flexmetric-0.4.0 → flexmetric-0.4.2}/README.md +12 -5
- flexmetric-0.4.2/flexmetric/metric_process/views.py +76 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric.egg-info/PKG-INFO +13 -6
- {flexmetric-0.4.0 → flexmetric-0.4.2}/setup.py +1 -1
- flexmetric-0.4.0/flexmetric/metric_process/views.py +0 -54
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric/__init__.py +0 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric/config/__init__.py +0 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric/config/configuration.py +0 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric/file_recognition/__init__.py +0 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric/file_recognition/exec_file.py +0 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric/logging_module/__init__.py +0 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric/logging_module/logger.py +0 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric/metric_process/__init__.py +0 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric/metric_process/database_processing.py +0 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric/metric_process/expiring_queue.py +0 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric/metric_process/process_commands.py +0 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric/metric_process/prometheus_agent.py +0 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric.egg-info/SOURCES.txt +0 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric.egg-info/dependency_links.txt +0 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric.egg-info/entry_points.txt +0 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric.egg-info/requires.txt +0 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/flexmetric.egg-info/top_level.txt +0 -0
- {flexmetric-0.4.0 → flexmetric-0.4.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: flexmetric
|
3
|
-
Version: 0.4.
|
3
|
+
Version: 0.4.2
|
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
|
@@ -118,9 +118,13 @@ curl -X POST http://localhost:5000/update_metric \
|
|
118
118
|
-H "Content-Type: application/json" \
|
119
119
|
-d '{
|
120
120
|
"result": [
|
121
|
-
{
|
121
|
+
{
|
122
|
+
"label": ["cpu", "core_1"],
|
123
|
+
"value": 42.5
|
124
|
+
}
|
122
125
|
],
|
123
|
-
"labels": ["
|
126
|
+
"labels": ["metric_type", "core"],
|
127
|
+
"main_label": "cpu_usage_metric"
|
124
128
|
}'
|
125
129
|
|
126
130
|
```
|
@@ -142,11 +146,14 @@ curl -k -X POST https://localhost:5000/update_metric \
|
|
142
146
|
-H "Content-Type: application/json" \
|
143
147
|
-d '{
|
144
148
|
"result": [
|
145
|
-
{
|
149
|
+
{
|
150
|
+
"label": ["cpu", "core_1"],
|
151
|
+
"value": 42.5
|
152
|
+
}
|
146
153
|
],
|
147
|
-
"labels": ["
|
154
|
+
"labels": ["metric_type", "core"],
|
155
|
+
"main_label": "cpu_usage_metric"
|
148
156
|
}'
|
149
|
-
|
150
157
|
```
|
151
158
|
|
152
159
|
### commands.yaml
|
@@ -85,9 +85,13 @@ curl -X POST http://localhost:5000/update_metric \
|
|
85
85
|
-H "Content-Type: application/json" \
|
86
86
|
-d '{
|
87
87
|
"result": [
|
88
|
-
{
|
88
|
+
{
|
89
|
+
"label": ["cpu", "core_1"],
|
90
|
+
"value": 42.5
|
91
|
+
}
|
89
92
|
],
|
90
|
-
"labels": ["
|
93
|
+
"labels": ["metric_type", "core"],
|
94
|
+
"main_label": "cpu_usage_metric"
|
91
95
|
}'
|
92
96
|
|
93
97
|
```
|
@@ -109,11 +113,14 @@ curl -k -X POST https://localhost:5000/update_metric \
|
|
109
113
|
-H "Content-Type: application/json" \
|
110
114
|
-d '{
|
111
115
|
"result": [
|
112
|
-
{
|
116
|
+
{
|
117
|
+
"label": ["cpu", "core_1"],
|
118
|
+
"value": 42.5
|
119
|
+
}
|
113
120
|
],
|
114
|
-
"labels": ["
|
121
|
+
"labels": ["metric_type", "core"],
|
122
|
+
"main_label": "cpu_usage_metric"
|
115
123
|
}'
|
116
|
-
|
117
124
|
```
|
118
125
|
|
119
126
|
### 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.
|
3
|
+
Version: 0.4.2
|
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
|
@@ -118,9 +118,13 @@ curl -X POST http://localhost:5000/update_metric \
|
|
118
118
|
-H "Content-Type: application/json" \
|
119
119
|
-d '{
|
120
120
|
"result": [
|
121
|
-
{
|
121
|
+
{
|
122
|
+
"label": ["cpu", "core_1"],
|
123
|
+
"value": 42.5
|
124
|
+
}
|
122
125
|
],
|
123
|
-
"labels": ["
|
126
|
+
"labels": ["metric_type", "core"],
|
127
|
+
"main_label": "cpu_usage_metric"
|
124
128
|
}'
|
125
129
|
|
126
130
|
```
|
@@ -142,11 +146,14 @@ curl -k -X POST https://localhost:5000/update_metric \
|
|
142
146
|
-H "Content-Type: application/json" \
|
143
147
|
-d '{
|
144
148
|
"result": [
|
145
|
-
{
|
149
|
+
{
|
150
|
+
"label": ["cpu", "core_1"],
|
151
|
+
"value": 42.5
|
152
|
+
}
|
146
153
|
],
|
147
|
-
"labels": ["
|
154
|
+
"labels": ["metric_type", "core"],
|
155
|
+
"main_label": "cpu_usage_metric"
|
148
156
|
}'
|
149
|
-
|
150
157
|
```
|
151
158
|
|
152
159
|
### 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.
|
5
|
+
version="0.4.2",
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|