From: Razvan Becheriu Date: Mon, 8 Sep 2025 11:37:32 +0000 (+0300) Subject: [#3213] added statistic-global-get-all X-Git-Tag: Kea-3.1.2~66 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26daff96cc993461b6deab4a47829474da323f75;p=thirdparty%2Fkea.git [#3213] added statistic-global-get-all --- diff --git a/doc/sphinx/api-files.txt b/doc/sphinx/api-files.txt index 9806449c08..7871938f92 100644 --- a/doc/sphinx/api-files.txt +++ b/doc/sphinx/api-files.txt @@ -171,6 +171,7 @@ src/share/api/server-tag-get.json src/share/api/shutdown.json src/share/api/statistic-get.json src/share/api/statistic-get-all.json +src/share/api/statistic-global-get-all.json src/share/api/statistic-remove.json src/share/api/statistic-remove-all.json src/share/api/statistic-reset.json diff --git a/doc/sphinx/arm/stats.rst b/doc/sphinx/arm/stats.rst index d716f0be53..4e85c18889 100644 --- a/doc/sphinx/arm/stats.rst +++ b/doc/sphinx/arm/stats.rst @@ -928,6 +928,439 @@ or "result": 0 } +.. isccmd:: statistic-global-get-all +.. _command-statistic-global-get-all: + +The ``statistic-global-get-all`` Command +---------------------------------------- + +The :isccmd:`statistic-global-get-all` command retrieves all global statistics recorded +(same as :isccmd:`statistic-global-get-all` but omitting subnet statistics). An example +command may look like this: + +:: + + { + "command": "statistic-global-get-all", + "arguments": { } + } + +The server responds with details of all recorded statistics, with a +result set to 0 to indicate that it iterated over all statistics (even +when the total number of statistics is zero). + +Here is an example response returning all collected statistics: + +:: + + { + "command": "statistic-global-get-all", + "arguments": { + "assigned-addresses": [ + [ + 0, + "2023-06-13 20:42:46.836096" + ] + ], + "cumulative-assigned-addresses": [ + [ + 0, + "2023-06-13 20:42:46.836166" + ] + ], + "declined-addresses": [ + [ + 0, + "2023-06-13 20:42:46.836156" + ] + ], + "pkt4-ack-received": [ + [ + 0, + "2023-06-13 20:42:46.616247" + ] + ], + "pkt4-ack-sent": [ + [ + 0, + "2023-06-13 20:42:46.616290" + ] + ], + "pkt4-decline-received": [ + [ + 0, + "2023-06-13 20:42:46.616296" + ] + ], + "pkt4-discover-received": [ + [ + 0, + "2023-06-13 20:42:46.616303" + ] + ], + "pkt4-inform-received": [ + [ + 0, + "2023-06-13 20:42:46.616308" + ] + ], + "pkt4-nak-received": [ + [ + 0, + "2023-06-13 20:42:46.616312" + ] + ], + "pkt4-nak-sent": [ + [ + 0, + "2023-06-13 20:42:46.616314" + ] + ], + "pkt4-offer-received": [ + [ + 0, + "2023-06-13 20:42:46.616318" + ] + ], + "pkt4-offer-sent": [ + [ + 0, + "2023-06-13 20:42:46.616323" + ] + ], + "pkt4-parse-failed": [ + [ + 0, + "2023-06-13 20:42:46.616326" + ] + ], + "pkt4-receive-drop": [ + [ + 0, + "2023-06-13 20:42:46.616330" + ] + ], + "pkt4-received": [ + [ + 0, + "2023-06-13 20:42:46.616335" + ] + ], + "pkt4-release-received": [ + [ + 0, + "2023-06-13 20:42:46.616339" + ] + ], + "pkt4-request-received": [ + [ + 0, + "2023-06-13 20:42:46.616343" + ] + ], + "pkt4-sent": [ + [ + 0, + "2023-06-13 20:42:46.616348" + ] + ], + "pkt4-unknown-received": [ + [ + 0, + "2023-06-13 20:42:46.616354" + ] + ], + "reclaimed-declined-addresses": [ + [ + 0, + "2023-06-13 20:42:46.836159" + ] + ], + "reclaimed-leases": [ + [ + 0, + "2023-06-13 20:42:46.836163" + ] + ], + "v4-allocation-fail": [ + [ + 0, + "2023-06-13 20:42:46.616358" + ] + ], + "v4-allocation-fail-classes": [ + [ + 0, + "2023-06-13 20:42:46.616363" + ] + ], + "v4-allocation-fail-no-pools": [ + [ + 0, + "2023-06-13 20:42:46.616368" + ] + ], + "v4-allocation-fail-shared-network": [ + [ + 0, + "2023-06-13 20:42:46.616372" + ] + ], + "v4-allocation-fail-subnet": [ + [ + 0, + "2023-06-13 20:42:46.616376" + ] + ], + "v4-lease-reuses": [ + [ + 0, + "2023-06-13 20:42:46.616410" + ] + ], + "v4-reservation-conflicts": [ + [ + 0, + "2023-06-13 20:42:46.616412" + ] + ] + }, + "result": 0 + } + +or + +:: + + { + "command": "statistic-global-get-all", + "arguments": { + "assigned-nas": [ + [ + 0, + "2023-06-13 21:28:57.196757" + ] + ], + "assigned-pds": [ + [ + 0, + "2023-06-13 21:28:57.196757" + ] + ], + "cumulative-assigned-nas": [ + [ + 0, + "2023-06-13 21:28:57.196757" + ] + ], + "cumulative-assigned-pds": [ + [ + 0, + "2023-06-13 21:28:57.196758" + ] + ], + "cumulative-registered": [ + [ + 0, + "2023-06-13 21:28:57.196758" + ] + ], + "declined-addresses": [ + [ + 0, + "2023-06-13 21:28:57.196754" + ] + ], + "pkt6-addr-reg-inform-received": [ + [ + 0, + "2023-06-13 21:28:57.177731" + ] + ], + "pkt6-addr-reg-reply-received": [ + [ + 0, + "2023-06-13 21:28:57.177731" + ] + ], + "pkt6-addr-reg-reply-sent": [ + [ + 0, + "2023-06-13 21:28:57.177731" + ] + ], + "pkt6-advertise-received": [ + [ + 0, + "2023-06-13 21:28:57.177731" + ] + ], + "pkt6-advertise-sent": [ + [ + 0, + "2023-06-13 21:28:57.177739" + ] + ], + "pkt6-decline-received": [ + [ + 0, + "2023-06-13 21:28:57.177739" + ] + ], + "pkt6-dhcpv4-query-received": [ + [ + 0, + "2023-06-13 21:28:57.177740" + ] + ], + "pkt6-dhcpv4-response-received": [ + [ + 0, + "2023-06-13 21:28:57.177740" + ] + ], + "pkt6-dhcpv4-response-sent": [ + [ + 0, + "2023-06-13 21:28:57.177741" + ] + ], + "pkt6-infrequest-received": [ + [ + 0, + "2023-06-13 21:28:57.177742" + ] + ], + "pkt6-parse-failed": [ + [ + 0, + "2023-06-13 21:28:57.177742" + ] + ], + "pkt6-rebind-received": [ + [ + 0, + "2023-06-13 21:28:57.177743" + ] + ], + "pkt6-receive-drop": [ + [ + 0, + "2023-06-13 21:28:57.177743" + ] + ], + "pkt6-received": [ + [ + 0, + "2023-06-13 21:28:57.177744" + ] + ], + "pkt6-release-received": [ + [ + 0, + "2023-06-13 21:28:57.177744" + ] + ], + "pkt6-renew-received": [ + [ + 0, + "2023-06-13 21:28:57.177745" + ] + ], + "pkt6-reply-received": [ + [ + 0, + "2023-06-13 21:28:57.177745" + ] + ], + "pkt6-reply-sent": [ + [ + 0, + "2023-06-13 21:28:57.177746" + ] + ], + "pkt6-request-received": [ + [ + 0, + "2023-06-13 21:28:57.177747" + ] + ], + "pkt6-sent": [ + [ + 0, + "2023-06-13 21:28:57.177747" + ] + ], + "pkt6-solicit-received": [ + [ + 0, + "2023-06-13 21:28:57.177748" + ] + ], + "pkt6-unknown-received": [ + [ + 0, + "2023-06-13 21:28:57.177748" + ] + ], + "reclaimed-declined-addresses": [ + [ + 0, + "2023-06-13 21:28:57.196755" + ] + ], + "reclaimed-leases": [ + [ + 0, + "2023-06-13 21:28:57.196756" + ] + ], + "v6-allocation-fail": [ + [ + 0, + "2023-06-13 21:28:57.177749" + ] + ], + "v6-allocation-fail-classes": [ + [ + 0, + "2023-06-13 21:28:57.177755" + ] + ], + "v6-allocation-fail-no-pools": [ + [ + 0, + "2023-06-13 21:28:57.177756" + ] + ], + "v6-allocation-fail-shared-network": [ + [ + 0, + "2023-06-13 21:28:57.177756" + ] + ], + "v6-allocation-fail-subnet": [ + [ + 0, + "2023-06-13 21:28:57.177757" + ] + ], + "v6-ia-na-lease-reuses": [ + [ + 0, + "2023-06-13 21:28:57.177757" + ] + ], + "v6-ia-pd-lease-reuses": [ + [ + 0, + "2023-06-13 21:28:57.177758" + ] + ] + }, + "result": 0 + } + .. isccmd:: statistic-reset-all .. _command-statistic-reset-all: diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index 1d59e0b7ac..41b64d7eee 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -1544,6 +1544,9 @@ ControlledDhcpv4Srv::ControlledDhcpv4Srv(uint16_t server_port /*= DHCP4_SERVER_P CommandMgr::instance().registerCommand("statistic-get-all", std::bind(&StatsMgr::statisticGetAllHandler, ph::_1, ph::_2)); + CommandMgr::instance().registerCommand("statistic-global-get-all", + std::bind(&StatsMgr::statisticGlobalGetAllHandler, ph::_1, ph::_2)); + CommandMgr::instance().registerCommand("statistic-reset-all", std::bind(&StatsMgr::statisticResetAllHandler, ph::_1, ph::_2)); @@ -1607,6 +1610,7 @@ ControlledDhcpv4Srv::~ControlledDhcpv4Srv() { CommandMgr::instance().deregisterCommand("shutdown"); CommandMgr::instance().deregisterCommand("statistic-get"); CommandMgr::instance().deregisterCommand("statistic-get-all"); + CommandMgr::instance().deregisterCommand("statistic-global-get-all"); CommandMgr::instance().deregisterCommand("statistic-remove"); CommandMgr::instance().deregisterCommand("statistic-remove-all"); CommandMgr::instance().deregisterCommand("statistic-reset"); diff --git a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc index e5a314b302..8ff37b43e2 100644 --- a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc @@ -546,6 +546,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, commandsRegistration) { EXPECT_TRUE(command_list.find("\"shutdown\"") != string::npos); EXPECT_TRUE(command_list.find("\"statistic-get\"") != string::npos); EXPECT_TRUE(command_list.find("\"statistic-get-all\"") != string::npos); + EXPECT_TRUE(command_list.find("\"statistic-global-get-all\"") != string::npos); EXPECT_TRUE(command_list.find("\"statistic-remove\"") != string::npos); EXPECT_TRUE(command_list.find("\"statistic-remove-all\"") != string::npos); EXPECT_TRUE(command_list.find("\"statistic-reset\"") != string::npos); @@ -656,6 +657,12 @@ TEST_F(CtrlChannelDhcpv4SrvTest, controlChannelStats) { EXPECT_EQ(stats_get_all, response); + // Check statistic-global-get-all + sendUnixCommand("{ \"command\" : \"statistic-global-get-all\", " + " \"arguments\": {}}", response); + + EXPECT_EQ(stats_get_all, response); + // Check statistic-reset sendUnixCommand("{ \"command\" : \"statistic-reset\", " " \"arguments\": {" @@ -1668,6 +1675,7 @@ TEST_F(CtrlChannelDhcpv4SrvTest, listCommands) { checkListCommands(rsp, "shutdown"); checkListCommands(rsp, "statistic-get"); checkListCommands(rsp, "statistic-get-all"); + checkListCommands(rsp, "statistic-global-get-all"); checkListCommands(rsp, "statistic-remove"); checkListCommands(rsp, "statistic-remove-all"); checkListCommands(rsp, "statistic-reset"); diff --git a/src/bin/dhcp4/tests/http_control_socket_unittest.cc b/src/bin/dhcp4/tests/http_control_socket_unittest.cc index 48579a744a..2f7e64a9ae 100644 --- a/src/bin/dhcp4/tests/http_control_socket_unittest.cc +++ b/src/bin/dhcp4/tests/http_control_socket_unittest.cc @@ -966,6 +966,12 @@ BaseCtrlChannelDhcpv4Test::testControlChannelStats() { EXPECT_EQ(stats_get_all, response); + // Check statistic-global-get-all + sendHttpCommand("{ \"command\" : \"statistic-global-get-all\", " + " \"arguments\": {}}", response); + + EXPECT_EQ(stats_get_all, response); + // Check statistic-reset sendHttpCommand("{ \"command\" : \"statistic-reset\", " " \"arguments\": {" @@ -2611,6 +2617,7 @@ BaseCtrlChannelDhcpv4Test::testListCommands() { checkListCommands(rsp, "shutdown"); checkListCommands(rsp, "statistic-get"); checkListCommands(rsp, "statistic-get-all"); + checkListCommands(rsp, "statistic-global-get-all"); checkListCommands(rsp, "statistic-remove"); checkListCommands(rsp, "statistic-remove-all"); checkListCommands(rsp, "statistic-reset"); diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index 9d2dcdf6e9..c7d9b072fb 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -1331,6 +1331,9 @@ ControlledDhcpv6Srv::ControlledDhcpv6Srv(uint16_t server_port /*= DHCP6_SERVER_P CommandMgr::instance().registerCommand("statistic-get-all", std::bind(&StatsMgr::statisticGetAllHandler, ph::_1, ph::_2)); + CommandMgr::instance().registerCommand("statistic-global-get-all", + std::bind(&StatsMgr::statisticGlobalGetAllHandler, ph::_1, ph::_2)); + CommandMgr::instance().registerCommand("statistic-reset-all", std::bind(&StatsMgr::statisticResetAllHandler, ph::_1, ph::_2)); @@ -1393,6 +1396,7 @@ ControlledDhcpv6Srv::~ControlledDhcpv6Srv() { CommandMgr::instance().deregisterCommand("shutdown"); CommandMgr::instance().deregisterCommand("statistic-get"); CommandMgr::instance().deregisterCommand("statistic-get-all"); + CommandMgr::instance().deregisterCommand("statistic-global-get-all"); CommandMgr::instance().deregisterCommand("statistic-remove"); CommandMgr::instance().deregisterCommand("statistic-remove-all"); CommandMgr::instance().deregisterCommand("statistic-reset"); diff --git a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc index f0d5eac636..91145d92fe 100644 --- a/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc +++ b/src/bin/dhcp6/tests/ctrl_dhcp6_srv_unittest.cc @@ -550,6 +550,7 @@ TEST_F(CtrlDhcpv6SrvTest, commandsRegistration) { EXPECT_TRUE(command_list.find("\"shutdown\"") != string::npos); EXPECT_TRUE(command_list.find("\"statistic-get\"") != string::npos); EXPECT_TRUE(command_list.find("\"statistic-get-all\"") != string::npos); + EXPECT_TRUE(command_list.find("\"statistic-global-get-all\"") != string::npos); EXPECT_TRUE(command_list.find("\"statistic-remove\"") != string::npos); EXPECT_TRUE(command_list.find("\"statistic-remove-all\"") != string::npos); EXPECT_TRUE(command_list.find("\"statistic-reset\"") != string::npos); @@ -666,6 +667,12 @@ TEST_F(CtrlChannelDhcpv6SrvTest, controlChannelStats) { EXPECT_EQ(stats_get_all, response); + // Check statistic-global-get-all + sendUnixCommand("{ \"command\" : \"statistic-global-get-all\", " + " \"arguments\": {}}", response); + + EXPECT_EQ(stats_get_all, response); + // Check statistic-reset sendUnixCommand("{ \"command\" : \"statistic-reset\", " " \"arguments\": {" @@ -1672,6 +1679,7 @@ TEST_F(CtrlChannelDhcpv6SrvTest, listCommands) { checkListCommands(rsp, "shutdown"); checkListCommands(rsp, "statistic-get"); checkListCommands(rsp, "statistic-get-all"); + checkListCommands(rsp, "statistic-global-get-all"); checkListCommands(rsp, "statistic-remove"); checkListCommands(rsp, "statistic-remove-all"); checkListCommands(rsp, "statistic-reset"); diff --git a/src/bin/dhcp6/tests/http_control_socket_unittest.cc b/src/bin/dhcp6/tests/http_control_socket_unittest.cc index 06ba22761e..8be9d533a6 100644 --- a/src/bin/dhcp6/tests/http_control_socket_unittest.cc +++ b/src/bin/dhcp6/tests/http_control_socket_unittest.cc @@ -983,6 +983,12 @@ BaseCtrlChannelDhcpv6Test::testControlChannelStats() { EXPECT_EQ(stats_get_all, response); + // Check statistic-global-get-all + sendHttpCommand("{ \"command\" : \"statistic-global-get-all\", " + " \"arguments\": {}}", response); + + EXPECT_EQ(stats_get_all, response); + // Check statistic-reset sendHttpCommand("{ \"command\" : \"statistic-reset\", " " \"arguments\": {" @@ -2611,6 +2617,7 @@ BaseCtrlChannelDhcpv6Test::testListCommands() { checkListCommands(rsp, "shutdown"); checkListCommands(rsp, "statistic-get"); checkListCommands(rsp, "statistic-get-all"); + checkListCommands(rsp, "statistic-global-get-all"); checkListCommands(rsp, "statistic-remove"); checkListCommands(rsp, "statistic-remove-all"); checkListCommands(rsp, "statistic-reset"); diff --git a/src/bin/shell/tests/dhcp4_basic_auth_tests.sh.in b/src/bin/shell/tests/dhcp4_basic_auth_tests.sh.in index 89aa299eaf..6515095b94 100755 --- a/src/bin/shell/tests/dhcp4_basic_auth_tests.sh.in +++ b/src/bin/shell/tests/dhcp4_basic_auth_tests.sh.in @@ -229,7 +229,7 @@ shell_command_test "shell.bad-auth" \ "Failed to run: HTTP Error 401: Unauthorized" shell_command_test "shell.authorized" \ "--auth-user pet --auth-password meow" "list-commands" "" \ - "[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet4-select-test\", \"subnet4o6-select-test\", \"version-get\" ], \"result\": 0 } ]" + "[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-global-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet4-select-test\", \"subnet4o6-select-test\", \"version-get\" ], \"result\": 0 } ]" shell_command_test "shell.bad-auth-password-file" \ "--auth-user foo --auth-password-file foobar" "list-commands" "fail" \ "Failed to run: [Errno 2] No such file or directory: 'foobar'" @@ -238,7 +238,7 @@ shell_command_test "shell.bad-auth-password-file-content" \ "Failed to run: HTTP Error 401: Unauthorized" shell_command_test "shell.good-auth-password-file-content" \ "--auth-user pet --auth-password-file ${tmpfile_path}/auth_password_file" "list-commands" "" \ - "[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet4-select-test\", \"subnet4o6-select-test\", \"version-get\" ], \"result\": 0 } ]" + "[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-global-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet4-select-test\", \"subnet4o6-select-test\", \"version-get\" ], \"result\": 0 } ]" shell_command_test "shell.flag-precedence" \ "--auth-user pet --auth-password meow --auth-password-file ${tmpfile_path}/auth_bad_password_file" "list-commands" "fail" \ "Failed to run: HTTP Error 401: Unauthorized" diff --git a/src/bin/shell/tests/dhcp6_basic_auth_tests.sh.in b/src/bin/shell/tests/dhcp6_basic_auth_tests.sh.in index 62778274f3..74b2282829 100755 --- a/src/bin/shell/tests/dhcp6_basic_auth_tests.sh.in +++ b/src/bin/shell/tests/dhcp6_basic_auth_tests.sh.in @@ -234,7 +234,7 @@ shell_command_test "shell.bad-auth" \ "Failed to run: HTTP Error 401: Unauthorized" shell_command_test "shell.authorized" \ "--auth-user pet --auth-password meow" "list-commands" "" \ - "[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet6-select-test\", \"version-get\" ], \"result\": 0 } ]" + "[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-global-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet6-select-test\", \"version-get\" ], \"result\": 0 } ]" shell_command_test "shell.bad-auth-password-file" \ "--auth-user foo --auth-password-file foobar" "list-commands" "fail" \ "Failed to run: [Errno 2] No such file or directory: 'foobar'" @@ -243,7 +243,7 @@ shell_command_test "shell.bad-auth-password-file-content" \ "Failed to run: HTTP Error 401: Unauthorized" shell_command_test "shell.good-auth-password-file-content" \ "--auth-user pet --auth-password-file ${tmpfile_path}/auth_password_file" "list-commands" "" \ - "[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet6-select-test\", \"version-get\" ], \"result\": 0 } ]" + "[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-global-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet6-select-test\", \"version-get\" ], \"result\": 0 } ]" shell_command_test "shell.flag-precedence" \ "--auth-user pet --auth-password meow --auth-password-file ${tmpfile_path}/auth_bad_password_file" "list-commands" "fail" \ "Failed to run: HTTP Error 401: Unauthorized" diff --git a/src/bin/shell/tests/shell_dhcp4_process_tests.sh.in b/src/bin/shell/tests/shell_dhcp4_process_tests.sh.in index db0b39d2c0..e4f5da844c 100755 --- a/src/bin/shell/tests/shell_dhcp4_process_tests.sh.in +++ b/src/bin/shell/tests/shell_dhcp4_process_tests.sh.in @@ -214,7 +214,7 @@ version_test() { version_test "shell.version" shell_command_test "shell.list-commands" "list-commands" \ - "[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet4-select-test\", \"subnet4o6-select-test\", \"version-get\" ], \"result\": 0 } ]" "" + "[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-global-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet4-select-test\", \"subnet4o6-select-test\", \"version-get\" ], \"result\": 0 } ]" "" shell_command_test "shell.bogus" "give-me-a-beer" \ "[ { \"result\": 2, \"text\": \"'give-me-a-beer' command not supported.\" } ]" "" shell_command_test "shell.empty-config-test" "config-test" \ diff --git a/src/bin/shell/tests/shell_dhcp6_process_tests.sh.in b/src/bin/shell/tests/shell_dhcp6_process_tests.sh.in index 37339989df..8dd102c0d4 100755 --- a/src/bin/shell/tests/shell_dhcp6_process_tests.sh.in +++ b/src/bin/shell/tests/shell_dhcp6_process_tests.sh.in @@ -219,7 +219,7 @@ version_test() { version_test "shell.version" shell_command_test "shell.list-commands" "list-commands" \ - "[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet6-select-test\", \"version-get\" ], \"result\": 0 } ]" "" + "[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-global-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet6-select-test\", \"version-get\" ], \"result\": 0 } ]" "" shell_command_test "shell.bogus" "give-me-a-beer" \ "[ { \"result\": 2, \"text\": \"'give-me-a-beer' command not supported.\" } ]" "" shell_command_test "shell.empty-config-test" "config-test" \ diff --git a/src/bin/shell/tests/tls_dhcp4_process_tests.sh.in b/src/bin/shell/tests/tls_dhcp4_process_tests.sh.in index 24cb1e8c02..7e6e0915b0 100755 --- a/src/bin/shell/tests/tls_dhcp4_process_tests.sh.in +++ b/src/bin/shell/tests/tls_dhcp4_process_tests.sh.in @@ -306,10 +306,10 @@ list_commands_test() { } list_commands_test "NoTLS" "${CONFIG_NONE}" "" \ -"[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet4-select-test\", \"subnet4o6-select-test\", \"version-get\" ], \"result\": 0 } ]" +"[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-global-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet4-select-test\", \"subnet4o6-select-test\", \"version-get\" ], \"result\": 0 } ]" list_commands_test "Encrypted" "${CONFIG_NOCR}" \ "--ca ${TEST_CA_DIR}/kea-ca.crt" \ -"[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet4-select-test\", \"subnet4o6-select-test\", \"version-get\" ], \"result\": 0 } ]" +"[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-global-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet4-select-test\", \"subnet4o6-select-test\", \"version-get\" ], \"result\": 0 } ]" list_commands_test "Authenticated" "${CONFIG}" \ "--ca ${TEST_CA_DIR}/kea-ca.crt --cert ${TEST_CA_DIR}/kea-client.crt --key ${TEST_CA_DIR}/kea-client.key" \ -"[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet4-select-test\", \"subnet4o6-select-test\", \"version-get\" ], \"result\": 0 } ]" +"[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-global-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet4-select-test\", \"subnet4o6-select-test\", \"version-get\" ], \"result\": 0 } ]" diff --git a/src/bin/shell/tests/tls_dhcp6_process_tests.sh.in b/src/bin/shell/tests/tls_dhcp6_process_tests.sh.in index 29c419a7af..fe0646db4a 100755 --- a/src/bin/shell/tests/tls_dhcp6_process_tests.sh.in +++ b/src/bin/shell/tests/tls_dhcp6_process_tests.sh.in @@ -321,10 +321,10 @@ list_commands_test() { } list_commands_test "NoTLS" "${CONFIG_NONE}" "" \ -"[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet6-select-test\", \"version-get\" ], \"result\": 0 } ]" +"[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-global-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet6-select-test\", \"version-get\" ], \"result\": 0 } ]" list_commands_test "Encrypted" "${CONFIG_NOCR}" \ "--ca ${TEST_CA_DIR}/kea-ca.crt" \ -"[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet6-select-test\", \"version-get\" ], \"result\": 0 } ]" +"[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-global-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet6-select-test\", \"version-get\" ], \"result\": 0 } ]" list_commands_test "Authenticated" "${CONFIG}" \ "--ca ${TEST_CA_DIR}/kea-ca.crt --cert ${TEST_CA_DIR}/kea-client.crt --key ${TEST_CA_DIR}/kea-client.key" \ -"[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet6-select-test\", \"version-get\" ], \"result\": 0 } ]" +"[ { \"arguments\": [ \"build-report\", \"config-backend-pull\", \"config-get\", \"config-hash-get\", \"config-reload\", \"config-set\", \"config-test\", \"config-write\", \"dhcp-disable\", \"dhcp-enable\", \"leases-reclaim\", \"list-commands\", \"server-tag-get\", \"shutdown\", \"statistic-get\", \"statistic-get-all\", \"statistic-global-get-all\", \"statistic-remove\", \"statistic-remove-all\", \"statistic-reset\", \"statistic-reset-all\", \"statistic-sample-age-set\", \"statistic-sample-age-set-all\", \"statistic-sample-count-set\", \"statistic-sample-count-set-all\", \"status-get\", \"subnet6-select-test\", \"version-get\" ], \"result\": 0 } ]" diff --git a/src/lib/stats/context.cc b/src/lib/stats/context.cc index 5826b35f11..e28228132a 100644 --- a/src/lib/stats/context.cc +++ b/src/lib/stats/context.cc @@ -77,6 +77,20 @@ StatContext::getAll() const { return (map); } +ConstElementPtr +StatContext::getAllGlobal() const { + ElementPtr map = Element::createMap(); // a map + // Let's iterate over all stored statistics... + for (auto const& s : stats_) { + // ... and add each of them to the map omitting + // subnet statistics. + if (s.first.find("subnet") != 0) { + map->set(s.first, s.second->getJSON()); + } + } + return (map); +} + void StatContext::setMaxSampleCountAll(uint32_t max_samples) { // Let's iterate over all stored statistics... diff --git a/src/lib/stats/context.h b/src/lib/stats/context.h index 117872f96c..b5879974db 100644 --- a/src/lib/stats/context.h +++ b/src/lib/stats/context.h @@ -75,6 +75,12 @@ public: /// @return map with all observations isc::data::ConstElementPtr getAll() const; + /// @brief Returns a map with all observations omitting those + /// related to subnet statistics. + /// + /// @return map with all observations + isc::data::ConstElementPtr getAllGlobal() const; + private: /// @brief Statistics container diff --git a/src/lib/stats/stats_mgr.cc b/src/lib/stats/stats_mgr.cc index 3d0bf32559..cbb7b32625 100644 --- a/src/lib/stats/stats_mgr.cc +++ b/src/lib/stats/stats_mgr.cc @@ -295,11 +295,22 @@ StatsMgr::getAll() const { return (getAllInternal()); } +ConstElementPtr +StatsMgr::getAllGlobal() const { + MultiThreadingLock lock(*mutex_); + return (getAllGlobalInternal()); +} + ConstElementPtr StatsMgr::getAllInternal() const { return (global_->getAll()); } +ConstElementPtr +StatsMgr::getAllGlobalInternal() const { + return (global_->getAllGlobal()); +} + void StatsMgr::resetAll() { MultiThreadingLock lock(*mutex_); @@ -437,6 +448,13 @@ StatsMgr::statisticGetAllHandler(const string& /*name*/, return (createAnswer(CONTROL_RESULT_SUCCESS, all_stats)); } +ConstElementPtr +StatsMgr::statisticGlobalGetAllHandler(const string& /*name*/, + const ConstElementPtr& /*params*/) { + ConstElementPtr all_stats = StatsMgr::instance().getAllGlobal(); + return (createAnswer(CONTROL_RESULT_SUCCESS, all_stats)); +} + ConstElementPtr StatsMgr::statisticResetAllHandler(const string& /*name*/, const ConstElementPtr& /*params*/) { diff --git a/src/lib/stats/stats_mgr.h b/src/lib/stats/stats_mgr.h index f49ab8ab7c..5ddf71537e 100644 --- a/src/lib/stats/stats_mgr.h +++ b/src/lib/stats/stats_mgr.h @@ -259,6 +259,11 @@ public: /// @return JSON structures representing all statistics isc::data::ConstElementPtr getAll() const; + /// @brief Returns all global statistics (omitting subnet statistics) as a JSON structure. + /// + /// @return JSON structures representing all global statistics (omitting subnet statistics) + isc::data::ConstElementPtr getAllGlobal() const; + /// @} /// @brief Returns an observation. @@ -413,11 +418,23 @@ public: /// /// @param name name of the command (ignored, should be "statistic-get-all") /// @param params ignored - /// @return answer containing values of all statistic + /// @return answer containing values of all statistics static isc::data::ConstElementPtr statisticGetAllHandler(const std::string& name, const isc::data::ConstElementPtr& params); + /// @brief Handles statistic-global-get-all command + /// + /// This method handles statistic-global-get-all command, which returns values + /// of all global statistics (omitting subnet statistics). Params parameter is ignored. + /// + /// @param name name of the command (ignored, should be "statistic-global-get-all") + /// @param params ignored + /// @return answer containing values of all global statistics (omitting subnet statistics) + static isc::data::ConstElementPtr + statisticGlobalGetAllHandler(const std::string& name, + const isc::data::ConstElementPtr& params); + /// @brief Handles statistic-reset-all command /// /// This method handles statistic-reset-all command, which sets values of @@ -731,6 +748,13 @@ private: /// @return JSON structures representing all statistics isc::data::ConstElementPtr getAllInternal() const; + /// @brief Returns all global statistics (omitting subnet statistics) as a JSON structure. + /// + /// Should be called in a thread safe context. + /// + /// @return JSON structures representing all global statistics (omitting subnet statistics) + isc::data::ConstElementPtr getAllGlobalInternal() const; + /// @private /// @brief Utility method that attempts to extract statistic name diff --git a/src/lib/stats/tests/stats_mgr_unittest.cc b/src/lib/stats/tests/stats_mgr_unittest.cc index 734d134c8d..5da3483894 100644 --- a/src/lib/stats/tests/stats_mgr_unittest.cc +++ b/src/lib/stats/tests/stats_mgr_unittest.cc @@ -693,17 +693,20 @@ TEST_F(StatsMgrTest, commandGetAll) { StatsMgr::instance().setValue("beta", 12.34); StatsMgr::instance().setValue("gamma", dur1234); StatsMgr::instance().setValue("delta", "Lorem ipsum"); + StatsMgr::instance().setValue("subnet", static_cast(5678)); // Now get them. They're used to generate expected output ConstElementPtr rep_alpha = StatsMgr::instance().get("alpha"); ConstElementPtr rep_beta = StatsMgr::instance().get("beta"); ConstElementPtr rep_gamma = StatsMgr::instance().get("gamma"); ConstElementPtr rep_delta = StatsMgr::instance().get("delta"); + ConstElementPtr rep_subnet = StatsMgr::instance().get("subnet"); ASSERT_TRUE(rep_alpha); ASSERT_TRUE(rep_beta); ASSERT_TRUE(rep_gamma); ASSERT_TRUE(rep_delta); + ASSERT_TRUE(rep_subnet); std::string exp_str_alpha = "[ [ 1234, \"" + isc::util::clockToText(StatsMgr::instance().getObservation("alpha") @@ -717,6 +720,9 @@ TEST_F(StatsMgrTest, commandGetAll) { std::string exp_str_delta = "[ [ \"Lorem ipsum\", \"" + isc::util::clockToText(StatsMgr::instance().getObservation("delta") ->getString().second) + "\" ] ]"; + std::string exp_str_subnet = "[ [ 5678, \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("subnet") + ->getInteger().second) + "\" ] ]"; // Check that all of them can be reported at once ConstElementPtr rsp = StatsMgr::instance().statisticGetAllHandler( @@ -727,6 +733,68 @@ TEST_F(StatsMgrTest, commandGetAll) { ASSERT_EQ(0, status_code); ASSERT_TRUE(rep_all); + // Verifying this is a bit more involved, as we don't know whether the + // order would be preserved or not. + EXPECT_EQ(5, rep_all->size()); + ASSERT_TRUE(rep_all->get("alpha")); + ASSERT_TRUE(rep_all->get("beta")); + ASSERT_TRUE(rep_all->get("delta")); + ASSERT_TRUE(rep_all->get("gamma")); + ASSERT_TRUE(rep_all->get("subnet")); + EXPECT_FALSE(rep_all->get("epsilon")); + + EXPECT_EQ(exp_str_alpha, rep_all->get("alpha")->str()); + EXPECT_EQ(exp_str_beta, rep_all->get("beta")->str()); + EXPECT_EQ(exp_str_gamma, rep_all->get("gamma")->str()); + EXPECT_EQ(exp_str_delta, rep_all->get("delta")->str()); + EXPECT_EQ(exp_str_subnet, rep_all->get("subnet")->str()); +} + +// This test checks whether statistic-global-get-all command returns all statistics +// correctly. +TEST_F(StatsMgrTest, commandGlobalGetAll) { + // Set a couple of statistics + StatsMgr::instance().setValue("alpha", static_cast(1234)); + StatsMgr::instance().setValue("beta", 12.34); + StatsMgr::instance().setValue("gamma", dur1234); + StatsMgr::instance().setValue("delta", "Lorem ipsum"); + StatsMgr::instance().setValue("subnet", static_cast(5678)); + + // Now get them. They're used to generate expected output + ConstElementPtr rep_alpha = StatsMgr::instance().get("alpha"); + ConstElementPtr rep_beta = StatsMgr::instance().get("beta"); + ConstElementPtr rep_gamma = StatsMgr::instance().get("gamma"); + ConstElementPtr rep_delta = StatsMgr::instance().get("delta"); + ConstElementPtr rep_subnet = StatsMgr::instance().get("subnet"); + + ASSERT_TRUE(rep_alpha); + ASSERT_TRUE(rep_beta); + ASSERT_TRUE(rep_gamma); + ASSERT_TRUE(rep_delta); + ASSERT_TRUE(rep_subnet); + + std::string exp_str_alpha = "[ [ 1234, \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("alpha") + ->getInteger().second) + "\" ] ]"; + std::string exp_str_beta = "[ [ 12.34, \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("beta") + ->getFloat().second) + "\" ] ]"; + std::string exp_str_gamma = "[ [ \"01:02:03.004000\", \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("gamma") + ->getDuration().second) + "\" ] ]"; + std::string exp_str_delta = "[ [ \"Lorem ipsum\", \"" + + isc::util::clockToText(StatsMgr::instance().getObservation("delta") + ->getString().second) + "\" ] ]"; + + // Check that all of them can be reported at once + ConstElementPtr rsp = StatsMgr::instance().statisticGlobalGetAllHandler( + "statistic-global-get-all", ElementPtr()); + ASSERT_TRUE(rsp); + int status_code; + ConstElementPtr rep_all = parseAnswer(status_code, rsp); + ASSERT_EQ(0, status_code); + ASSERT_TRUE(rep_all); + // Verifying this is a bit more involved, as we don't know whether the // order would be preserved or not. EXPECT_EQ(4, rep_all->size()); @@ -734,6 +802,7 @@ TEST_F(StatsMgrTest, commandGetAll) { ASSERT_TRUE(rep_all->get("beta")); ASSERT_TRUE(rep_all->get("delta")); ASSERT_TRUE(rep_all->get("gamma")); + ASSERT_FALSE(rep_all->get("subnet")); EXPECT_FALSE(rep_all->get("epsilon")); EXPECT_EQ(exp_str_alpha, rep_all->get("alpha")->str()); diff --git a/src/share/api/statistic-global-get-all.json b/src/share/api/statistic-global-get-all.json new file mode 100644 index 0000000000..e007da5200 --- /dev/null +++ b/src/share/api/statistic-global-get-all.json @@ -0,0 +1,404 @@ +{ + "access": "read", + "avail": "3.1.2", + "brief": [ + "This command retrieves all recorded global statistics (omitting subnet statistics)." + ], + "cmd-comment": [ + "The server responds with the details of all recorded global statistics (omitting subnet statistics), with a result of 0 indicating that it iterated over all global statistics (even when the total number of global statistics is zero)." + ], + "cmd-syntax": [ + "{", + " \"command\": \"statistic-global-get-all\",", + " \"arguments\": { }", + "}" + ], + "resp-syntax": [ + "{", + " \"result\": 0,", + " \"arguments\": {", + " \"assigned-addresses\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.836096\"", + " ]", + " ],", + " \"cumulative-assigned-addresses\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.836166\"", + " ]", + " ],", + " \"declined-addresses\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.836156\"", + " ]", + " ],", + " \"pkt4-ack-received\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616247\"", + " ]", + " ],", + " \"pkt4-ack-sent\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616290\"", + " ]", + " ],", + " \"pkt4-decline-received\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616296\"", + " ]", + " ],", + " \"pkt4-discover-received\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616303\"", + " ]", + " ],", + " \"pkt4-inform-received\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616308\"", + " ]", + " ],", + " \"pkt4-nak-received\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616312\"", + " ]", + " ],", + " \"pkt4-nak-sent\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616314\"", + " ]", + " ],", + " \"pkt4-offer-received\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616318\"", + " ]", + " ],", + " \"pkt4-offer-sent\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616323\"", + " ]", + " ],", + " \"pkt4-parse-failed\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616326\"", + " ]", + " ],", + " \"pkt4-receive-drop\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616330\"", + " ]", + " ],", + " \"pkt4-received\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616335\"", + " ]", + " ],", + " \"pkt4-release-received\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616339\"", + " ]", + " ],", + " \"pkt4-request-received\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616343\"", + " ]", + " ],", + " \"pkt4-sent\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616348\"", + " ]", + " ],", + " \"pkt4-unknown-received\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616354\"", + " ]", + " ],", + " \"reclaimed-declined-addresses\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.836159\"", + " ]", + " ],", + " \"reclaimed-leases\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.836163\"", + " ]", + " ],", + " \"v4-allocation-fail\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616358\"", + " ]", + " ],", + " \"v4-allocation-fail-classes\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616363\"", + " ]", + " ],", + " \"v4-allocation-fail-no-pools\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616368\"", + " ]", + " ],", + " \"v4-allocation-fail-shared-network\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616372\"", + " ]", + " ],", + " \"v4-allocation-fail-subnet\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616376\"", + " ]", + " ],", + " \"v4-lease-reuses\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616410\"", + " ]", + " ],", + " \"v4-reservation-conflicts\": [", + " [", + " 0,", + " \"2023-06-13 20:42:46.616412\"", + " ]", + " ]", + " }", + "}", + "", + "or", + "", + "{", + " \"result\": 0,", + " \"arguments\": {", + " \"assigned-nas\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.196757\"", + " ]", + " ],", + " \"assigned-pds\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.196757\"", + " ]", + " ],", + " \"cumulative-assigned-nas\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.196757\"", + " ]", + " ],", + " \"cumulative-assigned-pds\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.196758\"", + " ]", + " ],", + " \"declined-addresses\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.196754\"", + " ]", + " ],", + " \"pkt6-advertise-received\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177731\"", + " ]", + " ],", + " \"pkt6-advertise-sent\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177739\"", + " ]", + " ],", + " \"pkt6-decline-received\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177739\"", + " ]", + " ],", + " \"pkt6-dhcpv4-query-received\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177740\"", + " ]", + " ],", + " \"pkt6-dhcpv4-response-received\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177740\"", + " ]", + " ],", + " \"pkt6-dhcpv4-response-sent\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177741\"", + " ]", + " ],", + " \"pkt6-infrequest-received\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177742\"", + " ]", + " ],", + " \"pkt6-parse-failed\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177742\"", + " ]", + " ],", + " \"pkt6-rebind-received\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177743\"", + " ]", + " ],", + " \"pkt6-receive-drop\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177743\"", + " ]", + " ],", + " \"pkt6-received\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177744\"", + " ]", + " ],", + " \"pkt6-release-received\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177744\"", + " ]", + " ],", + " \"pkt6-renew-received\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177745\"", + " ]", + " ],", + " \"pkt6-reply-received\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177745\"", + " ]", + " ],", + " \"pkt6-reply-sent\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177746\"", + " ]", + " ],", + " \"pkt6-request-received\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177747\"", + " ]", + " ],", + " \"pkt6-sent\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177747\"", + " ]", + " ],", + " \"pkt6-solicit-received\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177748\"", + " ]", + " ],", + " \"pkt6-unknown-received\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177748\"", + " ]", + " ],", + " \"reclaimed-declined-addresses\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.196755\"", + " ]", + " ],", + " \"reclaimed-leases\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.196756\"", + " ]", + " ],", + " \"v6-allocation-fail\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177749\"", + " ]", + " ],", + " \"v6-allocation-fail-classes\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177755\"", + " ]", + " ],", + " \"v6-allocation-fail-no-pools\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177756\"", + " ]", + " ],", + " \"v6-allocation-fail-shared-network\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177756\"", + " ]", + " ],", + " \"v6-allocation-fail-subnet\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177757\"", + " ]", + " ],", + " \"v6-ia-na-lease-reuses\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177757\"", + " ]", + " ],", + " \"v6-ia-pd-lease-reuses\": [", + " [", + " 0,", + " \"2023-06-13 21:28:57.177758\"", + " ]", + " ]", + " }", + "}" + ], + + "description": "See ", + "name": "statistic-global-get-all", + "support": [ + "kea-dhcp4", + "kea-dhcp6" + ] +}