#include <linux/major.h>
#include <linux/types.h>
])
+ AC_CHECK_HEADERS([sys/sysmacros.h])
else
have_linux_raid_md_u_h="no"
fi
syntax = "proto3";
package collectd;
+option go_package = "collectd.org/rpc/proto";
import "types.proto";
service Collectd {
- // Dispatch collected values to collectd.
- rpc DispatchValues(DispatchValuesRequest) returns (DispatchValuesReply);
-
- // Query a list of values available from collectd's value cache.
- rpc QueryValues(QueryValuesRequest) returns (QueryValuesReply);
+ // DispatchValues reads the value lists from the DispatchValuesRequest stream.
+ // The gRPC server embedded into collectd will inject them into the system
+ // just like the network plugin.
+ rpc DispatchValues(stream DispatchValuesRequest)
+ returns (DispatchValuesResponse);
+
+ // QueryValues returns a stream of matching value lists from collectd's
+ // internal cache.
+ rpc QueryValues(QueryValuesRequest) returns (stream QueryValuesResponse);
}
// The arguments to DispatchValues.
message DispatchValuesRequest {
- collectd.types.ValueList values = 1;
+ // value_list is the metric to be sent to the server.
+ collectd.types.ValueList value_list = 1;
}
// The response from DispatchValues.
-message DispatchValuesReply {
-}
+message DispatchValuesResponse {}
// The arguments to QueryValues.
message QueryValuesRequest {
- // Query by the fields of the identifier. Only return values matching the
- // specified shell wildcard patterns (see fnmatch(3)). Use '*' to match
- // any value.
- collectd.types.Identifier identifier = 1;
+ // Query by the fields of the identifier. Only return values matching the
+ // specified shell wildcard patterns (see fnmatch(3)). Use '*' to match
+ // any value.
+ collectd.types.Identifier identifier = 1;
}
// The response from QueryValues.
-message QueryValuesReply {
- repeated collectd.types.ValueList values = 1;
-}
+message QueryValuesResponse { collectd.types.ValueList value_list = 1; }
syntax = "proto3";
package collectd.types;
+option go_package = "collectd.org/rpc/proto/types";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
message Identifier {
- string host = 1;
- string plugin = 2;
- string plugin_instance = 3;
- string type = 4;
- string type_instance = 5;
+ string host = 1;
+ string plugin = 2;
+ string plugin_instance = 3;
+ string type = 4;
+ string type_instance = 5;
}
message Value {
- oneof value {
- uint64 counter = 1;
- double gauge = 2;
- int64 derive = 3;
- uint64 absolute = 4;
- };
+ oneof value {
+ uint64 counter = 1;
+ double gauge = 2;
+ int64 derive = 3;
+ uint64 absolute = 4;
+ };
}
message ValueList {
- repeated Value value = 1;
+ repeated Value values = 1;
- google.protobuf.Timestamp time = 2;
- google.protobuf.Duration interval = 3;
+ google.protobuf.Timestamp time = 2;
+ google.protobuf.Duration interval = 3;
- Identifier identifier = 4;
+ Identifier identifier = 4;
+
+ repeated string ds_names = 5;
}
#include "plugin.h"
#include "common.h"
-#include "configfile.h"
#include "meta_data.h"
#include "utils_cache.h" /* for uc_get_rate() */
#include "utils_subst.h"
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include <curl/curl.h>
#include "common.h" /* rrd_update_file */
#include "plugin.h" /* plugin_register, plugin_submit */
-#include "configfile.h" /* cf_register */
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include <curl/curl.h>
#include <libxml/parser.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
/* Some versions of libcurl don't include this themselves and then don't have
* fd_set available. */
#if HAVE_YAJL_YAJL_VERSION_H
#include <yajl/yajl_version.h>
#endif
+#ifdef HAVE_SYS_CAPABILITY_H
+# include <sys/capability.h>
+#endif
#include <limits.h>
#include <poll.h>
static int ceph_init(void)
{
int ret;
+
+#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_DAC_OVERRIDE)
+ if (check_capability (CAP_DAC_OVERRIDE) != 0)
+ {
+ if (getuid () == 0)
+ WARNING ("ceph plugin: Running collectd as root, but the "
+ "CAP_DAC_OVERRIDE capability is missing. The plugin's read "
+ "function will probably fail. Is your init system dropping "
+ "capabilities?");
+ else
+ WARNING ("ceph plugin: collectd doesn't have the CAP_DAC_OVERRIDE "
+ "capability. If you don't want to run collectd as root, try running "
+ "\"setcap cap_dac_override=ep\" on the collectd binary.");
+ }
+#endif
+
ceph_daemons_print();
ret = cconn_main_loop(ASOK_REQ_VERSION);
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_mount.h"
#include "utils_ignorelist.h"
#</Plugin>
#<Plugin grpc>
-# WorkerThreads 5
# <Listen "0.0.0.0" "50051">
# EnableSSL true
# SSLRootCerts "/path/to/root.pem"
=back
-=item B<WorkerThreads> I<Num>
-
-Number of threads to start for handling incoming connections. The default
-value is B<5>.
-
=back
=head2 Plugin C<hddtemp>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_curl_stats.h"
#include "utils_match.h"
#include "utils_time.h"
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_avltree.h"
#include "utils_complain.h"
#include "utils_curl_stats.h"
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_curl_stats.h"
#include "utils_llist.h"
# include <arpa/inet.h>
#endif
+#ifdef HAVE_SYS_CAPABILITY_H
+# include <sys/capability.h>
+#endif
+
#ifdef HAVE_LIBKSTAT
extern kstat_ctl_t *kc;
#endif
sfree (array[i]);
sfree (array);
} /* }}} void strarray_free */
+
+#ifdef HAVE_SYS_CAPABILITY_H
+int check_capability (int capability) /* {{{ */
+{
+#ifdef _LINUX_CAPABILITY_VERSION_3
+ cap_user_header_t cap_header = calloc(1, sizeof (*cap_header));
+ if (cap_header == NULL)
+ {
+ ERROR("check_capability: calloc failed");
+ return (-1);
+ }
+
+ cap_user_data_t cap_data = calloc(1, sizeof (*cap_data));
+ if (cap_data == NULL)
+ {
+ ERROR("check_capability: calloc failed");
+ sfree(cap_header);
+ return (-1);
+ }
+
+ cap_header->pid = getpid();
+ cap_header->version = _LINUX_CAPABILITY_VERSION;
+ if (capget(cap_header, cap_data) < 0)
+ {
+ ERROR("check_capability: capget failed");
+ sfree(cap_header);
+ sfree(cap_data);
+ return (-1);
+ }
+
+ if ((cap_data->effective & (1 << capability)) == 0)
+ {
+ sfree(cap_header);
+ sfree(cap_data);
+ return (-1);
+ }
+ else
+ {
+ sfree(cap_header);
+ sfree(cap_data);
+ return (0);
+ }
+#else
+ WARNING ("check_capability: unsupported capability implementation. "
+ "Some plugin(s) may require elevated privileges to work properly.");
+ return (0);
+#endif /* _LINUX_CAPABILITY_VERSION_3 */
+} /* }}} int check_capability */
+#endif /* HAVE_SYS_CAPABILITY_H */
int strarray_add (char ***ret_array, size_t *ret_array_len, char const *str);
void strarray_free (char **array, size_t array_len);
+#ifdef HAVE_SYS_CAPABILITY_H
+/** Check if the current process benefits from the capability passed in
+ * argument. Returns zero if it does, less than zero if it doesn't or on error.
+ * See capabilities(7) for the list of possible capabilities.
+ * */
+int check_capability (int capability);
+#endif /* HAVE_SYS_CAPABILITY_H */
+
#endif /* COMMON_H */
if (data->ds_type & UTILS_MATCH_CF_DERIVE_INC)
{
- data->value.counter++;
+ data->value.derive++;
data->values_num++;
return (0);
}
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_db_query.h"
#include <dbi/dbi.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_mount.h"
#include "utils_ignorelist.h"
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_dns.h"
#include <poll.h>
#include <pcap.h>
+#ifdef HAVE_SYS_CAPABILITY_H
+# include <sys/capability.h>
+#endif
+
/*
* Private data types
*/
listen_thread_init = 1;
+#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_NET_RAW)
+ if (check_capability (CAP_NET_RAW) != 0)
+ {
+ if (getuid () == 0)
+ WARNING ("dns plugin: Running collectd as root, but the CAP_NET_RAW "
+ "capability is missing. The plugin's read function will probably "
+ "fail. Is your init system dropping capabilities?");
+ else
+ WARNING ("dns plugin: collectd doesn't have the CAP_NET_RAW capability. "
+ "If you don't want to run collectd as root, try running \"setcap "
+ "cap_net_raw=ep\" on the collectd binary.");
+ }
+#endif
+
return (0);
} /* int dns_init */
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
-
#include <stddef.h>
#include <sys/un.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_avltree.h"
#include "utils_complain.h"
#include <grp.h>
#include <signal.h>
+#ifdef HAVE_SYS_CAPABILITY_H
+# include <sys/capability.h>
+#endif
+
#define PL_NORMAL 0x01
#define PL_NOTIF_ACTION 0x02
sigaction (SIGCHLD, &sa, NULL);
+#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_SETUID) && defined(CAP_SETGID)
+ if ((check_capability (CAP_SETUID) != 0) ||
+ (check_capability (CAP_SETGID) != 0))
+ {
+ if (getuid () == 0)
+ WARNING ("exec plugin: Running collectd as root, but the CAP_SETUID "
+ "or CAP_SETGID capabilities are missing. The plugin's read function "
+ "will probably fail. Is your init system dropping capabilities?");
+ else
+ WARNING ("exec plugin: collectd doesn't have the CAP_SETUID or "
+ "CAP_SETGID capabilities. If you don't want to run collectd as root, "
+ "try running \"setcap 'cap_setuid=ep cap_setgid=ep'\" on the "
+ "collectd binary.");
+ }
+#endif
+
return (0);
} /* int exec_init }}} */
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
static const char *config_keys[] = {
#include "plugin.h"
#include "common.h"
-#include "configfile.h"
#include "utils_avltree.h"
#if HAVE_NETDB_H
#include "common.h"
#include "plugin.h"
#include "utils_time.h"
-#include "configfile.h"
#define CGPS_TRUE 1
#define CGPS_FALSE 0
#include <fstream>
#include <iostream>
+#include <queue>
#include <vector>
#include "collectd.grpc.pb.h"
#include "collectd.h"
#include "common.h"
-#include "configfile.h"
#include "plugin.h"
#include "daemon/utils_cache.h"
using collectd::Collectd;
using collectd::DispatchValuesRequest;
-using collectd::DispatchValuesReply;
+using collectd::DispatchValuesResponse;
using collectd::QueryValuesRequest;
-using collectd::QueryValuesReply;
+using collectd::QueryValuesResponse;
using google::protobuf::util::TimeUtil;
msg->set_allocated_interval(new google::protobuf::Duration(d));
for (size_t i = 0; i < vl->values_len; ++i) {
- auto v = msg->add_value();
+ auto v = msg->add_values();
switch (ds->ds[i].type) {
case DS_TYPE_COUNTER:
v->set_counter(vl->values[i].counter);
return grpc::Status(grpc::StatusCode::INTERNAL,
grpc::string("unknown value type"));
}
+
+ auto name = msg->add_ds_names();
+ name->assign(ds->ds[i].name);
}
return grpc::Status::OK;
size_t values_len = 0;
status = grpc::Status::OK;
- for (auto v : msg.value()) {
+ for (auto v : msg.values()) {
value_t *val = (value_t *)realloc(values, (values_len + 1) * sizeof(*values));
if (!val) {
status = grpc::Status(grpc::StatusCode::RESOURCE_EXHAUSTED,
} /* unmarshal_value_list() */
/*
- * request call-backs and call objects
+ * Collectd service
*/
-
-static grpc::Status Process(grpc::ServerContext *ctx,
- DispatchValuesRequest request, DispatchValuesReply *reply)
-{
- value_list_t vl = VALUE_LIST_INIT;
- auto status = unmarshal_value_list(request.values(), &vl);
- if (!status.ok())
- return status;
-
- if (plugin_dispatch_values(&vl))
- status = grpc::Status(grpc::StatusCode::INTERNAL,
- grpc::string("failed to enqueue values for writing"));
- return status;
-} /* Process(): DispatchValues */
-
-static grpc::Status Process(grpc::ServerContext *ctx,
- QueryValuesRequest request, QueryValuesReply *reply)
-{
- uc_iter_t *iter;
- char *name = NULL;
-
- value_list_t matcher;
- auto status = unmarshal_ident(request.identifier(), &matcher, false);
- if (!status.ok())
- return status;
-
- if ((iter = uc_get_iterator()) == NULL) {
- return grpc::Status(grpc::StatusCode::INTERNAL,
- grpc::string("failed to query values: cannot create iterator"));
- }
-
- status = grpc::Status::OK;
- while (uc_iterator_next(iter, &name) == 0) {
- value_list_t res;
- if (parse_identifier_vl(name, &res) != 0) {
- status = grpc::Status(grpc::StatusCode::INTERNAL,
- grpc::string("failed to parse identifier"));
- break;
+class CollectdImpl : public collectd::Collectd::Service {
+public:
+ grpc::Status QueryValues(grpc::ServerContext *ctx, QueryValuesRequest const *req, grpc::ServerWriter<QueryValuesResponse> *writer) override {
+ value_list_t match;
+ auto status = unmarshal_ident(req->identifier(), &match, false);
+ if (!status.ok()) {
+ return status;
}
- if (!ident_matches(&res, &matcher))
- continue;
-
- if (uc_iterator_get_time(iter, &res.time) < 0) {
- status = grpc::Status(grpc::StatusCode::INTERNAL,
- grpc::string("failed to retrieve value timestamp"));
- break;
+ std::queue<value_list_t> value_lists;
+ status = this->queryValuesRead(&match, &value_lists);
+ if (status.ok()) {
+ status = this->queryValuesWrite(ctx, writer, &value_lists);
}
- if (uc_iterator_get_interval(iter, &res.interval) < 0) {
- status = grpc::Status(grpc::StatusCode::INTERNAL,
- grpc::string("failed to retrieve value interval"));
- break;
- }
- if (uc_iterator_get_values(iter, &res.values, &res.values_len) < 0) {
- status = grpc::Status(grpc::StatusCode::INTERNAL,
- grpc::string("failed to retrieve values"));
- break;
+
+ while (!value_lists.empty()) {
+ auto vl = value_lists.front();
+ value_lists.pop();
+ sfree(vl.values);
}
- auto vl = reply->add_values();
- status = marshal_value_list(&res, vl);
- free(res.values);
- if (!status.ok())
- break;
+ return status;
}
- uc_iterator_destroy(iter);
-
- return status;
-} /* Process(): QueryValues */
-
-class Call
-{
-public:
- Call(Collectd::AsyncService *service, grpc::ServerCompletionQueue *cq)
- : service_(service), cq_(cq), status_(CREATE)
- { }
+ grpc::Status DispatchValues(grpc::ServerContext *ctx,
+ grpc::ServerReader<DispatchValuesRequest> *reader,
+ DispatchValuesResponse *res) override {
+ DispatchValuesRequest req;
- virtual ~Call()
- { }
+ while (reader->Read(&req)) {
+ value_list_t vl = VALUE_LIST_INIT;
+ auto status = unmarshal_value_list(req.value_list(), &vl);
+ if (!status.ok())
+ return status;
- void Handle()
- {
- if (status_ == CREATE) {
- Create();
- status_ = PROCESS;
- }
- else if (status_ == PROCESS) {
- Process();
- status_ = FINISH;
- }
- else {
- GPR_ASSERT(status_ == FINISH);
- Finish();
+ if (plugin_dispatch_values(&vl))
+ return grpc::Status(grpc::StatusCode::INTERNAL,
+ grpc::string("failed to enqueue values for writing"));
}
- } /* Handle() */
-protected:
- virtual void Create() = 0;
- virtual void Process() = 0;
- virtual void Finish() = 0;
-
- Collectd::AsyncService *service_;
- grpc::ServerCompletionQueue *cq_;
- grpc::ServerContext ctx_;
+ res->Clear();
+ return grpc::Status::OK;
+ }
private:
- enum CallStatus { CREATE, PROCESS, FINISH };
- CallStatus status_;
-}; /* class Call */
+ grpc::Status queryValuesRead(value_list_t const *match, std::queue<value_list_t> *value_lists) {
+ uc_iter_t *iter;
+ if ((iter = uc_get_iterator()) == NULL) {
+ return grpc::Status(grpc::StatusCode::INTERNAL,
+ grpc::string("failed to query values: cannot create iterator"));
+ }
-template<typename RequestT, typename ReplyT>
-class RpcCall final : public Call
-{
- typedef void (Collectd::AsyncService::*CreatorT)(grpc::ServerContext *,
- RequestT *, grpc::ServerAsyncResponseWriter<ReplyT> *,
- grpc::CompletionQueue *, grpc::ServerCompletionQueue *, void *);
+ grpc::Status status = grpc::Status::OK;
+ char *name = NULL;
+ while (uc_iterator_next(iter, &name) == 0) {
+ value_list_t vl;
+ if (parse_identifier_vl(name, &vl) != 0) {
+ status = grpc::Status(grpc::StatusCode::INTERNAL,
+ grpc::string("failed to parse identifier"));
+ break;
+ }
-public:
- RpcCall(Collectd::AsyncService *service,
- CreatorT creator, grpc::ServerCompletionQueue *cq)
- : Call(service, cq), creator_(creator), responder_(&ctx_)
- {
- Handle();
- } /* RpcCall() */
+ if (!ident_matches(&vl, match))
+ continue;
- virtual ~RpcCall()
- { }
+ if (uc_iterator_get_time(iter, &vl.time) < 0) {
+ status = grpc::Status(grpc::StatusCode::INTERNAL,
+ grpc::string("failed to retrieve value timestamp"));
+ break;
+ }
+ if (uc_iterator_get_interval(iter, &vl.interval) < 0) {
+ status = grpc::Status(grpc::StatusCode::INTERNAL,
+ grpc::string("failed to retrieve value interval"));
+ break;
+ }
+ if (uc_iterator_get_values(iter, &vl.values, &vl.values_len) < 0) {
+ status = grpc::Status(grpc::StatusCode::INTERNAL,
+ grpc::string("failed to retrieve values"));
+ break;
+ }
-private:
- void Create()
- {
- (service_->*creator_)(&ctx_, &request_, &responder_, cq_, cq_, this);
- } /* Create() */
+ value_lists->push(vl);
+ } // while (uc_iterator_next(iter, &name) == 0)
- void Process()
- {
- // Add a new request object to the queue.
- new RpcCall<RequestT, ReplyT>(service_, creator_, cq_);
- grpc::Status status = ::Process(&ctx_, request_, &reply_);
- responder_.Finish(reply_, status, this);
- } /* Process() */
+ uc_iterator_destroy(iter);
+ return status;
+ }
- void Finish()
- {
- delete this;
- } /* Finish() */
+ grpc::Status queryValuesWrite(grpc::ServerContext *ctx,
+ grpc::ServerWriter<QueryValuesResponse> *writer,
+ std::queue<value_list_t> *value_lists) {
+ while (!value_lists->empty()) {
+ auto vl = value_lists->front();
+ QueryValuesResponse res;
+ res.Clear();
+
+ auto status = marshal_value_list(&vl, res.mutable_value_list());
+ if (!status.ok()) {
+ return status;
+ }
- CreatorT creator_;
+ if (!writer->Write(res)) {
+ return grpc::Status::CANCELLED;
+ }
- RequestT request_;
- ReplyT reply_;
+ value_lists->pop();
+ sfree(vl.values);
+ }
- grpc::ServerAsyncResponseWriter<ReplyT> responder_;
-}; /* class RpcCall */
+ return grpc::Status::OK;
+ }
+};
/*
* gRPC server implementation
*/
-
class CollectdServer final
{
public:
}
}
- builder.RegisterService(&service_);
- cq_ = builder.AddCompletionQueue();
+ builder.RegisterService(&collectd_service_);
+
server_ = builder.BuildAndStart();
} /* Start() */
void Shutdown()
{
server_->Shutdown();
- cq_->Shutdown();
} /* Shutdown() */
- void Mainloop()
- {
- // Register request types.
- new RpcCall<DispatchValuesRequest, DispatchValuesReply>(&service_,
- &Collectd::AsyncService::RequestDispatchValues, cq_.get());
- new RpcCall<QueryValuesRequest, QueryValuesReply>(&service_,
- &Collectd::AsyncService::RequestQueryValues, cq_.get());
-
- while (true) {
- void *req = NULL;
- bool ok = false;
-
- if (!cq_->Next(&req, &ok))
- break; // Queue shut down.
- if (!ok) {
- ERROR("grpc: Failed to read from queue");
- break;
- }
-
- static_cast<Call *>(req)->Handle();
- }
- } /* Mainloop() */
-
private:
- Collectd::AsyncService service_;
+ CollectdImpl collectd_service_;
std::unique_ptr<grpc::Server> server_;
- std::unique_ptr<grpc::ServerCompletionQueue> cq_;
}; /* class CollectdServer */
static CollectdServer *server = nullptr;
/*
* collectd plugin interface
*/
-
extern "C" {
- static pthread_t *workers;
- static size_t workers_num = 5;
-
- static void *worker_thread(void *arg)
- {
- CollectdServer *s = (CollectdServer *)arg;
- s->Mainloop();
- return NULL;
- } /* worker_thread() */
-
static int c_grpc_config_listen(oconfig_item_t *ci)
{
if ((ci->values_num != 2)
if (c_grpc_config_listen(child))
return -1;
}
- else if (!strcasecmp("WorkerThreads", child->key)) {
- int n;
- if (cf_util_get_int(child, &n))
- return -1;
- workers_num = (size_t)n;
- }
else {
WARNING("grpc: Option `%s` not allowed here.", child->key);
}
static int c_grpc_init(void)
{
server = new CollectdServer();
- size_t i;
-
- if (! server) {
+ if (!server) {
ERROR("grpc: Failed to create server");
return -1;
}
- workers = (pthread_t *)calloc(workers_num, sizeof(*workers));
- if (! workers) {
- delete server;
- server = nullptr;
-
- ERROR("grpc: Failed to allocate worker threads");
- return -1;
- }
-
server->Start();
- for (i = 0; i < workers_num; i++) {
- plugin_thread_create(&workers[i], /* attr = */ NULL,
- worker_thread, server);
- }
- INFO("grpc: Started %zu workers", workers_num);
return 0;
} /* c_grpc_init() */
static int c_grpc_shutdown(void)
{
- size_t i;
-
if (!server)
- return -1;
+ return 0;
server->Shutdown();
- INFO("grpc: Waiting for %zu workers to terminate", workers_num);
- for (i = 0; i < workers_num; i++)
- pthread_join(workers[i], NULL);
- free(workers);
- workers = NULL;
- workers_num = 0;
-
delete server;
server = nullptr;
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
# include <netdb.h>
# include <netinet/in.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_ignorelist.h"
#if HAVE_SYS_TYPES_H
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#if KERNEL_LINUX
/* _GNU_SOURCE is needed for struct shm_info.used_ids on musl libc */
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include <libiptc/libiptc.h>
#include <libiptc/libip6tc.h>
+#ifdef HAVE_SYS_CAPABILITY_H
+# include <sys/capability.h>
+#endif
+
/*
* iptc_handle_t was available before libiptc was officially available as a
* shared library. Note, that when the shared lib was introduced, the API and
return (0);
} /* int iptables_shutdown */
+static int iptables_init (void)
+{
+#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_NET_ADMIN)
+ if (check_capability (CAP_NET_ADMIN) != 0)
+ {
+ if (getuid () == 0)
+ WARNING ("iptables plugin: Running collectd as root, but the "
+ "CAP_NET_ADMIN capability is missing. The plugin's read "
+ "function will probably fail. Is your init system dropping "
+ "capabilities?");
+ else
+ WARNING ("iptables plugin: collectd doesn't have the CAP_NET_ADMIN "
+ "capability. If you don't want to run collectd as root, try "
+ "running \"setcap cap_net_admin=ep\" on the collectd binary.");
+ }
+#endif
+ return (0);
+} /* int iptables_init */
+
void module_register (void)
{
plugin_register_config ("iptables", iptables_config,
config_keys, config_keys_num);
+ plugin_register_init ("iptables", iptables_init);
plugin_register_read ("iptables", iptables_read);
plugin_register_shutdown ("iptables", iptables_shutdown);
} /* void module_register */
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_ignorelist.h"
#if !KERNEL_LINUX
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_ignorelist.h"
#include <dirent.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include <netdb.h>
#include <netinet/in.h>
#include <linux/major.h>
#include <linux/raid/md_u.h>
+#ifdef HAVE_SYS_SYSMACROS_H
+#include <sys/sysmacros.h>
+#endif
+
#define PROC_DISKSTATS "/proc/diskstats"
#define DEV_DIR "/dev"
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_match.h"
#include <libmemcached/memcached.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include <netdb.h>
#include <sys/un.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include <netdb.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#ifdef HAVE_MYSQL_H
#include <mysql.h>
#include "plugin.h"
#include "common.h"
-#include "configfile.h"
#include "utils_fbhash.h"
#include "utils_cache.h"
#include "utils_complain.h"
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include <curl/curl.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include <glib.h>
#include <libnotify/notify.h>
#include "plugin.h"
#include "common.h"
-#include "configfile.h"
#define NAGIOS_OK 0
#define NAGIOS_WARNING 1
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#if HAVE_STDINT_H
# include <stdint.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#if defined(__APPLE__)
#pragma clang diagnostic push
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_db_query.h"
#include <oci.h>
#undef DONT_POISON_SPRINTF_YET
-#include "configfile.h"
-
#if HAVE_STDBOOL_H
# include <stdbool.h>
#endif
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include <netdb.h>
#include <poll.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_complain.h"
#include <netinet/in.h>
# include <netdb.h> /* NI_MAXHOST */
#endif
+#ifdef HAVE_SYS_CAPABILITY_H
+# include <sys/capability.h>
+#endif
+
#include <oping.h>
#ifndef NI_MAXHOST
"Will use a timeout of %gs.", ping_timeout);
}
+#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_NET_RAW)
+ if (check_capability (CAP_NET_RAW) != 0)
+ {
+ if (getuid () == 0)
+ WARNING ("ping plugin: Running collectd as root, but the CAP_NET_RAW "
+ "capability is missing. The plugin's read function will probably "
+ "fail. Is your init system dropping capabilities?");
+ else
+ WARNING ("ping plugin: collectd doesn't have the CAP_NET_RAW capability. "
+ "If you don't want to run collectd as root, try running \"setcap "
+ "cap_net_raw=ep\" on the collectd binary.");
+ }
+#endif
+
return (start_thread ());
} /* }}} int ping_init */
#include "common.h"
-#include "configfile.h"
#include "plugin.h"
#include "utils_cache.h"
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_llist.h"
#include <sys/stat.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
/* Include header files for the mach system, if they exist.. */
#if HAVE_THREAD_INFO
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include <sys/time.h>
#include <hiredis/hiredis.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_ignorelist.h"
#if defined(HAVE_SENSORS_SENSORS_H)
#include "plugin.h"
#include "common.h"
-#include "configfile.h"
#include "utils_avltree.h"
#include "utils_latency.h"
#include "common.h"
-#include "configfile.h"
#include "plugin.h"
#define log_err(...) ERROR ("table plugin: " __VA_ARGS__)
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#if HAVE_TERMIOS_H && HAVE_SYS_IOCTL_H && HAVE_MATH_H
# include <termios.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_ignorelist.h"
#if !KERNEL_LINUX
static int
check_permissions(void)
{
-#ifdef HAVE_SYS_CAPABILITY_H
- struct __user_cap_header_struct cap_header_data;
- cap_user_header_t cap_header = &cap_header_data;
- struct __user_cap_data_struct cap_data_data;
- cap_user_data_t cap_data = &cap_data_data;
- int ret = 0;
-#endif /* HAVE_SYS_CAPABILITY_H */
if (getuid() == 0) {
/* We have everything we need */
return 0;
-#ifndef HAVE_SYS_CAPABILITY_H
+#if !defined(HAVE_SYS_CAPABILITY_H) && !defined(CAP_SYS_RAWIO)
} else {
ERROR("turbostat plugin: Initialization failed: this plugin "
"requires collectd to run as root");
return -1;
}
-#else /* HAVE_SYS_CAPABILITY_H */
+#else /* HAVE_SYS_CAPABILITY_H && CAP_SYS_RAWIO */
}
- /* check for CAP_SYS_RAWIO */
- cap_header->pid = getpid();
- cap_header->version = _LINUX_CAPABILITY_VERSION;
- if (capget(cap_header, cap_data) < 0) {
- ERROR("turbostat plugin: capget failed");
- return -1;
- }
+ int ret = 0;
- if ((cap_data->effective & (1 << CAP_SYS_RAWIO)) == 0) {
+ if (check_capability(CAP_SYS_RAWIO) != 0) {
WARNING("turbostat plugin: Collectd doesn't have the "
"CAP_SYS_RAWIO capability. If you don't want to run "
"collectd as root, try running \"setcap "
"collectd a special capability (CAP_SYS_RAWIO) and read "
"access to /dev/cpu/*/msr (see previous warnings)");
return ret;
-#endif /* HAVE_SYS_CAPABILITY_H */
+#endif /* HAVE_SYS_CAPABILITY_H && CAP_SYS_RAWIO */
}
static int
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_cmd_flush.h"
#include "utils_cmd_getval.h"
#ifndef UTILS_CURL_STATS_H
#define UTILS_CURL_STATS_H 1
-#include "configfile.h"
#include "plugin.h"
#include <curl/curl.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_db_query.h"
/*
{
int status = strjoin (vl.type_instance, sizeof (vl.type_instance),
r_area->instances_buffer, r->instances_num, "-");
- if (status != 0)
+ if (status < 0)
{
ERROR ("udb_result_submit: creating type_instance failed with status %d.",
status);
int status = strjoin (tmp, sizeof (tmp), r_area->instances_buffer,
r->instances_num, "-");
- if (status != 0)
+ if (status < 0)
{
ERROR ("udb_result_submit: creating type_instance failed with status %d.",
status);
#ifndef UTILS_DB_QUERY_H
#define UTILS_DB_QUERY_H 1
-#include "configfile.h"
-
/*
* Data types
*/
* Florian octo Forster <octo at collectd.org>
*/
+/* Workaround for Solaris 10 defining label_t
+ * Issue #1301
+ */
+#if KERNEL_SOLARIS
+# ifndef _POSIX_C_SOURCE
+# define _POSIX_C_SOURCE 200112L
+# endif
+# undef __EXTENSIONS__
+#endif
+
#include "collectd.h"
#include "testing.h"
if (lc == NULL)
return (NULL);
- latency_counter_reset (lc);
lc->bin_width = HISTOGRAM_DEFAULT_BIN_WIDTH;
+ latency_counter_reset (lc);
return (lc);
} /* }}} latency_counter_t *latency_counter_create */
return;
cdtime_t bin_width = lc->bin_width;
+ cdtime_t max_bin = (lc->max - 1) / lc->bin_width;
+
+/*
+ If max latency is REDUCE_THRESHOLD times less than histogram's range,
+ then cut it in half. REDUCE_THRESHOLD must be >= 2.
+ Value of 4 is selected to reduce frequent changes of bin width.
+*/
+#define REDUCE_THRESHOLD 4
+ if ((lc->num > 0) && (lc->bin_width >= HISTOGRAM_DEFAULT_BIN_WIDTH * 2)
+ && (max_bin < HISTOGRAM_NUM_BINS / REDUCE_THRESHOLD))
+ {
+ /* new bin width will be the previous power of 2 */
+ bin_width = bin_width / 2;
+
+ DEBUG("utils_latency: latency_counter_reset: max_latency = %.3f; "
+ "max_bin = %"PRIu64"; old_bin_width = %.3f; new_bin_width = %.3f;",
+ CDTIME_T_TO_DOUBLE (lc->max),
+ max_bin,
+ CDTIME_T_TO_DOUBLE (lc->bin_width),
+ CDTIME_T_TO_DOUBLE (bin_width));
+ }
+
memset (lc, 0, sizeof (*lc));
/* preserve bin width */
#include "collectd.h"
#include "common.h"
-#include "configfile.h"
#include "plugin.h"
#if HAVE_SYS_SYSCTL_H
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#if HAVE_VARNISH_V4
#include <vapi/vsm.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_ignorelist.h"
#include "utils_complain.h"
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_complain.h"
#include "utils_format_graphite.h"
#include "plugin.h"
#include "common.h"
-#include "configfile.h"
#include "utils_cmd_putval.h"
#include "utils_format_graphite.h"
#include "utils_format_json.h"
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_format_graphite.h"
#include "plugin.h"
#include "common.h"
-#include "configfile.h"
#include "utils_cache.h"
#if HAVE_STDINT_H
#include "plugin.h"
#include "common.h"
-#include "configfile.h"
#include <sys/time.h>
#include <hiredis/hiredis.h>
#include "collectd.h"
#include "common.h"
-#include "configfile.h"
#include "plugin.h"
#include "utils_cache.h"
#include "utils_complain.h"
#include "plugin.h"
#include "common.h"
-#include "configfile.h"
#include "utils_cache.h"
#include <arpa/inet.h>
#include <errno.h>
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_cache.h"