formatStats - multiple declarations

Function formatStats

Format data members from a struct or a class into a string that can be added to a stat collection buffer for exporting to prometheus.

void formatStats(ValuesT) (
  ValuesT values,
  ref char[] buffer
);

The names and values of the members of the given struct are formatted as stat names and values, respectively.

Parameters

NameDescription
ValuesT The struct or class type to fetch the stat names from.
values The struct or class to fetch stat values from.
buffer The buffer to add the formatted stats to.

Function formatStats

Format data members from a struct or a class, with a additional label name and value, into a string that can be added to a stat collection buffer for exporting to prometheus.

void formatStats(string LabelName, ValuesT, LabelT) (
  ValuesT values,
  LabelT label_val,
  ref char[] buffer
);

Parameters

NameDescription
LabelName The name of the label to annotate the stats with.
ValuesT The struct or class type to fetch the stat names from.
LabelT The type of the label's value.
values The struct or class to fetch stat values from.
label_val The label value to annotate the stats with.
buffer The buffer to add the formatted stats to.

Function formatStats

Format data members from a struct or a class, with an additional struct or class to fetch label names and values from, into a string that can be added to a stat collection buffer for exporting to prometheus.

void formatStats(ValuesT, LabelsT) (
  ValuesT values,
  LabelsT labels,
  ref char[] buffer
);

Parameters

NameDescription
ValuesT The struct or class type to fetch the stat names from.
LabelsT The struct or class type to fetch the label names from.
values The struct or class to fetch stat values from.
labels The struct or class holding the label values to annotate the stats with.
buffer The buffer to add the formatted stats to.

Example

Test collecting populated stats, but without any label.

auto expected = "up_time_s 3600\ncount 347\nratio 3.14\nfraction 6.023\n" ~
    "very_real 0.43\n";

char[] actual;
formatStats(Statistics(3600, 347, 3.14, 6.023, 0.43), actual);

assert(actual == expected);

Example

Test collecting populated stats with one label

auto expected =
    "up_time_s {id=\"123.034\"} 3600\ncount {id=\"123.034\"} 347\n" ~
    "ratio {id=\"123.034\"} 3.14\nfraction {id=\"123.034\"} 6.023\n" ~
    "very_real {id=\"123.034\"} 0.43\n";

char[] actual;
formatStats!("id")(
    Statistics(3600, 347, 3.14, 6.023, 0.43), 123.034, actual);

assert(actual == expected);

Example

Test collecting stats having initial values with multiple labels

auto expected =
    "up_time_s {id=\"1235813\",job=\"ocean\",perf=\"3.14159\"} 3600\n" ~
    "count {id=\"1235813\",job=\"ocean\",perf=\"3.14159\"} 347\n" ~
    "ratio {id=\"1235813\",job=\"ocean\",perf=\"3.14159\"} 3.14\n" ~
    "fraction {id=\"1235813\",job=\"ocean\",perf=\"3.14159\"} 6.023\n" ~
    "very_real {id=\"1235813\",job=\"ocean\",perf=\"3.14159\"} 0.43\n";

char[] actual;
formatStats(Statistics(3600, 347, 3.14, 6.023, 0.43),
    Labels(1_235_813, "ocean", 3.14159), actual);

assert(actual == expected);