Skip to content

Instantly share code, notes, and snippets.

@wbollock
Created January 19, 2024 18:28
Show Gist options
  • Save wbollock/39d5c786c8cd5e93c007d5e51abf7ba8 to your computer and use it in GitHub Desktop.
Save wbollock/39d5c786c8cd5e93c007d5e51abf7ba8 to your computer and use it in GitHub Desktop.
label_pair.py
#!/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