You can download this code by clicking the button below.
This code is now available for download.
This function generates a random Prometheus gauge metric family, including name, help information, and optional labels.
Technology Stack : Prometheus, random, string
Code Type : Prometheus Gauge Metric Family
Code Difficulty : Intermediate
def random_gaugeMetricFamily(name, help, labels=None):
"""
This function generates a random Prometheus Gauge metric family.
"""
import random
import string
if labels is None:
labels = []
label_names = [random.choice(string.ascii_letters + '_') for _ in range(random.randint(1, 5))]
label_values = {label_name: random.choice(string.ascii_letters) for label_name in label_names}
return {
"name": name,
"help": help,
"type": "gauge",
"metric": [
{
"labels": label_values,
"value": random.random()
}
]
}
# JSON Explanation