flexmetric 0.1.3__py3-none-any.whl → 0.1.4__py3-none-any.whl
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/metric_process/prometheus_agent.py +4 -2
- {flexmetric-0.1.3.dist-info → flexmetric-0.1.4.dist-info}/METADATA +1 -1
- {flexmetric-0.1.3.dist-info → flexmetric-0.1.4.dist-info}/RECORD +6 -7
- flexmetric/metric_process/process_commands.py +0 -73
- {flexmetric-0.1.3.dist-info → flexmetric-0.1.4.dist-info}/WHEEL +0 -0
- {flexmetric-0.1.3.dist-info → flexmetric-0.1.4.dist-info}/entry_points.txt +0 -0
- {flexmetric-0.1.3.dist-info → flexmetric-0.1.4.dist-info}/top_level.txt +0 -0
@@ -96,7 +96,8 @@ def measure(init_flag,args):
|
|
96
96
|
exec_result.extend(function_results)
|
97
97
|
if args.commands:
|
98
98
|
cmd_results = process_commands(args.commands_config)
|
99
|
-
|
99
|
+
if cmd_results != None:
|
100
|
+
exec_result.extend(cmd_results)
|
100
101
|
# exec_result = process_commands('commands.yaml')
|
101
102
|
# print(exec_result)
|
102
103
|
global gauges
|
@@ -138,4 +139,5 @@ def main():
|
|
138
139
|
while True:
|
139
140
|
measure(flag,args)
|
140
141
|
flag = False
|
141
|
-
time.sleep(5)
|
142
|
+
time.sleep(5)
|
143
|
+
main()
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: flexmetric
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.4
|
4
4
|
Summary: A flexible Prometheus exporter for commands, databases, functions, and scripts.
|
5
5
|
Home-page: https://github.com/nikhillingadhal1999/custom_prometheus_agent
|
6
6
|
Author: Nikhil Lingadhal
|
@@ -7,10 +7,9 @@ flexmetric/logging_module/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
|
|
7
7
|
flexmetric/logging_module/logger.py,sha256=hXj9m2Q_KxJVI5YRHRoK6PXV5tO6NmvuVjq2Ipx_1tE,447
|
8
8
|
flexmetric/metric_process/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
9
|
flexmetric/metric_process/database_processing.py,sha256=OAJ0FbvjQLSqUh85KenuEQ5YG7ghWQYT-pzqogCOafk,2542
|
10
|
-
flexmetric/metric_process/
|
11
|
-
flexmetric/
|
12
|
-
flexmetric-0.1.
|
13
|
-
flexmetric-0.1.
|
14
|
-
flexmetric-0.1.
|
15
|
-
flexmetric-0.1.
|
16
|
-
flexmetric-0.1.3.dist-info/RECORD,,
|
10
|
+
flexmetric/metric_process/prometheus_agent.py,sha256=pZ0Czv1ZQvyH0JhuNac5rjP1PC0ixcXM3HsQ0J-WxaY,5402
|
11
|
+
flexmetric-0.1.4.dist-info/METADATA,sha256=adZgMG3ZOx9mlJwhCy3GHdih68q4CJODNb0MxKCSt8Y,5373
|
12
|
+
flexmetric-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
13
|
+
flexmetric-0.1.4.dist-info/entry_points.txt,sha256=urVePn5EWr3JqNvkYP7OsB_h2_Bqvv-Wq1MJRBexm8A,79
|
14
|
+
flexmetric-0.1.4.dist-info/top_level.txt,sha256=zBlrNwKhXUNhgu9RRZnXxYwYnmE-eocRe6wKSmQROA4,11
|
15
|
+
flexmetric-0.1.4.dist-info/RECORD,,
|
@@ -1,73 +0,0 @@
|
|
1
|
-
import subprocess
|
2
|
-
import yaml
|
3
|
-
import re
|
4
|
-
|
5
|
-
# 1. Read YAML commands
|
6
|
-
def read_commands_from_yaml(file_path):
|
7
|
-
with open(file_path, 'r') as f:
|
8
|
-
config = yaml.safe_load(f)
|
9
|
-
return config.get('commands', [])
|
10
|
-
|
11
|
-
# 2. Execute command with timeout
|
12
|
-
def execute_command_with_timeout(command, timeout):
|
13
|
-
try:
|
14
|
-
result = subprocess.run(command, shell=True, capture_output=True, text=True, timeout=timeout)
|
15
|
-
if result.returncode != 0:
|
16
|
-
return ''
|
17
|
-
return result.stdout.strip()
|
18
|
-
except subprocess.TimeoutExpired:
|
19
|
-
return ''
|
20
|
-
|
21
|
-
def process_commands(config_file):
|
22
|
-
commands = read_commands_from_yaml(config_file)
|
23
|
-
all_results = []
|
24
|
-
|
25
|
-
for cmd_info in commands:
|
26
|
-
command = cmd_info['command']
|
27
|
-
label_name = cmd_info['label']
|
28
|
-
timeout = cmd_info.get('timeout_seconds', 30)
|
29
|
-
label_column = cmd_info.get('label_column', -1)
|
30
|
-
value_column = cmd_info.get('value_column', 0)
|
31
|
-
fixed_label_value = cmd_info.get('label_value')
|
32
|
-
|
33
|
-
raw_output = execute_command_with_timeout(command, timeout)
|
34
|
-
lines = raw_output.strip().splitlines()
|
35
|
-
|
36
|
-
result_list = []
|
37
|
-
|
38
|
-
for line in lines:
|
39
|
-
parts = line.strip().split()
|
40
|
-
if not parts:
|
41
|
-
continue
|
42
|
-
if label_column == 'fixed':
|
43
|
-
label = fixed_label_value or 'label'
|
44
|
-
else:
|
45
|
-
try:
|
46
|
-
label = parts[label_column]
|
47
|
-
except IndexError:
|
48
|
-
label = 'unknown'
|
49
|
-
try:
|
50
|
-
raw_value = parts[value_column]
|
51
|
-
cleaned_value = re.sub(r'[^\d\.\-]', '', raw_value)
|
52
|
-
value = float(cleaned_value) if cleaned_value else 1
|
53
|
-
except (IndexError, ValueError):
|
54
|
-
value = 1
|
55
|
-
|
56
|
-
result_list.append({
|
57
|
-
'label': label,
|
58
|
-
'value': value
|
59
|
-
})
|
60
|
-
|
61
|
-
formatted = {
|
62
|
-
'result': result_list,
|
63
|
-
'labels': [label_name]
|
64
|
-
}
|
65
|
-
all_results.append(formatted)
|
66
|
-
|
67
|
-
return all_results
|
68
|
-
|
69
|
-
|
70
|
-
# # Example usage:
|
71
|
-
# if __name__ == "__main__":
|
72
|
-
# results = process_commands('/Users/nlingadh/code/custom_prometheus_agent/src/commands.yaml')
|
73
|
-
# print(results)
|
File without changes
|
File without changes
|
File without changes
|