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/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_ */ 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); 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();