prometheus-cpp icon indicating copy to clipboard operation
prometheus-cpp copied to clipboard

Confused by how to configure labels

Open jdx-john opened this issue 4 years ago • 1 comments

This is the only sample code (that I can see) showing how to set up and use metrics:

  // add a new counter family to the registry (families combine values with the
  // same name, but distinct label dimensions)
  auto& counter_family = BuildCounter()
                             .Name("time_running_seconds_total")
                             .Help("How many seconds is this server running?")
                             .Labels({{"label", "value"}})
                             .Register(*registry);

  // add a counter to the metric family
  auto& second_counter = counter_family.Add(
      {{"another_label", "value"}, {"yet_another_label", "value"}});

  for (;;) {
    std::this_thread::sleep_for(std::chrono::seconds(1));
    // increment the counter by one (second)
    second_counter.Increment();
  }

I am confused what is going on here. Specifically second_counter = counter_family.Add( - is this modifying counter_family so we're incrementing a time-series: time_running_seconds_total{label=value, another_label=value, yet_another_value = value}

Or something else? I thought metric dimensions had to be fully qualified e.g. if there are 3 labels, all 3 must be specified for a valid time-series. What would the output scrape look like?

jdx-john avatar Oct 06 '20 11:10 jdx-john

I am interested too.

FabienCarmagnac avatar Nov 26 '20 07:11 FabienCarmagnac