diff --git a/lib/api/CMakeLists.txt b/lib/api/CMakeLists.txt index 458df4102..71acd90b3 100644 --- a/lib/api/CMakeLists.txt +++ b/lib/api/CMakeLists.txt @@ -35,6 +35,7 @@ set(API_SRC actions/paths.cpp actions/restart.cpp actions/node.cpp + actions/stats.cpp ) if(WITH_WEB) diff --git a/lib/api/actions/stats.cpp b/lib/api/actions/stats.cpp new file mode 100644 index 000000000..fa8316495 --- /dev/null +++ b/lib/api/actions/stats.cpp @@ -0,0 +1,79 @@ +/** The API ressource for getting and resetting statistics. + * + * @author Steffen Vogel + * @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLASnode + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *********************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace villas { +namespace node { +namespace api { + +class StatsAction : public Action { + +public: + using Action::Action; + + virtual int execute(json_t *args, json_t **resp) + { + int ret, reset = 0; + json_error_t err; + + ret = json_unpack_ex(args, &err, 0, "{ s?: b }", + "reset", &reset + ); + if (ret < 0) + return ret; + + struct vlist *nodes = session->getSuperNode()->getNodes(); + + for (size_t i = 0; i < vlist_length(nodes); i++) { + struct node *n = (struct node *) vlist_at(nodes, i); + + if (n->stats) { + if (reset) { + stats_reset(n->stats); + info("Stats resetted for node %s", node_name(n)); + } + } + } + + *resp = json_object(); + + return 0; + } + +}; + +/* Register actions */ +static ActionPlugin p1("stats", "get or reset internal statistics counters"); + +} /* namespace api */ +} /* namespace node */ +} /* namespace villas */