{
    "mode": "man",
    "parameter": "librrd",
    "section": "3",
    "url": "https://www.chedong.com/phpMan.php/man/librrd/3/json",
    "generated": "2026-07-05T11:45:51Z",
    "sections": {
        "NAME": {
            "content": "librrd - RRD library functions\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "librrd contains most of the functionality in RRDtool.  The command line utilities and\nlanguage bindings are often just wrappers around the code contained in librrd.\n\nThis manual page documents the librrd API.\n\nNOTE: This document is a work in progress, and should be considered incomplete as long as\nthis warning persists.  For more information about the librrd functions, always consult the\nsource code.\n",
            "subsections": []
        },
        "CORE FUNCTIONS": {
            "content": "rrddumpcbr(char *filename, int optheader, rrdoutputcallbackt cb, void *user)\nIn some situations it is necessary to get the output of \"rrddump\" without writing it to\na file or the standard output. In such cases an application can ask rrddumpcbr to call\na user-defined function each time there is output to be stored somewhere. This can be\nused, to e.g. directly feed an XML parser with the dumped output or transfer the\nresulting string in memory.\n\nThe arguments for rrddumpcbr are the same as for rrddumpoptr except that the output\nfilename parameter is replaced by the user-defined callback function and an additional\nparameter for the callback function that is passed untouched, i.e. to store information\nabout the callback state needed for the user-defined callback to function properly.\n\nRecent versions of rrddumpoptr internally use this callback mechanism to write their\noutput to the file provided by the user.\n\nsizet rrddumpoptcbfileout(\nconst void *data,\nsizet len,\nvoid *user)\n{\nreturn fwrite(data, 1, len, (FILE *)user);\n}\n\nThe associated call for rrddumpcbr looks like\n\nres = rrddumpcbr(filename, optheader,\nrrddumpoptcbfileout, (void *)outfile);\n\nwhere the last parameter specifies the file handle rrddumpoptcbfileout should write\nto. There's no specific condition for the callback to detect when it is called for the\nfirst time, nor for the last time. If you require this for initialization and cleanup you\nshould do those tasks before and after calling rrddumpcbr respectively.\n\nrrdfetchcbregister(rrdfetchcbt c)\nIf your data does not reside in rrd files, but you would like to draw charts using the\nrrdgraph functionality, you can supply your own rrdfetch function and register it using\nthe rrdfetchcbregister function.\n\nThe argument signature and api must be the same of the callback function and must be\nequivalent to the one of rrdfetchfn in rrdfetch.c.\n\nTo activate the callback function you can use the pseudo filename cb//freeformtext.\n\nNote that rrdtool graph will not ask the same rrd for data twice. It determines this by\nbuilding a key out of the values supplied to the fetch function. If the values are the\nsame, the previous answer will be used.\n",
            "subsections": []
        },
        "UTILITY FUNCTIONS": {
            "content": "rrdrandom()\nGenerates random numbers just like random().  This further ensures that the random number\ngenerator is seeded exactly once per process.\n\nrrdstrtodbl\nan rrd aware string to double converter which sets rrderror in if there is a problem and\nuses the return code exclusively for conversion status reporting.\n\nrrdstrtod\nworks like normal strtod, but it is locale independent (and thread safe)\n\nrrdsnprintf\nworks  like normal snprintf but it is locale independent (and thread safe)\n\nrrdaddptr(void *dest, sizet *destsize, void *src)\nDynamically resize the array pointed to by \"dest\".  \"destsize\" is a pointer to the\ncurrent size of \"dest\".  Upon successful realloc(), the \"destsize\" is incremented by 1\nand the \"src\" pointer is stored at the end of the new \"dest\".  Returns 1 on success, 0 on\nfailure.\n\ntype arr = NULL;\ntype *elem = \"whatever\";\nsizet arrsize = 0;\nif (!rrdaddptr(&arr, &arrsize, elem))\nhandlefailure();\n\nrrdaddptrchunk(void *dest, sizet *destsize, void *src, sizet *alloc, sizet chunk)\nLike \"rrdaddptr\", except the destination is allocated in chunks of \"chunk\".  \"alloc\"\npoints to the number of entries allocated, whereas \"destsize\" points to the number of\nvalid pointers.  If more pointers are needed, \"chunk\" pointers are allocated and \"alloc\"\nis increased accordingly.  \"alloc\" must be >= \"destsize\".\n\nThis method improves performance on hosts with expensive \"realloc()\".\n\nrrdaddstrdup(char *dest, sizet *destsize, char *src)\nLike \"rrdaddptr\", except adds a \"strdup\" of the source string.\n\nchar arr = NULL;\nsizet arrsize = NULL;\nchar *str  = \"example text\";\nif (!rrdaddstrdup(&arr, &arrsize, str))\nhandlefailure();\n\nrrdaddstrdupchunk(char *dest, sizet *destsize, char *src, sizet *alloc, sizet chunk)\nLike \"rrdaddstrdup\", except the destination is allocated in chunks of \"chunk\".  \"alloc\"\npoints to the number of entries allocated, whereas \"destsize\" points to the number of\nvalid pointers.  If more pointers are needed, \"chunk\" pointers are allocated and \"alloc\"\nis increased accordingly.  \"alloc\" must be >= \"destsize\".\n\nrrdfreeptrs(void *src, sizet *cnt)\nFree an array of pointers allocated by \"rrdaddptr\" or \"rrdaddstrdup\".  Also frees the\narray pointer itself.  On return, the source pointer will be NULL and the count will be\nzero.\n\n/* created as above */\nrrdfreeptrs(&arr, &arrsize);\n/* here, arr == NULL && arrsize == 0 */\n\nrrdmkdirp(const char *pathname, modet mode)\nCreate the directory named \"pathname\" including all of its parent directories (similar to\n\"mkdir -p\" on the command line - see mkdir(1) for more information). The argument \"mode\"\nspecifies the permissions to use. It is modified by the process's \"umask\". See mkdir(2)\nfor more details.\n\nThe function returns 0 on success, a negative value else. In case of an error, \"errno\" is\nset accordingly. Aside from the errors documented in mkdir(2), the function may fail with\nthe following errors:\n\nEINVAL\n\"pathname\" is \"NULL\" or the empty string.\n\nENOMEM\nInsufficient memory was available.\n\nany error returned by stat(2)\n\nIn contrast to mkdir(2), the function does not fail if \"pathname\" already exists and is a\ndirectory.\n\nrrdscaledduration (const char * token, unsigned long divisor, unsigned long * valuep)\nParse a token in a context where it contains a count (of seconds or PDP instances), or a\nduration that can be converted to a count by representing the duration in seconds and\ndividing by some scaling factor.  For example, if a user would natively express a 3 day\narchive of samples collected every 2 minutes, the sample interval can be represented by\n\"2m\" instead of 120, and the archive duration by \"3d\" (to be divided by 120) instead of\n2160 (3*24*60*60 / 120).  See more examples in \"STEP, HEARTBEAT, and Rows As Durations\"\nin rrdcreate.\n\n\"token\" must be a number with an optional single-character suffix encoding the scaling\nfactor:\n\n\"s\" indicates seconds\n\n\"m\" indicates minutes.  The value is multiplied by 60.\n\n\"h\" indicates hours.  The value is multiplied by 3600 (or \"60m\").\n\n\"d\" indicates days.  The value is multiplied by 86400 (or \"24h\").\n\n\"w\" indicates weeks.  The value is multiplied by 604800 (or \"7d\").\n\n\"M\" indicates months.  The value is multiplied by 2678400 (or \"31d\").  (Note this factor\naccommodates the maximum number of days in a month.)\n\n\"y\" indicates years.  The value is multiplied by 31622400 (or \"366d\").  (Note this factor\naccommodates leap years.)\n\n\"divisor\" is a positive value representing the duration in seconds of an interval that\nthe desired result counts.\n\n\"valuep\" is a pointer to where the decoded value will be stored if the conversion is\nsuccessful.\n\nThe initial characters of \"token\" must be the base-10 representation of a positive\ninteger, or the conversion fails.\n\nIf the remainder \"token\" is empty (no suffix), it is a count and no scaling is performed.\n\nIf \"token\" has one of the suffixes above, the count is multiplied to convert it to a\nduration in seconds.  The resulting number of seconds is divided by \"divisor\" to produce\na count of intervals each of duration \"divisor\" seconds.  If division would produce a\nremainder (e.g., \"5m\" (300 seconds) divided by \"90s\"), the conversion is invalid.\n\nIf \"token\" has unrecognized trailing characters the conversion fails.\n\nThe function returns a null pointer if the conversion was successful and \"valuep\" has\nbeen updated to the scaled value.  On failure, it returns a text diagnostic suitable for\nuse in user error messages.\n",
            "subsections": []
        },
        "CLIENT FUNCTIONS": {
            "content": "The following functions are used to connected to an rrdcached instance, either via a unix or\ninet address, and create, update, or gather statistics about a specified RRD database file.\n\nThere are two different interfaces: The rrdclient family of functions operate on a user-\nprovided client object (rrdclientt) and support multiple concurrent connections to rrdcache\ninstances. The simpler rrdc family of functions handles connections transparently but can\nonly be used for one connection at a time.\n\nAll of the following functions and data types are specified in the \"rrdclient.h\" header\nfile.\n\nrrdclientnew(const char *daemonaddr)\nCreate a new client connection object. If specified, connect to the daemon at\n\"daemonaddr\". The connection can later be changed by calling rrdclientconnect.\n\nrrdclientdestroy(rrdclientt *client)\nClose a client connection and destroy the object by freeing all dynamically allocated\nmemory. After calling this function, \"client\" can no longer be used.\n\nrrdclientconnect(rrdclientt *client, const char *daemonaddr)\nrrdcconnect(const char *daemonaddr)\nConnect to a running rrdcached instance, specified via \"daemonaddr\". Any previous\nconnection will be closed. If \"daemonaddr\" is \"NULL\", it defaults to the value of the\n\"ENVRRDCACHEDADDRESS\" environment address.\n\nrrdclientisconnected(rrdclientt *client)\nReturn a boolean int if the client is connected to the server.\n\nrrdclientaddress(rrdclientt *client)\nReturns the server address belonging to the current connection.\n\nrrdcisconnected(const char *daemonaddr)\nReturn a boolean int to determine if the client is connected to the rrdcache daemon\nspecified by the \"daemonaddr\" parameter.\n\nrrdclientping(rrdclientt *client)\nrrdcping\nCheck the client connection by pinging the remote side.\n\nrrdcisanyconnected\nReturn a boolean int if any daemon connections are connected.\n\nrrdclientdisconnect(rrdclientt *client)\nrrdcdisconnect\nDisconnect gracefully from the present daemon connection.\n\nrrdclientupdate(rrdclientt *client, const char *filename, int valuesnum, const char *\nconst *values)\nrrdcupdate(const char *filename, int valuesnum, const char * const *values)\nUpdate the RRD \"filename\" via the rrdcached. Where \"valuesnum\" is the number of values\nto update and \"values\" are the new values to add.\n\nrrdclientinfo(rrdclientt *client, const char *filename)\nrrdcinfo(const char *filename)\nGrab rrd info of the RRD \"filename\" from the connected cache daemon.  This function\nreturns an rrdinfot structure of the following format:\n\ntypedef struct rrdblobt {\nunsigned long size; /* size of the blob */\nunsigned char *ptr; /* pointer */\n} rrdblobt;\n\ntypedef enum rrdinfotype { RDIVAL = 0,\nRDICNT,\nRDISTR,\nRDIINT,\nRDIBLO\n} rrdinfotypet;\n\ntypedef union rrdinfoval {\nunsigned long ucnt;\nrrdvaluet uval;\nchar     *ustr;\nint       uint;\nrrdblobt ublo;\n} rrdinfovalt;\n\ntypedef struct rrdinfot {\nchar     *key;\nrrdinfotypet type;\nrrdinfovalt value;\nstruct rrdinfot *next;\n} rrdinfot;\n\nrrdclientlast(rrdclientt *client, const char *filename)\nrrdclast(const char *filename)\nGrab the unix epoch of the last time RRD \"filename\" was updated.\n\nrrdclientfirst(rrdclientt *client, const char *filename, int rraindex)\nrrdcfirst(const char *filename, int rraindex)\nGet the first value of the first sample of the RRD \"filename\", of the \"rraindex\" RRA\n(Round Robin Archive) index number.  The RRA index number can be determined by pulling\nthe rrdinfot off the RRD.\n\nrrdclientcreate(rrdclientt *client, const char *filename, unsigned long pdpstep, timet\nlastup, int nooverwrite, int argc, const char argv)\nrrdccreate(const char *filename, unsigned long pdpstep, timet lastup, int nooverwrite,\nint argc, const char argv)\nCreate RRD database of path \"filename\".  The RRD will have a step size of \"pfpstep\", the\nunix epoch timestamp to start collecting data from. The number of data sources and RRAs\n\"argc\" and the definitions of the data sources and RRAs \"argv\". Lastly whether or not to\noverwrite an existing RRD if one is found with the same filename; \"nooverwrite\".\n\nrrdccreater2(rrdclientt *client, const char *filename, unsigned long pdpstep, timet\nlastup, int nooverwrite, const char sources, const char *template, int argc, const char\nargv)\nrrdccreater2(const char *filename, unsigned long pdpstep, timet lastup, int\nnooverwrite, const char sources, const char *template, int argc, const char argv)\nCreate an RRD database in the daemon. rrdccreater2 has the same parameters as\nrrdccreate with two added parameters of; \"sources\" and \"template\".\n\nwhere \"template\" is the file path to a RRD file template, with, the form defined in\nrrdcreate(1),\n\nThe \"sources\" parameter defines series of file paths with data defined, to prefill the\nRRD with. See rrdcreate(1) for more details.\n\nrrdclientflush(rrdclientt *client, const char *filename)\nrrdcflush(const char *filename)\nflush the currently RRD cached in the daemon specified via \"filename\".\n\nrrdclientforget(rrdclientt *client, const char *filename)\nrrdcforget(const char *filename)\nDrop the cached data for the RRD file specified via \"filename\".\n\nrrdcflushifdaemon(const char *daemonaddr, const char *filename)\nFlush the specified RRD given by \"filename\" only if the daemon \"daemonaddr\" is up and\nconnected.\n\nrrdclientfetch(rrdclientt *client, const char *filename, const char *cf, timet\n*retstart, timet *retend, unsigned long *retstep, unsigned long *retdsnum, char\n*retdsnames, rrdvaluet retdata)\nrrdcfetch(const char *filename, const char *cf, timet *retstart, timet *retend, unsigned\nlong *retstep, unsigned long *retdsnum, char *retdsnames, rrdvaluet retdata)\nPerform a fetch operation on the specified RRD Database given be \"filename\", where \"cf\"\nis the consolidation function, \"retstart\" is the start time given by unix epoch,\n\"retend\" is the endtime. \"retstep\" is the step size in seconds, \"retdsnum\" the number\nof data sources in the RRD, \"retdsnames\" the names of the data sources, and a pointer\nto an rrdvaluet object to shlep the data.\n\nrrdcstatsget(rrdclientt *client, rrdcstatst retstats)\nrrdcstatsget(rrdcstatst retstats)\nGet stats from the connected daemon, via a linked list of the following structure:\n\nstruct rrdcstatss {\nconst char *name;\nuint16t type;\n#define RRDCSTATSTYPEGAUGE   0x0001\n#define RRDCSTATSTYPECOUNTER 0x0002\nuint16t flags;\nunion {\nuint64t counter;\ndouble   gauge;\n} value;\nstruct rrdcstatss *next;\n};\ntypedef struct rrdcstatss rrdcstatst;\n\nrrdcstatsfree(rrdcstatst *retstats)\nFree the stats struct allocated via rrdcstatsget.\n\nSEE ALSO\nrrcached(1) rrdfetch(1) rrdinfo(1) rrdlast(1) rrdcreate(1) rrdupdate(1) rrdlast(1)\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "RRD Contributors <rrd-developers@lists.oetiker.ch>\n\n\n\n1.7.2                                        2022-03-17                                    librrd(3)",
            "subsections": []
        }
    },
    "summary": "librrd - RRD library functions",
    "flags": [],
    "examples": [],
    "see_also": []
}