librrd(3)                           rrdtool                          librrd(3)



NNAAMMEE
       librrd - RRD library functions

DDEESSCCRRIIPPTTIIOONN
       lliibbrrrrdd contains most of the functionality in RRRRDDTTooooll.  The command line
       utilities and language bindings are often just wrappers around the code
       contained in lliibbrrrrdd.

       This manual page documents the lliibbrrrrdd API.

       NNOOTTEE:: This document is a work in progress, and should be considered
       incomplete as long as this warning persists.  For more information
       about the lliibbrrrrdd functions, always consult the source code.

CCOORREE FFUUNNCCTTIIOONNSS
       rrrrdd__dduummpp__ccbb__rr((cchhaarr **ffiilleennaammee,, iinntt oopptt__hheeaaddeerr,, rrrrdd__oouuttppuutt__ccaallllbbaacckk__tt ccbb,,
       vvooiidd **uusseerr))
           In some situations it is necessary to get the output of "rrd_dump"
           without writing it to a file or the standard output. In such cases
           an application can ask rrrrdd__dduummpp__ccbb__rr to call an user-defined
           function each time there is output to be stored somewhere. This can
           be used, to e.g. directly feed an XML parser with the dumped output
           or transfer the resulting string in memory.

           The arguments for rrrrdd__dduummpp__ccbb__rr are the same as for rrrrdd__dduummpp__oopptt__rr
           except that the output filename parameter is replaced by the user-
           defined callback function and an additional parameter for the
           callback function that is passed untouched, i.e. to store
           information about the callback state needed for the user-defined
           callback to function properly.

           Recent versions of rrrrdd__dduummpp__oopptt__rr internally use this callback
           mechanism to write their output to the file provided by the user.

               size_t rrd_dump_opt_cb_fileout(
                   const void *data,
                   size_t len,
                   void *user)
               {
                   return fwrite(data, 1, len, (FILE *)user);
               }

           The associated call for rrrrdd__dduummpp__ccbb__rr looks like

               res = rrd_dump_cb_r(filename, opt_header,
                   rrd_dump_opt_cb_fileout, (void *)out_file);

           where the last parameter specifies the file handle
           rrrrdd__dduummpp__oopptt__ccbb__ffiilleeoouutt should write to. There's no specific
           condition for the callback to detect when it is called for the
           first time, nor for the last time. If you require this for
           initialization and cleanup you should do those tasks before and
           after calling rrrrdd__dduummpp__ccrr__rr respectively.

       rrrrdd__ffeettcchh__ccbb__rreeggiisstteerr((rrrrdd__ffeettcchh__ccbb__tt cc))
           If your data does not reside in rrd files, but you would like to
           draw charts using the rrd_graph functionality, you can supply your
           own rrd_fetch function and register it using the
           rrrrdd__ffeettcchh__ccbb__rreeggiisstteerr function.

           The argument signature and api must be the same of the callback
           function must be aequivalent to the on of rrrrdd__ffeettcchh__ffnn in
           _r_r_d___f_e_t_c_h_._c.

           To activate the callback function you can use the pseudo filename
           _c_b_/_/_f_r_e_e___f_o_r_m___t_e_x_t.

           Note that rrdtool graph will not ask the same rrd for data twice.
           It determines this by building a key out of the values supplied to
           the fetch function. If the values are the same, the previous answer
           will be used.

UUTTIILLIITTYY FFUUNNCCTTIIOONNSS
       _rr_rr_dd____rr_aa_nn_dd_oo_mm_((_))
           Generates random numbers just like _r_a_n_d_o_m_(_).  This further ensures
           that the random number generator is seeded exactly once per
           process.

       rrrrdd__ssttrrttooddbbll
           an rrd aware string to double converter which sets rrd_error in if
           there is a problem and uses the return code exclusively for
           conversion status reporting.

       rrrrdd__ssttrrttoodd
           works like normal strtod, but it is locale independent (and thread
           safe)

       rrrrdd__ssnnpprriinnttff
           works  like normal snprintf but it is locale independent (and
           thread safe)

       rrrrdd__aadddd__ppttrr((vvooiidd ******ddeesstt,, ssiizzee__tt **ddeesstt__ssiizzee,, vvooiidd **ssrrcc))
           Dynamically resize the array pointed to by "dest".  "dest_size" is
           a pointer to the current size of "dest".  Upon successful
           _r_e_a_l_l_o_c_(_), the "dest_size" is incremented by 1 and the "src"
           pointer is stored at the end of the new "dest".  Returns 1 on
           success, 0 on failure.

               type **arr = NULL;
               type *elem = "whatever";
               size_t arr_size = 0;
               if (!rrd_add_ptr(&arr, &arr_size, elem))
                   handle_failure();

       rrrrdd__aadddd__ppttrr__cchhuunnkk((vvooiidd ******ddeesstt,, ssiizzee__tt **ddeesstt__ssiizzee,, vvooiidd **ssrrcc,, ssiizzee__tt
       **aalllloocc,, ssiizzee__tt cchhuunnkk))
           Like "rrd_add_ptr", except the destination is allocated in chunks
           of "chunk".  "alloc" points to the number of entries allocated,
           whereas "dest_size" points to the number of valid pointers.  If
           more pointers are needed, "chunk" pointers are allocated and
           "alloc" is increased accordingly.  "alloc" must be >= "dest_size".

           This method improves performance on hosts with expensive
           "realloc()".

       rrrrdd__aadddd__ssttrrdduupp((cchhaarr ******ddeesstt,, ssiizzee__tt **ddeesstt__ssiizzee,, cchhaarr **ssrrcc))
           Like "rrd_add_ptr", except adds a "strdup" of the source string.

               char **arr = NULL;
               size_t arr_size = NULL;
               char *str  = "example text";
               if (!rrd_add_strdup(&arr, &arr_size, str))
                   handle_failure();

       rrrrdd__aadddd__ssttrrdduupp__cchhuunnkk((cchhaarr ******ddeesstt,, ssiizzee__tt **ddeesstt__ssiizzee,, cchhaarr **ssrrcc,, ssiizzee__tt
       **aalllloocc,, ssiizzee__tt cchhuunnkk))
           Like "rrd_add_strdup", except the destination is allocated in
           chunks of "chunk".  "alloc" points to the number of entries
           allocated, whereas "dest_size" points to the number of valid
           pointers.  If more pointers are needed, "chunk" pointers are
           allocated and "alloc" is increased accordingly.  "alloc" must be >=
           "dest_size".

       rrrrdd__ffrreeee__ppttrrss((vvooiidd ******ssrrcc,, ssiizzee__tt **ccnntt))
           Free an array of pointers allocated by "rrd_add_ptr" or
           "rrd_add_strdup".  Also frees the array pointer itself.  On return,
           the source pointer will be NULL and the count will be zero.

               /* created as above */
               rrd_free_ptrs(&arr, &arr_size);
               /* here, arr == NULL && arr_size == 0 */

       rrrrdd__mmkkddiirr__pp((ccoonnsstt cchhaarr **ppaatthhnnaammee,, mmooddee__tt mmooddee))
           Create the directory named "pathname" including all of its parent
           directories (similar to "mkdir -p" on the command line - see
           _m_k_d_i_r(1) for more information). The argument "mode" specifies the
           permissions to use. It is modified by the process's "umask". See
           _m_k_d_i_r(2) for more details.

           The function returns 0 on success, a negative value else. In case
           of an error, "errno" is set accordingly. Aside from the errors
           documented in _m_k_d_i_r(2), the function may fail with the following
           errors:

           EEIINNVVAALL
               "pathname" is "NULL" or the empty string.

           EENNOOMMEEMM
               Insufficient memory was available.

           aannyy eerrrroorr rreettuurrnneedd bbyy _ss_tt_aa_tt((22))

           In contrast to _m_k_d_i_r(2), the function does nnoott fail if "pathname"
           already exists and is a directory.

       rrrrdd__ssccaalleedd__dduurraattiioonn ((ccoonnsstt cchhaarr ** ttookkeenn,, uunnssiiggnneedd lloonngg ddiivviissoorr,,
       uunnssiiggnneedd lloonngg ** vvaalluueepp))
           Parse a token in a context where it contains a count (of seconds or
           PDP instances), or a duration that can be converted to a count by
           representing the duration in seconds and dividing by some scaling
           factor.  For example, if a user would natively express a 3 day
           archive of samples collected every 2 minutes, the sample interval
           can be represented by "2m" instead of 120, and the archive duration
           by "3d" (to be divided by 120) instead of 2160 (3*24*60*60 / 120).
           See more examples in "STEP, HEARTBEAT, and Rows As Durations" in
           rrdcreate.

           "token" must be a number with an optional single-character suffix
           encoding the scaling factor:

           "s" indicates seconds

           "m" indicates minutes.  The value is multiplied by 60.

           "h" indicates hours.  The value is multiplied by 3600 (or "60m").

           "d" indicates days.  The value is multiplied by 86400 (or "24h").

           "w" indicates weeks.  The value is multiplied by 604800 (or "7d").

           "M" indicates months.  The value is multiplied by 2678400 (or
               "31d").  (Note this factor accommodates the maximum number of
               days in a month.)

           "y" indicates years.  The value is multiplied by 31622400 (or
               "366d").  (Note this factor accommodates leap years.)

           "divisor" is a positive value representing the duration in seconds
           of an interval that the desired result counts.

           "valuep" is a pointer to where the decoded value will be stored if
           the conversion is successful.

           The initial characters of "token" must be the base-10
           representation of a positive integer, or the conversion fails.

           If the remainder "token" is empty (no suffix), it is a count and no
           scaling is performed.

           If "token" has one of the suffixes above, the count is multiplied
           to convert it to a duration in seconds.  The resulting number of
           seconds is divided by "divisor" to produce a count of intervals
           each of duration "divisor" seconds.  If division would produce a
           remainder (e.g., "5m" (300 seconds) divided by "90s"), the
           conversion is invalid.

           If "token" has unrecognized trailing characters the conversion
           fails.

           The function returns a null pointer if the conversion was
           successful and "valuep" has been updated to the scaled value.  On
           failure, it returns a text diagnostic suitable for use in user
           error messages.

CCLLIIEENNTT FFUUNNCCTTIIOONNSS
       The following functions are used to connected to an rrdcached instance,
       either via a unix or inet address, and create, update, or gather
       statistics about a specified RRD database file.

       There are two different interfaces: The rrrrdd__cclliieenntt__ family of functions
       operate on a user-provided client object (rrrrdd__cclliieenntt__tt) and support
       multiple concurrent connections to rrdcache instances. The simpler
       rrrrddcc__ family of functions handles connections transparently but can
       only be used for one connection at a time.

       All of the following functions and data types are specified in the
       "rrd_client.h" header file.

       rrrrdd__cclliieenntt__nneeww((ccoonnsstt cchhaarr **ddaaeemmoonn__aaddddrr))
           Create a new client connection object. If specified, connect to the
           daemon at "daemon_addr". The connection can later be changed by
           calling rrrrdd__cclliieenntt__ccoonnnneecctt.

       rrrrdd__cclliieenntt__ddeessttrrooyy((rrrrdd__cclliieenntt__tt **cclliieenntt))
           Close a client connection and destroy the object by freeing all
           dynamically allocated memory. After calling this function, "client"
           can no longer be used.

       rrrrdd__cclliieenntt__ccoonnnneecctt((rrrrdd__cclliieenntt__tt **cclliieenntt,, ccoonnsstt cchhaarr **ddaaeemmoonn__aaddddrr))
       rrrrddcc__ccoonnnneecctt((ccoonnsstt cchhaarr **ddaaeemmoonn__aaddddrr))
           Connect to a running rrdcached instance, specified via
           "daemon_addr". Any previous connection will be closed. If
           "daemon_addr" is "NULL", it defaults to the value of the
           "ENV_RRDCACHED_ADDRESS" environment address.

       rrrrdd__cclliieenntt__iiss__ccoonnnneecctteedd((rrrrdd__cclliieenntt__tt **cclliieenntt))
           Return a boolean int if the client is connected to the server.

       rrrrdd__cclliieenntt__aaddddrreessss((rrrrdd__cclliieenntt__tt **cclliieenntt))
           Returns the server address belonging to the current connection.

       rrrrddcc__iiss__ccoonnnneecctteedd((ccoonnsstt cchhaarr **ddaaeemmoonn__aaddddrr))
           Return a boolean int to determine if the client is connected to the
           rrdcache daemon specified by the "daemon_addr" parameter.

       rrrrdd__cclliieenntt__ppiinngg((rrrrdd__cclliieenntt__tt **cclliieenntt))
       rrrrddcc__ppiinngg
           Check the client connection by pinging the remote side.

       rrrrddcc__iiss__aannyy__ccoonnnneecctteedd
           Return a boolean int if any daemon connections are connected.

       rrrrdd__cclliieenntt__ddiissccoonnnneecctt((rrrrdd__cclliieenntt__tt **cclliieenntt))
       rrrrddcc__ddiissccoonnnneecctt
           Disconnect gracefully from the present daemon connection.

       rrrrdd__cclliieenntt__uuppddaattee((rrrrdd__cclliieenntt__tt **cclliieenntt,, ccoonnsstt cchhaarr **ffiilleennaammee,, iinntt
       vvaalluueess__nnuumm,, ccoonnsstt cchhaarr ** ccoonnsstt **vvaalluueess))
       rrrrddcc__uuppddaattee((ccoonnsstt cchhaarr **ffiilleennaammee,, iinntt vvaalluueess__nnuumm,, ccoonnsstt cchhaarr ** ccoonnsstt
       **vvaalluueess))
           Update the RRD "filename" via the rrdcached. Where "values_num" is
           the number of values to update and "values" are the new values to
           add.

       rrrrdd__cclliieenntt__iinnffoo((rrrrdd__cclliieenntt__tt **cclliieenntt,, ccoonnsstt cchhaarr **ffiilleennaammee))
       rrrrddcc__iinnffoo((ccoonnsstt cchhaarr **ffiilleennaammee))
           Grab rrd info of the RRD "filename" from the connected cache
           daemon.  This function returns an rrd_info_t structure of the
           following format:

               typedef struct rrd_blob_t {
                   unsigned long size; /* size of the blob */
                   unsigned char *ptr; /* pointer */
               } rrd_blob_t;

               typedef enum rrd_info_type { RD_I_VAL = 0,
                   RD_I_CNT,
                   RD_I_STR,
                   RD_I_INT,
                   RD_I_BLO
               } rrd_info_type_t;

               typedef union rrd_infoval {
                   unsigned long u_cnt;
                   rrd_value_t u_val;
                   char     *u_str;
                   int       u_int;
                   rrd_blob_t u_blo;
               } rrd_infoval_t;

               typedef struct rrd_info_t {
                   char     *key;
                   rrd_info_type_t type;
                   rrd_infoval_t value;
                   struct rrd_info_t *next;
               } rrd_info_t;

       rrrrdd__cclliieenntt__llaasstt((rrrrdd__cclliieenntt__tt **cclliieenntt,, ccoonnsstt cchhaarr **ffiilleennaammee))
       rrrrddcc__llaasstt((ccoonnsstt cchhaarr **ffiilleennaammee))
           Grab the unix epoch of the last time RRD "filename" was updated.

       rrrrdd__cclliieenntt__ffiirrsstt((rrrrdd__cclliieenntt__tt **cclliieenntt,, ccoonnsstt cchhaarr **ffiilleennaammee,, iinntt
       rrrraaiinnddeexx))
       rrrrddcc__ffiirrsstt((ccoonnsstt cchhaarr **ffiilleennaammee,, iinntt rrrraaiinnddeexx))
           Get the first value of the first sample of the RRD "filename", of
           the "rraindex" RRA (Round Robin Archive) index number.  The RRA
           index number can be determined by pulling the rrd_info_t off the
           RRD.

       rrrrdd__cclliieenntt__ccrreeaattee((rrrrdd__cclliieenntt__tt **cclliieenntt,, ccoonnsstt cchhaarr **ffiilleennaammee,, uunnssiiggnneedd
       lloonngg ppddpp__sstteepp,, ttiimmee__tt llaasstt__uupp,, iinntt nnoo__oovveerrwwrriittee,, iinntt aarrggcc,, ccoonnsstt cchhaarr
       ****aarrggvv))
       rrrrddcc__ccrreeaattee((ccoonnsstt cchhaarr **ffiilleennaammee,, uunnssiiggnneedd lloonngg ppddpp__sstteepp,, ttiimmee__tt
       llaasstt__uupp,, iinntt nnoo__oovveerrwwrriittee,, iinntt aarrggcc,, ccoonnsstt cchhaarr ****aarrggvv))
           Create RRD database of path "filename".  The RRD will have a step
           size of "pfp_step", the unix epoch timestamp to start collecting
           data from. The number of data sources and RRAs "argc" and the
           definitions of the data sources and RRAs "argv". Lastly whether or
           not to overwrite an existing RRD if one is found with the same
           filename; "no_overwrite".

       rrrrddcc__ccrreeaattee__rr22((rrrrdd__cclliieenntt__tt **cclliieenntt,, ccoonnsstt cchhaarr **ffiilleennaammee,, uunnssiiggnneedd
       lloonngg ppddpp__sstteepp,, ttiimmee__tt llaasstt__uupp,, iinntt nnoo__oovveerrwwrriittee,, ccoonnsstt cchhaarr ****ssoouurrcceess,,
       ccoonnsstt cchhaarr **tteemmppllaattee,, iinntt aarrggcc,, ccoonnsstt cchhaarr ****aarrggvv))
       rrrrddcc__ccrreeaattee__rr22((ccoonnsstt cchhaarr **ffiilleennaammee,, uunnssiiggnneedd lloonngg ppddpp__sstteepp,, ttiimmee__tt
       llaasstt__uupp,, iinntt nnoo__oovveerrwwrriittee,, ccoonnsstt cchhaarr ****ssoouurrcceess,, ccoonnsstt cchhaarr **tteemmppllaattee,,
       iinntt aarrggcc,, ccoonnsstt cchhaarr ****aarrggvv))
           Create an RRD database in the daemon. rrrrddcc__ccrreeaattee__rr22 has the same
           parameters as rrrrddcc__ccrreeaattee with two added parameters of; "sources"
           and "template".

           where "template" is the file path to a RRD file template, with, the
           form defined in rrrrddccrreeaattee(1),

           The "sources" parameter defines series of file paths with data
           defined, to prefill the RRD with. See rrrrddccrreeaattee(1) for more
           details.

       rrrrdd__cclliieenntt__fflluusshh((rrrrdd__cclliieenntt__tt **cclliieenntt,, ccoonnsstt cchhaarr **ffiilleennaammee))
       rrrrddcc__fflluusshh((ccoonnsstt cchhaarr **ffiilleennaammee))
           flush the currently RRD cached in the daemon specified via
           "filename".

       rrrrdd__cclliieenntt__ffoorrggeett((rrrrdd__cclliieenntt__tt **cclliieenntt,, ccoonnsstt cchhaarr **ffiilleennaammee))
       rrrrddcc__ffoorrggeett((ccoonnsstt cchhaarr **ffiilleennaammee))
           Drop the cached data for the RRD file specified via "filename".

       rrrrddcc__fflluusshh__iiff__ddaaeemmoonn((ccoonnsstt cchhaarr **ddaaeemmoonn__aaddddrr,, ccoonnsstt cchhaarr **ffiilleennaammee))
           Flush the specified RRD given by "filename" only if the daemon
           "daemon_addr" is up and connected.

       rrrrdd__cclliieenntt__ffeettcchh((rrrrdd__cclliieenntt__tt **cclliieenntt,, ccoonnsstt cchhaarr **ffiilleennaammee,, ccoonnsstt cchhaarr
       **ccff,, ttiimmee__tt **rreett__ssttaarrtt,, ttiimmee__tt **rreett__eenndd,, uunnssiiggnneedd lloonngg **rreett__sstteepp,,
       uunnssiiggnneedd lloonngg **rreett__ddss__nnuumm,, cchhaarr ******rreett__ddss__nnaammeess,, rrrrdd__vvaalluuee__tt
       ****rreett__ddaattaa))
       rrrrddcc__ffeettcchh((ccoonnsstt cchhaarr **ffiilleennaammee,, ccoonnsstt cchhaarr **ccff,, ttiimmee__tt **rreett__ssttaarrtt,,
       ttiimmee__tt **rreett__eenndd,, uunnssiiggnneedd lloonngg **rreett__sstteepp,, uunnssiiggnneedd lloonngg **rreett__ddss__nnuumm,,
       cchhaarr ******rreett__ddss__nnaammeess,, rrrrdd__vvaalluuee__tt ****rreett__ddaattaa))
           Perform a fetch operation on the specified RRD Database given be
           "filename", where "cf" is the consolidation function, "ret_start"
           is the start time given by unix epoch, "ret_end" is the endtime.
           "ret_step" is the step size in seconds, "ret_ds_num" the number of
           data sources in the RRD, "ret_ds_names" the names of the data
           sources, and a pointer to an rrd_value_t object to shlep the data.

       rrrrddcc__ssttaattss__ggeett((rrrrdd__cclliieenntt__tt **cclliieenntt,, rrrrddcc__ssttaattss__tt ****rreett__ssttaattss))
       rrrrddcc__ssttaattss__ggeett((rrrrddcc__ssttaattss__tt ****rreett__ssttaattss))
           Get stats from the connected daemon, via a linked list of the
           following structure:

               struct rrdc_stats_s {
                   const char *name;
                   uint16_t type;
                   #define RRDC_STATS_TYPE_GAUGE   0x0001
                   #define RRDC_STATS_TYPE_COUNTER 0x0002
                   uint16_t flags;
                   union {
                       uint64_t counter;
                       double   gauge;
                   } value;
                   struct rrdc_stats_s *next;
               };
               typedef struct rrdc_stats_s rrdc_stats_t;

       rrrrddcc__ssttaattss__ffrreeee((rrrrddcc__ssttaattss__tt **rreett__ssttaattss))
           Free the stats struct allocated via rrrrddcc__ssttaattss__ggeett.

   SSEEEE AALLSSOO
           rrrrccaacchheedd(1) rrrrddffeettcchh(1) rrrrddiinnffoo(1) rrrrddllaasstt(1) rrrrddccrreeaattee(1)
           rrrrdduuppddaattee(1) rrrrddllaasstt(1)

AAUUTTHHOORR
       RRD Contributors <rrd-developers@lists.oetiker.ch>



1.5.999                           2016-11-03                         librrd(3)
