index 65b05845814ec6e66601cda58bc829a279956f37..d5d732197bc519de94fe0eafc585a964233bfdf4 100644 (file)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
SDB_PLUGIN_MAGIC;
SDB_PLUGIN_MAGIC;
/* else: first/new host */
if (state->current_host) {
/* else: first/new host */
if (state->current_host) {
- sdb_log(SDB_LOG_DEBUG, "collectd::unixsock backend: Added/updated "
- "%i metric%s (%i failed) for host '%s'.",
+ sdb_log(SDB_LOG_DEBUG, "Added/updated %i metric%s (%i failed) for host '%s'.",
state->metrics_updated, state->metrics_updated == 1 ? "" : "s",
state->metrics_failed, state->current_host);
state->metrics_updated = state->metrics_failed = 0;
state->metrics_updated, state->metrics_updated == 1 ? "" : "s",
state->metrics_failed, state->current_host);
state->metrics_updated = state->metrics_failed = 0;
state->current_host = strdup(hostname);
if (! state->current_host) {
char errbuf[1024];
state->current_host = strdup(hostname);
if (! state->current_host) {
char errbuf[1024];
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to allocate "
- "string buffer: %s",
+ sdb_log(SDB_LOG_ERR, "Failed to allocate string buffer: %s",
sdb_strerror(errno, errbuf, sizeof(errbuf)));
return -1;
}
sdb_strerror(errno, errbuf, sizeof(errbuf)));
return -1;
}
status = sdb_plugin_store_host(hostname, last_update);
if (status < 0) {
status = sdb_plugin_store_host(hostname, last_update);
if (status < 0) {
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to "
- "store/update host '%s'.", hostname);
+ sdb_log(SDB_LOG_ERR, "Failed to store/update host '%s'.", hostname);
return -1;
}
else if (status > 0) /* value too old */
return 0;
return -1;
}
else if (status > 0) /* value too old */
return 0;
- sdb_log(SDB_LOG_DEBUG, "collectd::unixsock backend: Added/updated "
- "host '%s' (last update timestamp = %"PRIsdbTIME").",
+ sdb_log(SDB_LOG_DEBUG, "Added/updated host '%s' "
+ "(last update timestamp = %"PRIsdbTIME").",
hostname, last_update);
return 0;
} /* store_host */
hostname, last_update);
return 0;
} /* store_host */
char metric_id[(ud->ts_base ? strlen(ud->ts_base) : 0)
+ strlen(hostname) + sizeof(name) + 7];
char metric_id[(ud->ts_base ? strlen(ud->ts_base) : 0)
+ strlen(hostname) + sizeof(name) + 7];
- sdb_metric_store_t store = { ud->ts_type, metric_id };
+ sdb_metric_store_t store = { ud->ts_type, metric_id, NULL, last_update };
sdb_data_t data = { SDB_TYPE_STRING, { .string = NULL } };
sdb_data_t data = { SDB_TYPE_STRING, { .string = NULL } };
else
status = sdb_plugin_store_metric(hostname, name, NULL, last_update);
if (status < 0) {
else
status = sdb_plugin_store_metric(hostname, name, NULL, last_update);
if (status < 0) {
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to "
- "store/update metric '%s/%s'.", hostname, name);
+ sdb_log(SDB_LOG_ERR, "Failed to store/update metric '%s/%s'.", hostname, name);
return -1;
}
return -1;
}
hostname = strchr(hostname, ' ');
if (! hostname) {
hostname = strchr(hostname, ' ');
if (! hostname) {
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Expected to find "
- "a space character in the LISTVAL response");
+ sdb_log(SDB_LOG_ERR, "Expected to find a space character "
+ "in the LISTVAL response");
return -1;
}
*hostname = '\0';
return -1;
}
*hostname = '\0';
if (sdb_data_parse(data[0].data.string, SDB_TYPE_DATETIME, &last_update)) {
char errbuf[1024];
if (sdb_data_parse(data[0].data.string, SDB_TYPE_DATETIME, &last_update)) {
char errbuf[1024];
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to parse "
- "timestamp '%s' returned by LISTVAL: %s", data[0].data.string,
+ sdb_log(SDB_LOG_ERR, "Failed to parse timestamp '%s' "
+ "returned by LISTVAL: %s", data[0].data.string,
sdb_strerror(errno, errbuf, sizeof(errbuf)));
return -1;
}
sdb_strerror(errno, errbuf, sizeof(errbuf)));
return -1;
}
ud = SDB_OBJ_WRAPPER(user_data)->data;
if (sdb_unixsock_client_connect(ud->client)) {
ud = SDB_OBJ_WRAPPER(user_data)->data;
if (sdb_unixsock_client_connect(ud->client)) {
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: "
- "Failed to connect to collectd.");
+ sdb_log(SDB_LOG_ERR, "Failed to connect to collectd.");
return -1;
}
return -1;
}
- sdb_log(SDB_LOG_INFO, "collectd::unixsock backend: Successfully "
- "connected to collectd @ %s.",
+ sdb_log(SDB_LOG_INFO, "Successfully connected to collectd @ %s.",
sdb_unixsock_client_path(ud->client));
return 0;
} /* sdb_collectd_init */
sdb_unixsock_client_path(ud->client));
return 0;
} /* sdb_collectd_init */
state.ud = ud;
if (sdb_unixsock_client_send(ud->client, "LISTVAL") <= 0) {
state.ud = ud;
if (sdb_unixsock_client_send(ud->client, "LISTVAL") <= 0) {
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to send "
- "LISTVAL command to collectd @ %s.",
+ sdb_log(SDB_LOG_ERR, "Failed to send LISTVAL command to collectd @ %s.",
sdb_unixsock_client_path(ud->client));
return -1;
}
line = sdb_unixsock_client_recv(ud->client, buffer, sizeof(buffer));
if (! line) {
sdb_unixsock_client_path(ud->client));
return -1;
}
line = sdb_unixsock_client_recv(ud->client, buffer, sizeof(buffer));
if (! line) {
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to read "
- "status of LISTVAL command from collectd @ %s.",
+ sdb_log(SDB_LOG_ERR, "Failed to read status of LISTVAL command from collectd @ %s.",
sdb_unixsock_client_path(ud->client));
return -1;
}
sdb_unixsock_client_path(ud->client));
return -1;
}
errno = 0;
count = strtol(line, &endptr, /* base */ 0);
if (errno || (line == endptr)) {
errno = 0;
count = strtol(line, &endptr, /* base */ 0);
if (errno || (line == endptr)) {
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to parse "
- "status of LISTVAL command from collectd @ %s.",
+ sdb_log(SDB_LOG_ERR, "Failed to parse status of LISTVAL command from collectd @ %s.",
sdb_unixsock_client_path(ud->client));
return -1;
}
if (count < 0) {
sdb_unixsock_client_path(ud->client));
return -1;
}
if (count < 0) {
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to get "
- "value list from collectd @ %s: %s",
+ sdb_log(SDB_LOG_ERR, "Failed to get value list from collectd @ %s: %s",
sdb_unixsock_client_path(ud->client),
msg ? msg : line);
return -1;
sdb_unixsock_client_path(ud->client),
msg ? msg : line);
return -1;
SDB_OBJ(&state_obj), count, /* delim */ "/",
/* column count = */ 3,
SDB_TYPE_STRING, SDB_TYPE_STRING, SDB_TYPE_STRING)) {
SDB_OBJ(&state_obj), count, /* delim */ "/",
/* column count = */ 3,
SDB_TYPE_STRING, SDB_TYPE_STRING, SDB_TYPE_STRING)) {
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed "
- "to read response from collectd @ %s.",
+ sdb_log(SDB_LOG_ERR, "Failed to read response from collectd @ %s.",
sdb_unixsock_client_path(ud->client));
return -1;
}
if (state.current_host) {
sdb_unixsock_client_path(ud->client));
return -1;
}
if (state.current_host) {
- sdb_log(SDB_LOG_DEBUG, "collectd::unixsock backend: Added/updated "
- "%i metric%s (%i failed) for host '%s'.",
+ sdb_log(SDB_LOG_DEBUG, "Added/updated %i metric%s (%i failed) for host '%s'.",
state.metrics_updated, state.metrics_updated == 1 ? "" : "s",
state.metrics_failed, state.current_host);
free(state.current_host);
state.metrics_updated, state.metrics_updated == 1 ? "" : "s",
state.metrics_failed, state.current_host);
free(state.current_host);
int i;
if (oconfig_get_string(ci, &name)) {
int i;
if (oconfig_get_string(ci, &name)) {
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Instance requires "
- "a single string argument\n\tUsage: <Instance NAME>");
+ sdb_log(SDB_LOG_ERR, "Instance requires a single string argument\n"
+ "\tUsage: <Instance NAME>");
return -1;
}
ud = calloc(1, sizeof(*ud));
if (! ud) {
char errbuf[1024];
return -1;
}
ud = calloc(1, sizeof(*ud));
if (! ud) {
char errbuf[1024];
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to "
- "allocate user-data object: %s",
+ sdb_log(SDB_LOG_ERR, "Failed to allocate user-data object: %s",
sdb_strerror(errno, errbuf, sizeof(errbuf)));
return -1;
}
sdb_strerror(errno, errbuf, sizeof(errbuf)));
return -1;
}
else if (! strcasecmp(child->key, "TimeseriesBaseURL"))
oconfig_get_string(child, &ud->ts_base);
else
else if (! strcasecmp(child->key, "TimeseriesBaseURL"))
oconfig_get_string(child, &ud->ts_base);
else
- sdb_log(SDB_LOG_WARNING, "collectd::unixsock backend: Ignoring "
- "unknown config option '%s' inside <Instance %s>.",
- child->key, name);
+ sdb_log(SDB_LOG_WARNING, "Ignoring unknown config option '%s' "
+ "inside <Instance %s>.", child->key, name);
}
if ((ud->ts_type == NULL) != (ud->ts_base == NULL)) {
}
if ((ud->ts_type == NULL) != (ud->ts_base == NULL)) {
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Both options, "
- "TimeseriesBackend and TimeseriesBaseURL, have to be "
- "specified.");
+ sdb_log(SDB_LOG_ERR, "Both options, TimeseriesBackend and TimeseriesBaseURL, "
+ "have to be specified.");
ud->ts_type = ud->ts_base = NULL;
user_data_destroy(ud);
return -1;
ud->ts_type = ud->ts_base = NULL;
user_data_destroy(ud);
return -1;
* -> will require different ID generation */
if (strcasecmp(ud->ts_type, "rrdtool")
&& strcasecmp(ud->ts_type, "rrdcached")) {
* -> will require different ID generation */
if (strcasecmp(ud->ts_type, "rrdtool")
&& strcasecmp(ud->ts_type, "rrdcached")) {
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: "
- "TimeseriesBackend '%s' is not supported - "
+ sdb_log(SDB_LOG_ERR, "TimeseriesBackend '%s' is not supported - "
"use 'rrdtool' instead.", ud->ts_type);
ud->ts_type = ud->ts_base = NULL;
user_data_destroy(ud);
"use 'rrdtool' instead.", ud->ts_type);
ud->ts_type = ud->ts_base = NULL;
user_data_destroy(ud);
ud->ts_type = strdup(ud->ts_type);
ud->ts_base = strdup(ud->ts_base);
if ((! ud->ts_type) || (! ud->ts_base)) {
ud->ts_type = strdup(ud->ts_type);
ud->ts_base = strdup(ud->ts_base);
if ((! ud->ts_type) || (! ud->ts_base)) {
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed "
- "to duplicate a string");
+ sdb_log(SDB_LOG_ERR, "Failed to duplicate a string");
user_data_destroy(ud);
return -1;
}
}
if (! socket_path) {
user_data_destroy(ud);
return -1;
}
}
if (! socket_path) {
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Instance '%s' "
- "missing the 'Socket' option.", name);
+ sdb_log(SDB_LOG_ERR, "Instance '%s' missing the 'Socket' option.", name);
user_data_destroy(ud);
return -1;
}
user_data_destroy(ud);
return -1;
}
ud->client = sdb_unixsock_client_create(socket_path);
if (! ud->client) {
char errbuf[1024];
ud->client = sdb_unixsock_client_create(socket_path);
if (! ud->client) {
char errbuf[1024];
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to create "
- "unixsock client: %s",
+ sdb_log(SDB_LOG_ERR, "Failed to create unixsock client: %s",
sdb_strerror(errno, errbuf, sizeof(errbuf)));
user_data_destroy(ud);
return -1;
sdb_strerror(errno, errbuf, sizeof(errbuf)));
user_data_destroy(ud);
return -1;
user_data = sdb_object_create_wrapper("collectd-userdata", ud,
user_data_destroy);
if (! user_data) {
user_data = sdb_object_create_wrapper("collectd-userdata", ud,
user_data_destroy);
if (! user_data) {
- sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to allocate "
- "user-data wrapper object");
+ sdb_log(SDB_LOG_ERR, "Failed to allocate user-data wrapper object");
user_data_destroy(ud);
return -1;
}
user_data_destroy(ud);
return -1;
}
if (! strcasecmp(child->key, "Instance"))
sdb_collectd_config_instance(child);
else
if (! strcasecmp(child->key, "Instance"))
sdb_collectd_config_instance(child);
else
- sdb_log(SDB_LOG_WARNING, "collectd::unixsock backend: Ignoring "
- "unknown config option '%s'.", child->key);
+ sdb_log(SDB_LOG_WARNING, "Ignoring unknown config option '%s'.", child->key);
}
return 0;
} /* sdb_collectd_config */
}
return 0;
} /* sdb_collectd_config */