{
f->open_object_section("perfcounter_collection");
- for (perf_counters_set_t::iterator l = m_loggers.begin();
- l != m_loggers.end(); ++l) {
- // Optionally filter on logger name, pass through counter filter
- if (logger.empty() || (*l)->get_name() == logger) {
- (*l)->dump_formatted_generic(f, schema, histograms, dump_labeled, counter);
+ if (dump_labeled) {
+ std::string prev_key_name;
+ for (auto l = m_loggers.begin(); l != m_loggers.end(); ++l) {
+ std::string_view key_name = ceph::perf_counters::key_name((*l)->get_name());
+ if (key_name != prev_key_name) {
+ // close previous set of counters before dumping new one
+ if (!prev_key_name.empty()) {
+ f->close_section(); // array section
+ }
+ prev_key_name = key_name;
+
+ f->open_array_section(key_name);
+ (*l)->dump_formatted_generic(f, schema, histograms, true, "");
+ } else {
+ (*l)->dump_formatted_generic(f, schema, histograms, true, "");
+ }
+ }
+ if (!m_loggers.empty()) {
+ f->close_section(); // final array section
+ }
+ } else {
+ for (auto l = m_loggers.begin(); l != m_loggers.end(); ++l) {
+ // Optionally filter on logger name, pass through counter filter
+ if (logger.empty() || (*l)->get_name() == logger) {
+ (*l)->dump_formatted_generic(f, schema, histograms, false, counter);
+ }
}
}
f->close_section();
bool histograms, bool dump_labeled, const std::string &counter) const
{
if (dump_labeled) {
- std::string_view perf_counter_name = ceph::perf_counters::key_name(m_name);
- f->open_object_section(perf_counter_name);
-
+ f->open_object_section(""); // should be enclosed by array
f->open_object_section("labels");
for (auto label : ceph::perf_counters::key_labels(m_name)) {
// don't dump labels with empty label names
std::string message;
ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf dump\" }", &message));
ASSERT_EQ("{}\n", message);
+ ASSERT_EQ("", client.do_request("{ \"prefix\": \"counter dump\" }", &message));
+ ASSERT_EQ("{}\n", message);
}
enum {
)";
std::string counter_key1 = ceph::perf_counters::key_create("name1", {{"label1", "val1"}});
std::string counter_key2 = ceph::perf_counters::key_create("name2", {{"label2", "val2"}});
+ std::string counter_key3 = ceph::perf_counters::key_create("name1", {{"label1", "val3"}});
PerfCounters* counters1 = setup_test_perfcounter4(counter_key1, g_ceph_context);
PerfCounters* counters2 = setup_test_perfcounter4(counter_key2, g_ceph_context);
+ PerfCounters* counters3 = setup_test_perfcounter4(counter_key3, g_ceph_context);
counters1->inc(TEST_PERFCOUNTERS2_ELEMENT_FOO, 3);
counters1->dec(TEST_PERFCOUNTERS2_ELEMENT_FOO, 1);
counters2->set(TEST_PERFCOUNTERS2_ELEMENT_FOO, 4);
+ counters3->inc(TEST_PERFCOUNTERS2_ELEMENT_FOO, 3);
AdminSocketClient client(get_rand_socket_path());
std::string message;
ASSERT_EQ("", client.do_request(R"({ "prefix": "counter dump", "format": "raw" })", &message));
ASSERT_EQ(R"({
- "name1": {
- "labels": {
- "label1": "val1"
+ "name1": [
+ {
+ "labels": {
+ "label1": "val1"
+ },
+ "counters": {
+ "foo": 2,
+ "bar": 0.000000000
+ }
},
- "counters": {
- "foo": 2,
- "bar": 0.000000000
+ {
+ "labels": {
+ "label1": "val3"
+ },
+ "counters": {
+ "foo": 3,
+ "bar": 0.000000000
+ }
}
- },
- "name2": {
- "labels": {
- "label2": "val2"
- },
- "counters": {
- "foo": 4,
- "bar": 0.000000000
+ ],
+ "name2": [
+ {
+ "labels": {
+ "label2": "val2"
+ },
+ "counters": {
+ "foo": 4,
+ "bar": 0.000000000
+ }
}
- }
+ ]
}
)", message);
ASSERT_EQ("", client.do_request(R"({ "prefix": "counter schema", "format": "raw" })", &message));
ASSERT_EQ(R"({
- "name1": {
- "labels": {
- "label1": "val1"
+ "name1": [
+ {
+ "labels": {
+ "label1": "val1"
+ },
+ "counters": {
+ "foo": {
+ "type": 2,
+ "metric_type": "gauge",
+ "value_type": "integer",
+ "description": "",
+ "nick": "",
+ "priority": 0,
+ "units": "none"
+ },
+ "bar": {
+ "type": 1,
+ "metric_type": "gauge",
+ "value_type": "real",
+ "description": "",
+ "nick": "",
+ "priority": 0,
+ "units": "none"
+ }
+ }
},
- "counters": {
- "foo": {
- "type": 2,
- "metric_type": "gauge",
- "value_type": "integer",
- "description": "",
- "nick": "",
- "priority": 0,
- "units": "none"
+ {
+ "labels": {
+ "label1": "val3"
},
- "bar": {
- "type": 1,
- "metric_type": "gauge",
- "value_type": "real",
- "description": "",
- "nick": "",
- "priority": 0,
- "units": "none"
+ "counters": {
+ "foo": {
+ "type": 2,
+ "metric_type": "gauge",
+ "value_type": "integer",
+ "description": "",
+ "nick": "",
+ "priority": 0,
+ "units": "none"
+ },
+ "bar": {
+ "type": 1,
+ "metric_type": "gauge",
+ "value_type": "real",
+ "description": "",
+ "nick": "",
+ "priority": 0,
+ "units": "none"
+ }
}
}
- },
- "name2": {
- "labels": {
- "label2": "val2"
- },
- "counters": {
- "foo": {
- "type": 2,
- "metric_type": "gauge",
- "value_type": "integer",
- "description": "",
- "nick": "",
- "priority": 0,
- "units": "none"
+ ],
+ "name2": [
+ {
+ "labels": {
+ "label2": "val2"
},
- "bar": {
- "type": 1,
- "metric_type": "gauge",
- "value_type": "real",
- "description": "",
- "nick": "",
- "priority": 0,
- "units": "none"
+ "counters": {
+ "foo": {
+ "type": 2,
+ "metric_type": "gauge",
+ "value_type": "integer",
+ "description": "",
+ "nick": "",
+ "priority": 0,
+ "units": "none"
+ },
+ "bar": {
+ "type": 1,
+ "metric_type": "gauge",
+ "value_type": "real",
+ "description": "",
+ "nick": "",
+ "priority": 0,
+ "units": "none"
+ }
}
}
- }
+ ]
}
)", message);
ASSERT_EQ("", client.do_request(R"({ "prefix": "counter dump", "format": "raw" })", &message));
ASSERT_EQ(R"({
- "bad_ctrs": {
- "labels": {
- "label1": "val1"
- },
- "counters": {
- "foo": 4,
- "bar": 0.000000000
+ "bad_ctrs": [
+ {
+ "labels": {
+ "label1": "val1"
+ },
+ "counters": {
+ "foo": 4,
+ "bar": 0.000000000
+ }
}
- },
- "bad_ctrs2": {
- "labels": {},
- "counters": {
- "foo": 6,
- "bar": 0.000000000
+ ],
+ "bad_ctrs2": [
+ {
+ "labels": {},
+ "counters": {
+ "foo": 6,
+ "bar": 0.000000000
+ }
}
- },
- "good_ctrs": {
- "labels": {
- "label1": "",
- "label3": "val4"
- },
- "counters": {
- "foo": 2,
- "bar": 0.000000000
+ ],
+ "good_ctrs": [
+ {
+ "labels": {
+ "label1": "",
+ "label3": "val4"
+ },
+ "counters": {
+ "foo": 2,
+ "bar": 0.000000000
+ }
}
- },
- "only_key": {
- "labels": {},
- "counters": {
- "foo": 4,
- "bar": 0.000000000
+ ],
+ "only_key": [
+ {
+ "labels": {},
+ "counters": {
+ "foo": 4,
+ "bar": 0.000000000
+ }
}
- },
- "too_many_delimiters": {
- "labels": {
- "label1": "val1"
- },
- "counters": {
- "foo": 8,
- "bar": 0.000000000
+ ],
+ "too_many_delimiters": [
+ {
+ "labels": {
+ "label1": "val1"
+ },
+ "counters": {
+ "foo": 8,
+ "bar": 0.000000000
+ }
}
- }
+ ]
}
)", message);
// test unlabeled perf counters are in the schema dump with labels and counters sections
ASSERT_EQ("", client.do_request(R"({ "prefix": "counter schema", "format": "raw" })", &message));
ASSERT_EQ(R"({
- "bad_ctrs": {
- "labels": {
- "label1": "val1"
- },
- "counters": {
- "foo": {
- "type": 2,
- "metric_type": "gauge",
- "value_type": "integer",
- "description": "",
- "nick": "",
- "priority": 0,
- "units": "none"
+ "bad_ctrs": [
+ {
+ "labels": {
+ "label1": "val1"
},
- "bar": {
- "type": 1,
- "metric_type": "gauge",
- "value_type": "real",
- "description": "",
- "nick": "",
- "priority": 0,
- "units": "none"
+ "counters": {
+ "foo": {
+ "type": 2,
+ "metric_type": "gauge",
+ "value_type": "integer",
+ "description": "",
+ "nick": "",
+ "priority": 0,
+ "units": "none"
+ },
+ "bar": {
+ "type": 1,
+ "metric_type": "gauge",
+ "value_type": "real",
+ "description": "",
+ "nick": "",
+ "priority": 0,
+ "units": "none"
+ }
}
}
- },
- "bad_ctrs2": {
- "labels": {},
- "counters": {
- "foo": {
- "type": 2,
- "metric_type": "gauge",
- "value_type": "integer",
- "description": "",
- "nick": "",
- "priority": 0,
- "units": "none"
- },
- "bar": {
- "type": 1,
- "metric_type": "gauge",
- "value_type": "real",
- "description": "",
- "nick": "",
- "priority": 0,
- "units": "none"
+ ],
+ "bad_ctrs2": [
+ {
+ "labels": {},
+ "counters": {
+ "foo": {
+ "type": 2,
+ "metric_type": "gauge",
+ "value_type": "integer",
+ "description": "",
+ "nick": "",
+ "priority": 0,
+ "units": "none"
+ },
+ "bar": {
+ "type": 1,
+ "metric_type": "gauge",
+ "value_type": "real",
+ "description": "",
+ "nick": "",
+ "priority": 0,
+ "units": "none"
+ }
}
}
- },
- "good_ctrs": {
- "labels": {
- "label1": "",
- "label3": "val4"
- },
- "counters": {
- "foo": {
- "type": 2,
- "metric_type": "gauge",
- "value_type": "integer",
- "description": "",
- "nick": "",
- "priority": 0,
- "units": "none"
+ ],
+ "good_ctrs": [
+ {
+ "labels": {
+ "label1": "",
+ "label3": "val4"
},
- "bar": {
- "type": 1,
- "metric_type": "gauge",
- "value_type": "real",
- "description": "",
- "nick": "",
- "priority": 0,
- "units": "none"
+ "counters": {
+ "foo": {
+ "type": 2,
+ "metric_type": "gauge",
+ "value_type": "integer",
+ "description": "",
+ "nick": "",
+ "priority": 0,
+ "units": "none"
+ },
+ "bar": {
+ "type": 1,
+ "metric_type": "gauge",
+ "value_type": "real",
+ "description": "",
+ "nick": "",
+ "priority": 0,
+ "units": "none"
+ }
}
}
- },
- "only_key": {
- "labels": {},
- "counters": {
- "foo": {
- "type": 2,
- "metric_type": "gauge",
- "value_type": "integer",
- "description": "",
- "nick": "",
- "priority": 0,
- "units": "none"
- },
- "bar": {
- "type": 1,
- "metric_type": "gauge",
- "value_type": "real",
- "description": "",
- "nick": "",
- "priority": 0,
- "units": "none"
+ ],
+ "only_key": [
+ {
+ "labels": {},
+ "counters": {
+ "foo": {
+ "type": 2,
+ "metric_type": "gauge",
+ "value_type": "integer",
+ "description": "",
+ "nick": "",
+ "priority": 0,
+ "units": "none"
+ },
+ "bar": {
+ "type": 1,
+ "metric_type": "gauge",
+ "value_type": "real",
+ "description": "",
+ "nick": "",
+ "priority": 0,
+ "units": "none"
+ }
}
}
- },
- "too_many_delimiters": {
- "labels": {
- "label1": "val1"
- },
- "counters": {
- "foo": {
- "type": 2,
- "metric_type": "gauge",
- "value_type": "integer",
- "description": "",
- "nick": "",
- "priority": 0,
- "units": "none"
+ ],
+ "too_many_delimiters": [
+ {
+ "labels": {
+ "label1": "val1"
},
- "bar": {
- "type": 1,
- "metric_type": "gauge",
- "value_type": "real",
- "description": "",
- "nick": "",
- "priority": 0,
- "units": "none"
+ "counters": {
+ "foo": {
+ "type": 2,
+ "metric_type": "gauge",
+ "value_type": "integer",
+ "description": "",
+ "nick": "",
+ "priority": 0,
+ "units": "none"
+ },
+ "bar": {
+ "type": 1,
+ "metric_type": "gauge",
+ "value_type": "real",
+ "description": "",
+ "nick": "",
+ "priority": 0,
+ "units": "none"
+ }
}
}
- }
+ ]
}
)", message);