version 1.1.1.1, 2013/10/14 10:32:48
|
version 1.1.1.3, 2016/11/02 10:35:00
|
Line 1
|
Line 1
|
|
#include "first.h" |
|
|
#include "server.h" |
#include "server.h" |
#include "connections.h" |
#include "connections.h" |
#include "response.h" |
#include "response.h" |
Line 7
|
Line 9
|
#include "plugin.h" |
#include "plugin.h" |
#include <sys/types.h> |
#include <sys/types.h> |
|
|
|
#include <assert.h> |
#include <fcntl.h> |
#include <fcntl.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <stdio.h> |
Line 64 FREE_FUNC(mod_rrd_free) {
|
Line 67 FREE_FUNC(mod_rrd_free) {
|
for (i = 0; i < srv->config_context->used; i++) { |
for (i = 0; i < srv->config_context->used; i++) { |
plugin_config *s = p->config_storage[i]; |
plugin_config *s = p->config_storage[i]; |
|
|
|
if (NULL == s) continue; |
|
|
buffer_free(s->path_rrdtool_bin); |
buffer_free(s->path_rrdtool_bin); |
buffer_free(s->path_rrd); |
buffer_free(s->path_rrd); |
|
|
Line 169 static int mod_rrd_create_pipe(server *srv, plugin_dat
|
Line 174 static int mod_rrd_create_pipe(server *srv, plugin_dat
|
p->read_fd = from_rrdtool_fds[0]; |
p->read_fd = from_rrdtool_fds[0]; |
p->rrdtool_pid = pid; |
p->rrdtool_pid = pid; |
|
|
#ifdef FD_CLOEXEC | fd_close_on_exec(p->write_fd); |
fcntl(p->write_fd, F_SETFD, FD_CLOEXEC); | fd_close_on_exec(p->read_fd); |
fcntl(p->read_fd, F_SETFD, FD_CLOEXEC); | |
#endif | |
|
|
break; |
break; |
} |
} |
Line 265 static int mod_rrdtool_create_rrd(server *srv, plugin_
|
Line 268 static int mod_rrdtool_create_rrd(server *srv, plugin_
|
"RRA:MIN:0.5:24:775 " |
"RRA:MIN:0.5:24:775 " |
"RRA:MIN:0.5:288:797\n")); |
"RRA:MIN:0.5:288:797\n")); |
|
|
if (-1 == (safe_write(p->write_fd, p->cmd->ptr, p->cmd->used - 1))) { | if (-1 == (safe_write(p->write_fd, CONST_BUF_LEN(p->cmd)))) { |
log_error_write(srv, __FILE__, __LINE__, "ss", |
log_error_write(srv, __FILE__, __LINE__, "ss", |
"rrdtool-write: failed", strerror(errno)); |
"rrdtool-write: failed", strerror(errno)); |
|
|
return HANDLER_ERROR; |
return HANDLER_ERROR; |
} |
} |
|
|
buffer_prepare_copy(p->resp, 4096); | buffer_string_prepare_copy(p->resp, 4095); |
if (-1 == (r = safe_read(p->read_fd, p->resp->ptr, p->resp->size))) { | if (-1 == (r = safe_read(p->read_fd, p->resp->ptr, p->resp->size - 1))) { |
log_error_write(srv, __FILE__, __LINE__, "ss", |
log_error_write(srv, __FILE__, __LINE__, "ss", |
"rrdtool-read: failed", strerror(errno)); |
"rrdtool-read: failed", strerror(errno)); |
|
|
return HANDLER_ERROR; |
return HANDLER_ERROR; |
} |
} |
|
|
p->resp->used = r; | buffer_commit(p->resp, r); |
|
|
if (p->resp->ptr[0] != 'O' || |
if (p->resp->ptr[0] != 'O' || |
p->resp->ptr[1] != 'K') { |
p->resp->ptr[1] != 'K') { |
Line 338 SETDEFAULTS_FUNC(mod_rrd_set_defaults) {
|
Line 341 SETDEFAULTS_FUNC(mod_rrd_set_defaults) {
|
size_t i; |
size_t i; |
|
|
config_values_t cv[] = { |
config_values_t cv[] = { |
{ "rrdtool.binary", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, | { "rrdtool.binary", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 0 */ |
{ "rrdtool.db-name", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, | { "rrdtool.db-name", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 1 */ |
{ NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } | { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } |
}; |
}; |
|
|
if (!p) return HANDLER_ERROR; |
if (!p) return HANDLER_ERROR; |
|
|
p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *)); | force_assert(srv->config_context->used > 0); |
| p->config_storage = calloc(1, srv->config_context->used * sizeof(plugin_config *)); |
|
|
for (i = 0; i < srv->config_context->used; i++) { |
for (i = 0; i < srv->config_context->used; i++) { |
|
data_config const* config = (data_config const*)srv->config_context->data[i]; |
plugin_config *s; |
plugin_config *s; |
|
|
s = calloc(1, sizeof(plugin_config)); |
s = calloc(1, sizeof(plugin_config)); |
Line 362 SETDEFAULTS_FUNC(mod_rrd_set_defaults) {
|
Line 367 SETDEFAULTS_FUNC(mod_rrd_set_defaults) {
|
|
|
p->config_storage[i] = s; |
p->config_storage[i] = s; |
|
|
if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) { | if (0 != config_insert_values_global(srv, config->value, cv, i == 0 ? T_CONFIG_SCOPE_SERVER : T_CONFIG_SCOPE_CONNECTION)) { |
return HANDLER_ERROR; |
return HANDLER_ERROR; |
} |
} |
|
|
if (i > 0 && !buffer_is_empty(s->path_rrdtool_bin)) { | if (i > 0 && !buffer_string_is_empty(s->path_rrdtool_bin)) { |
/* path_rrdtool_bin is a global option */ |
/* path_rrdtool_bin is a global option */ |
|
|
log_error_write(srv, __FILE__, __LINE__, "s", |
log_error_write(srv, __FILE__, __LINE__, "s", |
Line 382 SETDEFAULTS_FUNC(mod_rrd_set_defaults) {
|
Line 387 SETDEFAULTS_FUNC(mod_rrd_set_defaults) {
|
|
|
/* check for dir */ |
/* check for dir */ |
|
|
if (buffer_is_empty(p->conf.path_rrdtool_bin)) { | if (buffer_string_is_empty(p->conf.path_rrdtool_bin)) { |
log_error_write(srv, __FILE__, __LINE__, "s", |
log_error_write(srv, __FILE__, __LINE__, "s", |
"rrdtool.binary has to be set"); |
"rrdtool.binary has to be set"); |
return HANDLER_ERROR; |
return HANDLER_ERROR; |
Line 409 TRIGGER_FUNC(mod_rrd_trigger) {
|
Line 414 TRIGGER_FUNC(mod_rrd_trigger) {
|
plugin_config *s = p->config_storage[i]; |
plugin_config *s = p->config_storage[i]; |
int r; |
int r; |
|
|
if (buffer_is_empty(s->path_rrd)) continue; | if (buffer_string_is_empty(s->path_rrd)) continue; |
|
|
/* write the data down every minute */ |
/* write the data down every minute */ |
|
|
Line 418 TRIGGER_FUNC(mod_rrd_trigger) {
|
Line 423 TRIGGER_FUNC(mod_rrd_trigger) {
|
buffer_copy_string_len(p->cmd, CONST_STR_LEN("update ")); |
buffer_copy_string_len(p->cmd, CONST_STR_LEN("update ")); |
buffer_append_string_buffer(p->cmd, s->path_rrd); |
buffer_append_string_buffer(p->cmd, s->path_rrd); |
buffer_append_string_len(p->cmd, CONST_STR_LEN(" N:")); |
buffer_append_string_len(p->cmd, CONST_STR_LEN(" N:")); |
buffer_append_off_t(p->cmd, s->bytes_read); | buffer_append_int(p->cmd, s->bytes_read); |
buffer_append_string_len(p->cmd, CONST_STR_LEN(":")); |
buffer_append_string_len(p->cmd, CONST_STR_LEN(":")); |
buffer_append_off_t(p->cmd, s->bytes_written); | buffer_append_int(p->cmd, s->bytes_written); |
buffer_append_string_len(p->cmd, CONST_STR_LEN(":")); |
buffer_append_string_len(p->cmd, CONST_STR_LEN(":")); |
buffer_append_long(p->cmd, s->requests); | buffer_append_int(p->cmd, s->requests); |
buffer_append_string_len(p->cmd, CONST_STR_LEN("\n")); |
buffer_append_string_len(p->cmd, CONST_STR_LEN("\n")); |
|
|
if (-1 == (r = safe_write(p->write_fd, p->cmd->ptr, p->cmd->used - 1))) { | if (-1 == (r = safe_write(p->write_fd, CONST_BUF_LEN(p->cmd)))) { |
p->rrdtool_running = 0; |
p->rrdtool_running = 0; |
|
|
log_error_write(srv, __FILE__, __LINE__, "ss", |
log_error_write(srv, __FILE__, __LINE__, "ss", |
Line 434 TRIGGER_FUNC(mod_rrd_trigger) {
|
Line 439 TRIGGER_FUNC(mod_rrd_trigger) {
|
return HANDLER_ERROR; |
return HANDLER_ERROR; |
} |
} |
|
|
buffer_prepare_copy(p->resp, 4096); | buffer_string_prepare_copy(p->resp, 4095); |
if (-1 == (r = safe_read(p->read_fd, p->resp->ptr, p->resp->size))) { | if (-1 == (r = safe_read(p->read_fd, p->resp->ptr, p->resp->size - 1))) { |
p->rrdtool_running = 0; |
p->rrdtool_running = 0; |
|
|
log_error_write(srv, __FILE__, __LINE__, "ss", |
log_error_write(srv, __FILE__, __LINE__, "ss", |
Line 444 TRIGGER_FUNC(mod_rrd_trigger) {
|
Line 449 TRIGGER_FUNC(mod_rrd_trigger) {
|
return HANDLER_ERROR; |
return HANDLER_ERROR; |
} |
} |
|
|
p->resp->used = r; | buffer_commit(p->resp, r); |
|
|
if (p->resp->ptr[0] != 'O' || |
if (p->resp->ptr[0] != 'O' || |
p->resp->ptr[1] != 'K') { |
p->resp->ptr[1] != 'K') { |