From 9477e41577e16b21170040984f8a4a2930ab1cc0 Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Wed, 6 May 2015 13:08:10 +0300 Subject: [PATCH 1/3] collectd: Add an API to scollectd data The scollectd is an infrastructure that allows different part of the code to register internal counters and the infrastructure would send it periodically to an external server. This patch adds and API to the scollectd that allows to inquire a register value and the names of the registered values. The collectd_value structure is used to return a single value that can be of type: double or signed and unsigned 64 bit long. The definition of the API are found in scollectd_api.hh The inquiries are for the local cpu, it is up to the caller to call a relevent cpu. Signed-off-by: Amnon Heiman --- core/scollectd.cc | 50 +++++++++++++++++++++++++++++++++++++ core/scollectd_api.hh | 58 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 core/scollectd_api.hh diff --git a/core/scollectd.cc b/core/scollectd.cc index 534fe86d89..add70efbac 100644 --- a/core/scollectd.cc +++ b/core/scollectd.cc @@ -34,6 +34,7 @@ #include "scollectd.hh" #include "core/future-util.hh" #include "net/api.hh" +#include "scollectd_api.hh" bool scollectd::type_instance_id::operator<( const scollectd::type_instance_id& id2) const { @@ -385,6 +386,20 @@ private: arm(); }); } +public: + shared_ptr get_values(const type_instance_id & id) { + return _values[id]; + } + + std::vector get_instance_ids() { + std::vector res(_values.size()); + int pos = 0; + for (auto i: _values) { + res[pos++] = i.first; + } + return res; + } + private: value_list_map _values; std::vector _regs; @@ -451,4 +466,39 @@ boost::program_options::options_description get_options_description() { "collectd host name"); return opts; } + +std::vector get_collectd_value( + shared_ptr id) { + std::vector res_values; + auto raw_types = get_impl().get_values(*id); + if (raw_types == nullptr) { + return res_values; + } + std::vector types(raw_types->size()); + raw_types->types(&(*types.begin())); + std::vector> value(raw_types->size()); + raw_types->values(&(*value.begin())); + + auto i = value.begin(); + for (auto t : types) { + collectd_value c(t, be64toh(*i)); + res_values.push_back(c); + } + return res_values; +} + +std::vector get_collectd_types( + const scollectd::type_instance_id& id) { + auto res = get_impl().get_values(id); + if (res == nullptr) { + return std::vector(); + } + std::vector vals(res->size()); + res->types(&(*vals.begin())); + return vals; +} + +std::vector get_collectd_ids() { + return get_impl().get_instance_ids(); +} } diff --git a/core/scollectd_api.hh b/core/scollectd_api.hh new file mode 100644 index 0000000000..550c4fe8d4 --- /dev/null +++ b/core/scollectd_api.hh @@ -0,0 +1,58 @@ +/* + * Copyright 2015 Cloudius Systems + */ + +#ifndef CORE_SCOLLECTD_API_HH_ +#define CORE_SCOLLECTD_API_HH_ + +#include "core/scollectd.hh" + +namespace scollectd { + +struct collectd_value { + union { + double _d; + uint64_t _ui; + int64_t _i; + } u; + scollectd::data_type _type; + collectd_value() + : _type(data_type::GAUGE) { + } + collectd_value(data_type t, uint64_t i) + : _type(t) { + u._ui = i; + } + + collectd_value& operator=(const collectd_value& c) = default; + + collectd_value& operator+=(const collectd_value& c) { + *this = *this + c; + return *this; + } + + collectd_value operator+(const collectd_value& c) { + collectd_value res(*this); + switch (_type) { + case data_type::GAUGE: + res.u._d += c.u._d; + break; + case data_type::DERIVE: + res.u._i += c.u._i; + break; + default: + res.u._ui += c.u._ui; + break; + } + return res; + } +}; + +std::vector get_collectd_value( + shared_ptr id); + +std::vector get_collectd_ids(); + +} + +#endif /* CORE_SCOLLECTD_API_HH_ */ From 3188ae6b8b30a65ad346dbe6db012147a631c5a3 Mon Sep 17 00:00:00 2001 From: Gleb Natapov Date: Mon, 11 May 2015 10:11:53 +0300 Subject: [PATCH 2/3] rpc: remove unneeded capture Also 'sent' is moved twice. I wonder how it even worked. Second move was probably done first. --- rpc/rpc_impl.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/rpc_impl.hh b/rpc/rpc_impl.hh index c44781db31..ed20bac792 100644 --- a/rpc/rpc_impl.hh +++ b/rpc/rpc_impl.hh @@ -300,7 +300,7 @@ auto send_helper(MsgType t, std::index_sequence) { auto xargs = std::tie(m->t, m->id, std::get(m->args)...); // holds references to all message elements promise<> sent; // will be fulfilled when data is sent auto fsent = sent.get_future(); - dst.out_ready() = dst.out_ready().then([&dst, xargs = std::move(xargs), m = std::move(m), sent = std::move(sent)] () mutable { + dst.out_ready() = dst.out_ready().then([&dst, xargs = std::move(xargs), m = std::move(m)] () mutable { return marshall(dst.serializer(), dst.out(), std::move(xargs)).then([m = std::move(m)] {}); }).finally([sent = std::move(sent)] () mutable { sent.set_value(); From 0e23702dfd9f45198757c38b17df84b7e94e3734 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Mon, 11 May 2015 13:33:33 +0300 Subject: [PATCH 3/3] core: add make_directory() API --- core/reactor.cc | 13 +++++++++++++ core/reactor.hh | 1 + core/seastar.hh | 1 + 3 files changed, 15 insertions(+) diff --git a/core/reactor.cc b/core/reactor.cc index 506db746dc..d80554a6a8 100644 --- a/core/reactor.cc +++ b/core/reactor.cc @@ -495,6 +495,15 @@ reactor::open_directory(sstring name) { }); } +future<> +reactor::make_directory(sstring name) { + return _thread_pool.submit>([name = std::move(name)] { + return wrap_syscall(::mkdir(name.c_str(), S_IRWXU)); + }).then([] (syscall_result sr) { + sr.throw_if_error(); + }); +} + future<> posix_file_impl::flush(void) { return engine()._thread_pool.submit>([this] { @@ -1722,6 +1731,10 @@ future open_directory(sstring name) { return engine().open_directory(std::move(name)); } +future<> make_directory(sstring name) { + return engine().make_directory(std::move(name)); +} + future<> remove_file(sstring pathname) { return engine().remove_file(std::move(pathname)); } diff --git a/core/reactor.hh b/core/reactor.hh index 7cf30b7ca3..edf21a27c3 100644 --- a/core/reactor.hh +++ b/core/reactor.hh @@ -759,6 +759,7 @@ public: future open_file_dma(sstring name, open_flags flags); future open_directory(sstring name); + future<> make_directory(sstring name); future> file_type(sstring name); future<> remove_file(sstring pathname); diff --git a/core/seastar.hh b/core/seastar.hh index 8f4bce6601..92622fd6bb 100644 --- a/core/seastar.hh +++ b/core/seastar.hh @@ -47,5 +47,6 @@ future connect(socket_address sa); // File API future open_file_dma(sstring name, open_flags flags); future open_directory(sstring name); +future<> make_directory(sstring name); future<> remove_file(sstring pathname);