Created
January 19, 2024 18:28
-
-
Save wbollock/39d5c786c8cd5e93c007d5e51abf7ba8 to your computer and use it in GitHub Desktop.
label_pair.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# calculate average bytes per label pair for a given metric | |
def calculate_average_bytes_per_label_pair(metric_string): | |
# Splitting the metric string into label pairs | |
label_pairs = metric_string.split(", ") | |
# Calculating the total bytes | |
total_bytes = sum(len(pair) for pair in label_pairs) | |
# Calculating the average bytes per label pair | |
average_bytes = total_bytes / len(label_pairs) | |
return average_bytes | |
# Metric string | |
# replace this! | |
metric_string = 'name="vbin_linode_memory_numa_stat", class="hierarchical_anon", component="linodes", environment="testing", instance="h8002-iad3.linode.com", job="node_exporter", node="N0", username="linode54110847"' | |
# Calculate average bytes | |
average_bytes_per_label_pair = calculate_average_bytes_per_label_pair(metric_string) | |
print(average_bytes_per_label_pair) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment