Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 569 lines (462 sloc) 14.2 kB
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* Cherokee
4 *
5 * Authors:
6 * Alvaro Lopez Ortega <alvaro@alobbs.com>
7 *
920e20b @alobbs Happy new year!
alobbs authored
8 * Copyright (C) 2001-2011 Alvaro Lopez Ortega
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301, USA.
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
23 */
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
24
25 #include "common-internal.h"
26
27 #include <unistd.h>
28 #include <errno.h>
29 #include <sys/types.h>
30 #include <signal.h>
31 #include <sys/stat.h>
8008c3f @alobbs Fixes a couple of minor compilation issues reported by Sandino Araico
alobbs authored
32 #include <sys/wait.h>
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
33
34 #include "rrd_tools.h"
b226fc8 @alobbs Improves how the 'cherokee' temporal directory was being created.
alobbs authored
35 #include "init.h"
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
36 #include "virtual_server.h"
37 #include "util.h"
38
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
39 #define ELAPSE_UPDATE 60
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
40 #define ENTRIES "rrd"
41
42
43 /* Global RRDtool connection instance
44 */
45 cherokee_rrd_connection_t *rrd_connection = NULL;
46
f58493e @alobbs Relocates a symbol so the render_rrd module can be consumed as a
alobbs authored
47 cherokee_collector_rrd_interval_t cherokee_rrd_intervals[] = {
48 { "1h", "1 Hour", ( 1 * 60 * 60) / 580},
49 { "6h", "6 Hours", ( 6 * 60 * 60) / 580},
50 { "1d", "1 Day", (24 * 60 * 60) / 580},
51 { "1w", "1 Week", (7 * 24 * 60 * 60) / 580},
52 { "1m", "1 Month", (28 * 24 * 60 * 60) / 580},
53 { NULL, NULL, 0}
54 };
55
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
56
57 static ret_t
58 cherokee_rrd_connection_init (cherokee_rrd_connection_t *rrd_conn)
59 {
60 rrd_conn->write_fd = -1;
61 rrd_conn->read_fd = -1;
62 rrd_conn->pid = -1;
661c14f @alobbs Do not try to spawn new rrdtool binaries once the server is exiting.
alobbs authored
63 rrd_conn->exiting = false;
60ea84b @alobbs Cherokee does no longer throw a fatal error when rrdtool is configured
alobbs authored
64 rrd_conn->disabled = false;
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
65
66 cherokee_buffer_init (&rrd_conn->tmp);
67 cherokee_buffer_init (&rrd_conn->path_rrdtool);
68 cherokee_buffer_init (&rrd_conn->path_databases);
42fe802 @alobbs The RRD image cache directory is not longer inside the RRD database
alobbs authored
69 cherokee_buffer_init (&rrd_conn->path_img_cache);
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
70
71 CHEROKEE_MUTEX_INIT (&rrd_conn->mutex, NULL);
72
73 return ret_ok;
74 }
75
76
77 ret_t
78 cherokee_rrd_connection_get (cherokee_rrd_connection_t **rrd_conn)
79 {
80 if (rrd_connection == NULL) {
0a0d697 @alobbs The RRD information collector can store information about the number
alobbs authored
81 /* Create the global object
82 */
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
83 rrd_connection = malloc (sizeof(cherokee_rrd_connection_t));
84 if (unlikely (rrd_connection == NULL)) {
85 return ret_error;
86 }
87
88 cherokee_rrd_connection_init (rrd_connection);
89 }
90
91 if (rrd_conn != NULL) {
92 *rrd_conn = rrd_connection;
93 }
94
95 return ret_ok;
96 }
97
98
99 ret_t
100 cherokee_rrd_connection_configure (cherokee_rrd_connection_t *rrd_conn,
101 cherokee_config_node_t *config)
102 {
103 ret_t ret;
104 cherokee_config_node_t *subconf;
105
c38cf38 @alobbs Fixes the RRD support so both the rrd collector and the rrd_render
alobbs authored
106 /* Warning: If s web server collects data (rrd collector) and
107 * renders graphs (handler render_rrd) it calls this function
108 * twice with the same object. Take that in mind.
109 */
110
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
111 /* RRDtool binary
112 */
c38cf38 @alobbs Fixes the RRD support so both the rrd collector and the rrd_render
alobbs authored
113 if (cherokee_buffer_is_empty (&rrd_conn->path_rrdtool)) {
114 ret = cherokee_config_node_get (config, "rrdtool_path", &subconf);
115 if (ret == ret_ok) {
116 cherokee_buffer_add_buffer (&rrd_conn->path_rrdtool, &subconf->val);
117 } else {
118 ret = cherokee_find_exec_in_path ("rrdtool", &rrd_conn->path_rrdtool);
119 if (ret != ret_ok) {
120 rrd_conn->disabled = true;
f28f188 @alobbs rrdtool is optional. Do not print an error if not found.
alobbs authored
121 LOG_WARNING (CHEROKEE_ERROR_RRD_NO_BINARY, getenv("PATH"));
c38cf38 @alobbs Fixes the RRD support so both the rrd collector and the rrd_render
alobbs authored
122 }
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
123 }
124 }
125
126 /* RRDtool databases directory
127 */
c38cf38 @alobbs Fixes the RRD support so both the rrd collector and the rrd_render
alobbs authored
128 if (cherokee_buffer_is_empty (&rrd_conn->path_databases)) {
129 ret = cherokee_config_node_get (config, "database_dir", &subconf);
130 if (ret == ret_ok) {
131 cherokee_buffer_add_buffer (&rrd_conn->path_databases, &subconf->val);
132 } else {
133 cherokee_buffer_add_str (&rrd_conn->path_databases, CHEROKEE_RRD_DIR);
134 }
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
135 }
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
136
42fe802 @alobbs The RRD image cache directory is not longer inside the RRD database
alobbs authored
137 /* Build the image cache directory
0a0d697 @alobbs The RRD information collector can store information about the number
alobbs authored
138 */
c38cf38 @alobbs Fixes the RRD support so both the rrd collector and the rrd_render
alobbs authored
139 if (cherokee_buffer_is_empty (&rrd_conn->path_img_cache)) {
b226fc8 @alobbs Improves how the 'cherokee' temporal directory was being created.
alobbs authored
140 cherokee_buffer_add_buffer (&rrd_conn->path_img_cache, &cherokee_tmp_dir);
141 cherokee_buffer_add_str (&rrd_conn->path_img_cache, "/rrd-cache");
c38cf38 @alobbs Fixes the RRD support so both the rrd collector and the rrd_render
alobbs authored
142 }
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
143
144 return ret_ok;
145 }
146
147
148 ret_t
149 cherokee_rrd_connection_mrproper (cherokee_rrd_connection_t *rrd_conn)
150 {
151 CHEROKEE_MUTEX_DESTROY (&rrd_conn->mutex);
152
153 cherokee_buffer_mrproper (&rrd_conn->tmp);
154 cherokee_buffer_mrproper (&rrd_conn->path_rrdtool);
42fe802 @alobbs The RRD image cache directory is not longer inside the RRD database
alobbs authored
155 cherokee_buffer_mrproper (&rrd_conn->path_databases);
156 cherokee_buffer_mrproper (&rrd_conn->path_img_cache);
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
157
158 return cherokee_rrd_connection_kill (rrd_conn, true);
159 }
160
161
162 ret_t
163 cherokee_rrd_connection_spawn (cherokee_rrd_connection_t *rrd_conn)
164 {
165 #ifdef HAVE_FORK
166 int re;
167 pid_t pid;
168 char *argv[3];
169 int fds_to[2];
170 int fds_from[2];
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
171
661c14f @alobbs Do not try to spawn new rrdtool binaries once the server is exiting.
alobbs authored
172 /* Do not spawn if the server it exiting */
60ea84b @alobbs Cherokee does no longer throw a fatal error when rrdtool is configured
alobbs authored
173 if ((rrd_conn->exiting) ||
174 (rrd_conn->disabled))
175 {
661c14f @alobbs Do not try to spawn new rrdtool binaries once the server is exiting.
alobbs authored
176 return ret_ok;
177 }
178
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
179 /* There might be a live process */
180 if ((rrd_conn->write_fd != -1) &&
181 (rrd_conn->read_fd != -1) &&
182 (rrd_conn->pid != -1))
183 {
184 return ret_ok;
185 }
186
187 TRACE (ENTRIES, "Spawning a new RRDtool instance: %s -\n", rrd_conn->path_rrdtool.buf);
188
189 /* Create communication pipes */
a68f41b @alobbs Merges the Front-Line Cache branch.
alobbs authored
190 re = cherokee_pipe(fds_to);
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
191 if (re != 0) {
192 return ret_error;
193 }
194
a68f41b @alobbs Merges the Front-Line Cache branch.
alobbs authored
195 re = cherokee_pipe(fds_from);
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
196 if (re != 0) {
197 return ret_error;
198 }
199
200 /* Spawn the new child process */
201 pid = fork();
202 switch (pid) {
203 case 0:
204 argv[0] = rrd_conn->path_rrdtool.buf;
205 argv[1] = (char *) "-";
206 argv[2] = NULL;
207
208 /* Move stdout to fd_from[1] */
209 dup2 (fds_from[1], STDOUT_FILENO);
9a6e161 @alobbs Safer fd closing
alobbs authored
210 cherokee_fd_close (fds_from[1]);
211 cherokee_fd_close (fds_from[0]);
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
212
213 /* Move the stdin to fd_to[0] */
214 dup2 (fds_to[0], STDIN_FILENO);
9a6e161 @alobbs Safer fd closing
alobbs authored
215 cherokee_fd_close (fds_to[0]);
216 cherokee_fd_close (fds_to[1]);
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
217
218 /* Execute it */
5ced005 @alobbs Handles EINTR while invoking execv*()
alobbs authored
219 do {
220 re = execv(argv[0], argv);
221 } while (errno == EINTR);
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
222
165f0ad @alobbs Merges the 'newerrors' branch (r3613:HEAD). It implements a new
alobbs authored
223 LOG_ERRNO (errno, cherokee_err_error, CHEROKEE_ERROR_RRD_EXECV, argv[0]);
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
224 exit (EXIT_ERROR);
225
226 case -1:
165f0ad @alobbs Merges the 'newerrors' branch (r3613:HEAD). It implements a new
alobbs authored
227 LOG_ERRNO (errno, cherokee_err_error, CHEROKEE_ERROR_RRD_FORK, pid);
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
228 break;
229
230 default:
9a6e161 @alobbs Safer fd closing
alobbs authored
231 cherokee_fd_close (fds_from[1]);
232 cherokee_fd_close (fds_to[0]);
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
233
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
234 rrd_conn->write_fd = fds_to[1];
235 rrd_conn->read_fd = fds_from[0];
236 rrd_conn->pid = pid;
237
238 fcntl (rrd_conn->write_fd, F_SETFD, FD_CLOEXEC);
239 fcntl (rrd_conn->read_fd, F_SETFD, FD_CLOEXEC);
240 break;
241 }
242
243 return ret_ok;
244 #else
245 return ret_error;
246 #endif
247 }
248
249
250 ret_t
251 cherokee_rrd_connection_kill (cherokee_rrd_connection_t *rrd_conn,
252 cherokee_boolean_t do_kill)
253 {
db5f975 @alobbs Safer error checking. Ensure rrdtool actually exited.
alobbs authored
254 int re;
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
255 int status;
256
257 if (rrd_conn->write_fd) {
9a6e161 @alobbs Safer fd closing
alobbs authored
258 cherokee_fd_close (rrd_conn->write_fd);
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
259 rrd_conn->write_fd = -1;
260 }
261
262 if (rrd_conn->read_fd) {
9a6e161 @alobbs Safer fd closing
alobbs authored
263 cherokee_fd_close (rrd_conn->read_fd);
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
264 rrd_conn->read_fd = -1;
265 }
266
5e17ee6 @alobbs Fixes the RRD clean up/killing function. The graceful restart
alobbs authored
267 if (rrd_conn->pid != -1) {
268 if (do_kill) {
269 kill (rrd_conn->pid, SIGTERM);
270 }
db5f975 @alobbs Safer error checking. Ensure rrdtool actually exited.
alobbs authored
271
272 do {
273 re = waitpid (rrd_conn->pid, &status, 0);
274 if ((re < 0) && (errno == EINTR)) {
275 usleep (500 * 1000);
276 continue;
277 }
278 break;
279 } while (true);
280
5e17ee6 @alobbs Fixes the RRD clean up/killing function. The graceful restart
alobbs authored
281 rrd_conn->pid = -1;
282 }
283
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
284 return ret_ok;
285 }
286
287
288 static ret_t
289 read_rrdtool (cherokee_rrd_connection_t *rrd_conn,
290 cherokee_buffer_t *buffer)
291 {
292 ret_t ret;
293 size_t got;
294
295 do {
296 ret = cherokee_buffer_read_from_fd (buffer, rrd_conn->read_fd,
297 DEFAULT_RECV_SIZE, &got);
298 } while (ret == ret_eagain);
299
300 return ret;
301 }
302
303
304 static ret_t
305 write_rrdtool (cherokee_rrd_connection_t *rrd_conn,
306 cherokee_buffer_t *buffer)
307 {
308 ssize_t written;
309
310 while (true) {
311 written = write (rrd_conn->write_fd, buffer->buf, buffer->len);
312 if (written >= (ssize_t) buffer->len) {
313 cherokee_buffer_clean (buffer);
314 return ret_ok;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
315
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
316 } else if (written > 0) {
317 cherokee_buffer_move_to_begin (buffer, written);
318 continue;
319
320 } else {
321 switch (errno) {
322 case EINTR:
323 continue;
324 default:
325 return ret_error;
326 }
327 }
328 }
329
330 SHOULDNT_HAPPEN;
331 return ret_error;
332 }
333
334
335 ret_t
336 cherokee_rrd_connection_execute (cherokee_rrd_connection_t *rrd_conn,
337 cherokee_buffer_t *buf)
338 {
339 ret_t ret;
340
cb6408b @alobbs The handler render_rrd draws the number of HTTP requests now (in the
alobbs authored
341 TRACE (ENTRIES, "Sending to RRDtool: %s", buf->buf);
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
342
60ea84b @alobbs Cherokee does no longer throw a fatal error when rrdtool is configured
alobbs authored
343 /* Might be disabled
344 */
345 if (unlikely (rrd_conn->disabled)) {
346 return ret_ok;
347 }
348
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
349 /* Spawn rrdtool
350 */
351 ret = cherokee_rrd_connection_spawn (rrd_conn);
352 if (unlikely (ret != ret_ok)) {
353 return ret_error;
354 }
355
356 /* Write command
357 */
358 ret = write_rrdtool (rrd_conn, buf);
359 if (unlikely (ret != ret_ok)) {
360 return ret_error;
361 }
362
363 /* Read response
364 */
365 cherokee_buffer_clean (buf);
366
367 ret = read_rrdtool (rrd_conn, buf);
368 if (unlikely (ret != ret_ok)) {
369 cherokee_rrd_connection_kill (rrd_conn, false);
370 return ret_error;
371 }
372
373 return ret_ok;
374 }
375
376
377 static cherokee_boolean_t
378 ensure_db_exists (cherokee_buffer_t *path_database)
379 {
380 int re;
381 struct stat info;
382 char *slash;
383
384 /* It exists
385 */
386 re = cherokee_stat (path_database->buf, &info);
387 if ((re == 0) && (info.st_size > 0)) {
388 return true;
389 }
390
391 /* Write access
392 */
393 slash = strrchr (path_database->buf, '/');
394 if (slash == NULL) {
395 return false;
396 }
397
398 *slash = '\0';
399 re = access (path_database->buf, W_OK);
400 if (re != 0) {
165f0ad @alobbs Merges the 'newerrors' branch (r3613:HEAD). It implements a new
alobbs authored
401 LOG_ERRNO (errno, cherokee_err_error, CHEROKEE_ERROR_RRD_WRITE, path_database->buf);
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
402 return false;
403 }
404 *slash = '/';
405
406 return false;
407 }
408
409
410 ret_t
411 cherokee_rrd_connection_create_srv_db (cherokee_rrd_connection_t *rrd_conn)
412 {
413 ret_t ret;
414 cherokee_boolean_t exist;
415 cherokee_buffer_t tmp = CHEROKEE_BUF_INIT;
416 cherokee_buffer_t dbname = CHEROKEE_BUF_INIT;
417
418 /* Ensure directories are accessible
419 */
42fe802 @alobbs The RRD image cache directory is not longer inside the RRD database
alobbs authored
420 ret = cherokee_mkdir_p_perm (&rrd_conn->path_databases, 0775, W_OK);
b738664 @alobbs Bugfix: RRD was not working for Virtual Servers with spaces in its
alobbs authored
421 switch (ret) {
422 case ret_ok:
423 break;
424 case ret_error:
42fe802 @alobbs The RRD image cache directory is not longer inside the RRD database
alobbs authored
425 LOG_CRITICAL (CHEROKEE_ERROR_RRD_MKDIR_WRITE, rrd_conn->path_databases.buf);
0a0d697 @alobbs The RRD information collector can store information about the number
alobbs authored
426 return ret_error;
b738664 @alobbs Bugfix: RRD was not working for Virtual Servers with spaces in its
alobbs authored
427 case ret_deny:
428 LOG_CRITICAL (CHEROKEE_ERROR_RRD_DIR_PERMS, rrd_conn->path_databases.buf);
429 return ret_error;
430 default:
431 RET_UNKNOWN(ret);
432 return ret_error;
0a0d697 @alobbs The RRD information collector can store information about the number
alobbs authored
433 }
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
434
435 /* Check the Server database
436 */
437 cherokee_buffer_add_buffer (&dbname, &rrd_conn->path_databases);
438 cherokee_buffer_add_str (&dbname, "/server.rrd");
439
440 exist = ensure_db_exists (&dbname);
441 if (exist) {
442 return ret_ok;
443 }
444
445 cherokee_buffer_add_str (&tmp, "create ");
446 cherokee_buffer_add_buffer (&tmp, &dbname);
447 cherokee_buffer_add_str (&tmp, " --step ");
448 cherokee_buffer_add_long10 (&tmp, ELAPSE_UPDATE);
449 cherokee_buffer_add_str (&tmp, " ");
450
451 /* Data Sources */
452 cherokee_buffer_add_va (&tmp, "DS:Accepts:ABSOLUTE:%d:U:U ", ELAPSE_UPDATE*10);
0a0d697 @alobbs The RRD information collector can store information about the number
alobbs authored
453 cherokee_buffer_add_va (&tmp, "DS:Requests:ABSOLUTE:%d:U:U ", ELAPSE_UPDATE*10);
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
454 cherokee_buffer_add_va (&tmp, "DS:Timeouts:ABSOLUTE:%d:U:U ", ELAPSE_UPDATE*10);
455 cherokee_buffer_add_va (&tmp, "DS:RX:ABSOLUTE:%d:U:U ", ELAPSE_UPDATE*10);
456 cherokee_buffer_add_va (&tmp, "DS:TX:ABSOLUTE:%d:U:U ", ELAPSE_UPDATE*10);
457
458 /* Archives */
459 cherokee_buffer_add_str (&tmp, "RRA:AVERAGE:0.5:1:600 ");
460 cherokee_buffer_add_str (&tmp, "RRA:AVERAGE:0.5:6:700 ");
461 cherokee_buffer_add_str (&tmp, "RRA:AVERAGE:0.5:24:775 ");
462 cherokee_buffer_add_str (&tmp, "RRA:AVERAGE:0.5:288:797 ");
463
464 cherokee_buffer_add_str (&tmp, "RRA:MAX:0.5:1:600 ");
465 cherokee_buffer_add_str (&tmp, "RRA:MAX:0.5:6:700 ");
466 cherokee_buffer_add_str (&tmp, "RRA:MAX:0.5:24:775 ");
467 cherokee_buffer_add_str (&tmp, "RRA:MAX:0.5:288:797 ");
468
469 cherokee_buffer_add_str (&tmp, "RRA:MIN:0.5:1:600 ");
470 cherokee_buffer_add_str (&tmp, "RRA:MIN:0.5:6:700 ");
471 cherokee_buffer_add_str (&tmp, "RRA:MIN:0.5:24:775 ");
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
472 cherokee_buffer_add_str (&tmp, "RRA:MIN:0.5:288:797 ");
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
473 cherokee_buffer_add_str (&tmp, "\n");
474
475 /* Exec */
476 TRACE (ENTRIES, "Creating RRDtool server database: %s\n", tmp.buf);
477
478 ret = cherokee_rrd_connection_spawn (rrd_conn);
479 if (unlikely (ret != ret_ok)) {
480 return ret_error;
481 }
482
483 ret = cherokee_rrd_connection_execute (rrd_conn, &tmp);
484 if (unlikely (ret != ret_ok)) {
485 return ret_error;
486 }
487
488 cherokee_buffer_mrproper (&dbname);
489 cherokee_buffer_mrproper (&tmp);
490 return ret_ok;
491 }
492
493
494 ret_t
495 cherokee_rrd_connection_create_vsrv_db (cherokee_rrd_connection_t *rrd_conn,
496 cherokee_buffer_t *dbpath)
497 {
498 ret_t ret;
499 cherokee_boolean_t exist;
500 cherokee_buffer_t tmp = CHEROKEE_BUF_INIT;
501
502 /* Ensure directories are accessible
503 */
42fe802 @alobbs The RRD image cache directory is not longer inside the RRD database
alobbs authored
504 ret = cherokee_mkdir_p_perm (&rrd_conn->path_databases, 0775, W_OK);
b738664 @alobbs Bugfix: RRD was not working for Virtual Servers with spaces in its
alobbs authored
505 switch (ret) {
506 case ret_ok:
507 break;
508 case ret_error:
42fe802 @alobbs The RRD image cache directory is not longer inside the RRD database
alobbs authored
509 LOG_CRITICAL (CHEROKEE_ERROR_RRD_MKDIR_WRITE, rrd_conn->path_databases.buf);
0a0d697 @alobbs The RRD information collector can store information about the number
alobbs authored
510 return ret_error;
b738664 @alobbs Bugfix: RRD was not working for Virtual Servers with spaces in its
alobbs authored
511 case ret_deny:
512 LOG_CRITICAL (CHEROKEE_ERROR_RRD_DIR_PERMS, rrd_conn->path_databases.buf);
513 return ret_error;
514 default:
515 RET_UNKNOWN(ret);
516 return ret_error;
0a0d697 @alobbs The RRD information collector can store information about the number
alobbs authored
517 }
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
518
519 /* Check the Server database
520 */
521 exist = ensure_db_exists (dbpath);
522 if (exist) {
523 return ret_ok;
524 }
525
526 cherokee_buffer_add_str (&tmp, "create ");
527 cherokee_buffer_add_buffer (&tmp, dbpath);
528 cherokee_buffer_add_str (&tmp, " --step ");
529 cherokee_buffer_add_long10 (&tmp, ELAPSE_UPDATE);
530 cherokee_buffer_add_str (&tmp, " ");
531
532 /* Data Sources */
533 cherokee_buffer_add_va (&tmp, "DS:RX:ABSOLUTE:%d:U:U ", ELAPSE_UPDATE*10);
534 cherokee_buffer_add_va (&tmp, "DS:TX:ABSOLUTE:%d:U:U ", ELAPSE_UPDATE*10);
535
536 /* Archives */
537 cherokee_buffer_add_str (&tmp, "RRA:AVERAGE:0.5:1:600 ");
538 cherokee_buffer_add_str (&tmp, "RRA:AVERAGE:0.5:6:700 ");
539 cherokee_buffer_add_str (&tmp, "RRA:AVERAGE:0.5:24:775 ");
540 cherokee_buffer_add_str (&tmp, "RRA:AVERAGE:0.5:288:797 ");
541
542 cherokee_buffer_add_str (&tmp, "RRA:MAX:0.5:1:600 ");
543 cherokee_buffer_add_str (&tmp, "RRA:MAX:0.5:6:700 ");
544 cherokee_buffer_add_str (&tmp, "RRA:MAX:0.5:24:775 ");
545 cherokee_buffer_add_str (&tmp, "RRA:MAX:0.5:288:797 ");
546
547 cherokee_buffer_add_str (&tmp, "RRA:MIN:0.5:1:600 ");
548 cherokee_buffer_add_str (&tmp, "RRA:MIN:0.5:6:700 ");
549 cherokee_buffer_add_str (&tmp, "RRA:MIN:0.5:24:775 ");
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
550 cherokee_buffer_add_str (&tmp, "RRA:MIN:0.5:288:797 ");
8ce4b46 @alobbs Re-implements the RRD graph generation. It should significantly low
alobbs authored
551 cherokee_buffer_add_str (&tmp, "\n");
552
553 /* Exec */
554 TRACE (ENTRIES, "Creating RRDtool vserver database: %s\n", tmp.buf);
555
556 ret = cherokee_rrd_connection_spawn (rrd_conn);
557 if (unlikely (ret != ret_ok)) {
558 return ret_error;
559 }
560
561 ret = cherokee_rrd_connection_execute (rrd_conn, &tmp);
562 if (unlikely (ret != ret_ok)) {
563 return ret_error;
564 }
565
566 cherokee_buffer_mrproper (&tmp);
567 return ret_ok;
568 }
Something went wrong with that request. Please try again.