RRDcached chaining mode

Steve Shipway <[email protected]>
Newsgroups gmane.comp.db.rrdtool.devel
Message-ID <28E447343A85354483BCF7C3E9D5EAA51499AF3C@uxcn10-1.UoA.auckland.ac.nz>
Attached is a small patch for rrdtool to allow chaining of update requests received via rrdcached on to a second instance of rrdcached specified by a command line parameter -C.

EG:
$ rrdcached -l unix:/tmp/a.sock -b /var/rrda
$ rrdcached -l unix:/tmp/b.sock -b /var/rrdb -C unix:/tmp/a.sock
$ rrdtool update --daemon unix:/tmp/b.sock foo.rrd N:1:1

This updates foo.rrd in both /var/rrdb and /var/rrda, provided it exists, of course.  This also works over TCP sockets, and you can mix and match UNIX and TCP sockets if you like.  This patch only chains UPDATE requests, not CREATEs, STATs, or anything else.

The requests are sent to the remote daemon immediately after they are added to the update queue for the receiving daemon (thus avoiding any trouble of how to handle them after queueing).  If the relay fails then an error is logged BUT the rrdcached still returns a success code to the remote client (as there is no 'warning' code for a partial success).

I've run this here for a few days keeping a shadow copy of our secondary MRTG server's RRD files, and it worked without problem.  There was a bit of an issue when I defined two instances to chain to each other, though :)

I think it would need to have CREATE, and probably FLUSH, FLUSHALL and STATS chained as well for this to be of real use.

Thoughts?

Steve

________________________________
Steve Shipway
ITS Unix Services Design Lead
University of Auckland, New Zealand
Floor 1, 58 Symonds Street, Auckland
Phone: +64 (0)9 3737599 ext 86487
DDI: +64 (0)9 924 6487
Mobile: +64 (0)21 753 189
Email: [email protected]<mailto:[email protected]>
P Please consider the environment before printing this e-mail

_______________________________________________
rrd-developers mailing list
[email protected]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers
rrd-chain.diff (application/octet-stream, 3 KB)
diff --ignore-all-space --recursive rrdtool-1.4.99910092700/src/rrd_daemon.c rrdtool-1.4.uoa/src/rrd_daemon.c
74c74
< #include "rrd.h"
---
> #include "rrd_tool.h"
221a222,224
> /* maximum number of updates we will relay in one go */
> #define RELAY_MAX 512
> 
278a281
> static char *copy_daemon = (char *)0;
1323a1328
>   char *orig_file;
1326a1332,1333
>   char thisopt[CMD_MAX];
>   char *values_arr[RELAY_MAX];
1336a1344
>   orig_file = file;
1431a1440,1444
>     if( copy_daemon ) {
>         values_arr[values_num] = value;
> 		strncpy(thisopt,value,sizeof(thisopt));
> 		value = thisopt;
> 	}
1471c1484,1485
<   if (values_num < 1)
---
> 
>   if (values_num < 1) {
1473c1487,1517
<   else
---
>   } else if( copy_daemon ) {
>     status = rrdc_connect(copy_daemon);
>     status = rrdc_is_connected(copy_daemon);
>     if(!status) {
>         RRDD_LOG (LOG_ERR, "handle_request_update: could not connect to remote rrdcached: %s",rrd_get_error());
>         rrd_clear_error();
>         return send_response(sock, RESP_OK,
>         "Errors, enqueued %i value(s) but could not connect to remote daemon.\n", values_num);
>     }
> 	/* now, if we are doing chained updates unix->unix or tcp->tcp all will be 
>        OK as we're preserving the orig_file.  However if we're doing
>        tcp->unix we need to use 'file' (IE with the path) and if we're doing
>        unix->tcp we need to REMOVE the default path.                         */
>     if( ! strncmp( copy_daemon, "unix:", 5 ) || (*copy_daemon == '/') ) {
>        /* going to a unix socket: 'file' is already expanded. */
>     } else { /* going to a tcp: strip path if necessary */
>        file = orig_file; 
>        if( ! strncmp( file, config_base_dir, _config_base_dir_len ) ) {
>            file += _config_base_dir_len + 1; /* skip path and separator */
>        }
>     }
>     status = rrdc_update(file,values_num,(const char * const *) values_arr);
>     if(status) {
>         RRDD_LOG (LOG_ERR, "handle_request_update: could not perform remote update: %s",rrd_get_error());
>         rrd_clear_error();
>         return send_response(sock, RESP_OK,
>             "Errors, enqueued %i value(s) but could not relay.\n", values_num);
>     }
>     return send_response(sock, RESP_OK,
>                          "Update successful, enqueued and relayed %i value(s).\n", values_num);
>   } else {
1475c1519,1520
<                          "errors, enqueued %i value(s).\n", values_num);
---
>                          "Update successful, enqueued %i value(s).\n", values_num);
>   }
3213c3268
<   while ((option = getopt(argc, argv, "Ogl:s:m:P:f:w:z:t:Bb:p:Fj:a:h?")) != -1)
---
>   while ((option = getopt(argc, argv, "Ogl:s:m:P:f:w:z:t:Bb:p:Fj:a:hC:?")) != -1)
3216a3272,3275
>       case 'C':
>         copy_daemon = strdup (optarg);
>         break;
> 
3564a3624,3626
>             "  -C <address>  Chain all UPDATE requests on to the specified rrdcached\n"
>             "                address. This only passes on successful UPDATE requests\n"
>             "                and the address format is as with the -l option.\n"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.