Code

Imported upstream version 1.4.8
[pkg-rrdtool.git] / doc / librrd.txt
1 librrd(3)                           rrdtool                          librrd(3)
5 N\bNA\bAM\bME\bE
6        librrd - RRD library functions
8 D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
9        l\bli\bib\bbr\brr\brd\bd contains most of the functionality in R\bRR\bRD\bDT\bTo\boo\bol\bl.  The command line
10        utilities and language bindings are often just wrappers around the code
11        contained in l\bli\bib\bbr\brr\brd\bd.
13        This manual page documents the l\bli\bib\bbr\brr\brd\bd API.
15        N\bNO\bOT\bTE\bE:\b: This document is a work in progress, and should be considered
16        incomplete as long as this warning persists.  For more information
17        about the l\bli\bib\bbr\brr\brd\bd functions, always consult the source code.
19 C\bCO\bOR\bRE\bE F\bFU\bUN\bNC\bCT\bTI\bIO\bON\bNS\bS
20        r\brr\brd\bd_\b_d\bdu\bum\bmp\bp_\b_c\bcb\bb_\b_r\br(\b(c\bch\bha\bar\br *\b*f\bfi\bil\ble\ben\bna\bam\bme\be,\b, i\bin\bnt\bt o\bop\bpt\bt_\b_h\bhe\bea\bad\bde\ber\br,\b, r\brr\brd\bd_\b_o\bou\but\btp\bpu\but\bt_\b_c\bca\bal\bll\blb\bba\bac\bck\bk_\b_t\bt c\bcb\bb,\b,
21        v\bvo\boi\bid\bd *\b*u\bus\bse\ber\br)\b)
22            In some situations it is necessary to get the output of "rrd_dump"
23            without writing it to a file or the standard output. In such cases
24            an application can ask r\brr\brd\bd_\b_d\bdu\bum\bmp\bp_\b_c\bcb\bb_\b_r\br to call an user-defined
25            function each time there is output to be stored somewhere. This can
26            be used, to e.g. directly feed an XML parser with the dumped output
27            or transfer the resulting string in memory.
29            The arguments for r\brr\brd\bd_\b_d\bdu\bum\bmp\bp_\b_c\bcb\bb_\b_r\br are the same as for r\brr\brd\bd_\b_d\bdu\bum\bmp\bp_\b_o\bop\bpt\bt_\b_r\br
30            except that the output filename parameter is replaced by the user-
31            defined callback function and an additional parameter for the
32            callback function that is passed untouched, i.e. to store
33            information about the callback state needed for the user-defined
34            callback to function properly.
36            Recent versions of r\brr\brd\bd_\b_d\bdu\bum\bmp\bp_\b_o\bop\bpt\bt_\b_r\br internally use this callback
37            mechanism to write their output to the file provided by the user.
39                size_t rrd_dump_opt_cb_fileout(
40                    const void *data,
41                    size_t len,
42                    void *user)
43                {
44                    return fwrite(data, 1, len, (FILE *)user);
45                }
47            The associated call for r\brr\brd\bd_\b_d\bdu\bum\bmp\bp_\b_c\bcb\bb_\b_r\br looks like
49                res = rrd_dump_cb_r(filename, opt_header,
50                    rrd_dump_opt_cb_fileout, (void *)out_file);
52            where the last parameter specifies the file handle
53            r\brr\brd\bd_\b_d\bdu\bum\bmp\bp_\b_o\bop\bpt\bt_\b_c\bcb\bb_\b_f\bfi\bil\ble\beo\bou\but\bt should write to. There's no specific
54            condition for the callback to detect when it is called for the
55            first time, nor for the last time. If you require this for
56            initialization and cleanup you should do those tasks before and
57            after calling r\brr\brd\bd_\b_d\bdu\bum\bmp\bp_\b_c\bcr\br_\b_r\br respectively.
59 U\bUT\bTI\bIL\bLI\bIT\bTY\bY F\bFU\bUN\bNC\bCT\bTI\bIO\bON\bNS\bS
60        _\br\br_\br\br_\bd\bd_\b_\b__\br\br_\ba\ba_\bn\bn_\bd\bd_\bo\bo_\bm\bm_\b(\b(_\b)\b)
61            Generates random numbers just like _\br_\ba_\bn_\bd_\bo_\bm_\b(_\b).  This further ensures
62            that the random number generator is seeded exactly once per
63            process.
65        r\brr\brd\bd_\b_a\bad\bdd\bd_\b_p\bpt\btr\br(\b(v\bvo\boi\bid\bd *\b**\b**\b*d\bde\bes\bst\bt,\b, s\bsi\biz\bze\be_\b_t\bt *\b*d\bde\bes\bst\bt_\b_s\bsi\biz\bze\be,\b, v\bvo\boi\bid\bd *\b*s\bsr\brc\bc)\b)
66            Dynamically resize the array pointed to by "dest".  "dest_size" is
67            a pointer to the current size of "dest".  Upon successful
68            _\br_\be_\ba_\bl_\bl_\bo_\bc_\b(_\b), the "dest_size" is incremented by 1 and the "src"
69            pointer is stored at the end of the new "dest".  Returns 1 on
70            success, 0 on failure.
72                type **arr = NULL;
73                type *elem = "whatever";
74                size_t arr_size = 0;
75                if (!rrd_add_ptr(&arr, &arr_size, elem))
76                    handle_failure();
78        r\brr\brd\bd_\b_a\bad\bdd\bd_\b_s\bst\btr\brd\bdu\bup\bp(\b(c\bch\bha\bar\br *\b**\b**\b*d\bde\bes\bst\bt,\b, s\bsi\biz\bze\be_\b_t\bt *\b*d\bde\bes\bst\bt_\b_s\bsi\biz\bze\be,\b, c\bch\bha\bar\br *\b*s\bsr\brc\bc)\b)
79            Like "rrd_add_ptr", except adds a "strdup" of the source string.
81                char **arr = NULL;
82                size_t arr_size = NULL;
83                char *str  = "example text";
84                if (!rrd_add_strdup(&arr, &arr_size, str))
85                    handle_failure();
87        r\brr\brd\bd_\b_f\bfr\bre\bee\be_\b_p\bpt\btr\brs\bs(\b(v\bvo\boi\bid\bd *\b**\b**\b*s\bsr\brc\bc,\b, s\bsi\biz\bze\be_\b_t\bt *\b*c\bcn\bnt\bt)\b)
88            Free an array of pointers allocated by "rrd_add_ptr" or
89            "rrd_add_strdup".  Also frees the array pointer itself.  On return,
90            the source pointer will be NULL and the count will be zero.
92                /* created as above */
93                rrd_free_ptrs(&arr, &arr_size);
94                /* here, arr == NULL && arr_size == 0 */
96        r\brr\brd\bd_\b_m\bmk\bkd\bdi\bir\br_\b_p\bp(\b(c\bco\bon\bns\bst\bt c\bch\bha\bar\br *\b*p\bpa\bat\bth\bhn\bna\bam\bme\be,\b, m\bmo\bod\bde\be_\b_t\bt m\bmo\bod\bde\be)\b)
97            Create the directory named "pathname" including all of its parent
98            directories (similar to "mkdir -p" on the command line - see
99            _\bm_\bk_\bd_\bi_\br(1) for more information). The argument "mode" specifies the
100            permissions to use. It is modified by the process's "umask". See
101            _\bm_\bk_\bd_\bi_\br(2) for more details.
103            The function returns 0 on success, a negative value else. In case
104            of an error, "errno" is set accordingly. Aside from the errors
105            documented in _\bm_\bk_\bd_\bi_\br(2), the function may fail with the following
106            errors:
108            E\bEI\bIN\bNV\bVA\bAL\bL
109                "pathname" is "NULL" or the empty string.
111            E\bEN\bNO\bOM\bME\bEM\bM
112                Insufficient memory was available.
114            a\ban\bny\by e\ber\brr\bro\bor\br r\bre\bet\btu\bur\brn\bne\bed\bd b\bby\by _\bs\bs_\bt\bt_\ba\ba_\bt\bt(\b(2\b2)\b)
116            In contrast to _\bm_\bk_\bd_\bi_\br(2), the function does n\bno\bot\bt fail if "pathname"
117            already exists and is a directory.
119 A\bAU\bUT\bTH\bHO\bOR\bR
120        RRD Contributors <rrd-developers@lists.oetiker.ch>
124 1.4.8                             2013-05-23                         librrd(3)