{
    "mode": "perldoc",
    "parameter": "RRDs",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/RRDs/json",
    "generated": "2026-06-14T06:04:57Z",
    "synopsis": "use RRDs;\nRRDs::error\nRRDs::last ...\nRRDs::info ...\nRRDs::create ...\nRRDs::update ...\nRRDs::updatev ...\nRRDs::graph ...\nRRDs::fetch ...\nRRDs::tune ...\nRRDs::times(start, end)\nRRDs::dump ...\nRRDs::restore ...\nRRDs::flushcached ...\nRRDs::registerfetchcb ...\n$RRDs::VERSION",
    "sections": {
        "NAME": {
            "content": "RRDs - Access RRDtool as a shared module\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use RRDs;\nRRDs::error\nRRDs::last ...\nRRDs::info ...\nRRDs::create ...\nRRDs::update ...\nRRDs::updatev ...\nRRDs::graph ...\nRRDs::fetch ...\nRRDs::tune ...\nRRDs::times(start, end)\nRRDs::dump ...\nRRDs::restore ...\nRRDs::flushcached ...\nRRDs::registerfetchcb ...\n$RRDs::VERSION\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "",
            "subsections": [
                {
                    "name": "Calling Sequence",
                    "content": "This module accesses RRDtool functionality directly from within Perl. The arguments to the\nfunctions listed in the SYNOPSIS are explained in the regular RRDtool documentation. The command\nline call\n\nrrdtool update mydemo.rrd --template in:out N:12:13\n\ngets turned into\n\nRRDs::update (\"mydemo.rrd\", \"--template\", \"in:out\", \"N:12:13\");\n\nNote that\n\n--template=in:out\n\nis also valid.\n\nThe RRDs::times function takes two parameters: a \"start\" and \"end\" time. These should be\nspecified in the AT-STYLE TIME SPECIFICATION format used by RRDtool. See the rrdfetch\ndocumentation for a detailed explanation on how to specify time.\n"
                },
                {
                    "name": "Error Handling",
                    "content": "The RRD functions will not abort your program even when they cannot make sense out of the\narguments you fed them.\n\nThe function RRDs::error should be called to get the error status after each function call. If\nRRDs::error does not return anything then the previous function has completed its task\nsuccessfully.\n\nuse RRDs;\nRRDs::update (\"mydemo.rrd\",\"N:12:13\");\nmy $ERR=RRDs::error;\ndie \"ERROR while updating mydemo.rrd: $ERR\\n\" if $ERR;\n"
                },
                {
                    "name": "Return Values",
                    "content": "The functions RRDs::last, RRDs::graph, RRDs::info, RRDs::fetch and RRDs::times return their\nfindings.\n\nRRDs::last returns a single INTEGER representing the last update time.\n\n$lastupdate = RRDs::last ...\n\nRRDs::graph returns an ARRAY containing the x-size and y-size of the created image and a pointer\nto an array with the results of the PRINT arguments.\n\n($resultarr,$xsize,$ysize) = RRDs::graph ...\nprint \"Imagesize: ${xsize}x${ysize}\\n\";\nprint \"Averages: \", (join \", \", @$averages);\n\nRRDs::info returns a pointer to a hash. The keys of the hash represent the property names of the\nRRD and the values of the hash are the values of the properties.\n\n$hash = RRDs::info \"example.rrd\";\nforeach my $key (keys %$hash){\nprint \"$key = $$hash{$key}\\n\";\n}\n\nRRDs::graphv takes the same parameters as RRDs::graph but it returns a pointer to hash. The hash\nreturned contains meta information about the graph. Like its size as well as the position of the\ngraph area on the image. When calling with '-' as the filename then the contents of the graph\nwill be returned in the hash as well (key 'image').\n\nRRDs::updatev also returns a pointer to hash. The keys of the hash are concatenated strings of a\ntimestamp, RRA index, and data source name for each consolidated data point (CDP) written to\ndisk as a result of the current update call. The hash values are CDP values.\n\nRRDs::fetch is the most complex of the pack regarding return values. There are 4 values. Two\nnormal integers, a pointer to an array and a pointer to an array of pointers.\n\nmy ($start,$step,$names,$data) = RRDs::fetch ...\nprint \"Start:       \", scalar localtime($start), \" ($start)\\n\";\nprint \"Step size:   $step seconds\\n\";\nprint \"DS names:    \", join (\", \", @$names).\"\\n\";\nprint \"Data points: \", $#$data + 1, \"\\n\";\nprint \"Data:\\n\";\nfor my $line (@$data) {\nprint \"  \", scalar localtime($start), \" ($start) \";\n$start += $step;\nfor my $val (@$line) {\nprintf \"%12.1f \", $val;\n}\nprint \"\\n\";\n}\n\nRRDs::xport exposes the rrdxport functionality and returns data with the following structure:\n\nmy ($start,$end,$step,$cols,$names,$data) = RRDs::xport ...\n\n# $start : timestamp\n# $end   : timestamp\n# $step  : seconds\n# $cols  : number of returned columns\n# $names : arrayref with the names of the columns\n# $data  : arrayref of arrayrefs with the data (first index is time, second is column)\n\nRRDs::times returns two integers which are the number of seconds since epoch (1970-01-01) for\nthe supplied \"start\" and \"end\" arguments, respectively.\n\nSee the examples directory for more ways to use this extension.\n"
                },
                {
                    "name": "Fetch Callback Function",
                    "content": "Normally when using graph, xport or fetch the data you see will come from an actual rrd file.\nSome people who like the look of rrd charts, therefore export their data from a database and\nthen load it into an rrd file just to be able to call rrdgraph on it. Using a custom callback,\nyou can supply your own code for handling the data requests from graph, xport and fetch.\n\nTo do this, you have to first write a fetch function in perl, and then register this function\nusing \"RRDs::fetchregistercallback\".\n\nFinally you can use the pseudo path name cb//[*filename*] to tell rrdtool to use your callback\nroutine instead of the normal rrdtool fetch function to organize the data required.\n\nThe callback function must look like this:\n\nsub fetchcallback {\nmy $argshash = shift;\n# {\n#  filename => 'cb//somefilename',\n#  cd => 'AVERAGE',\n#  start => 1401295291,\n#  end => 1401295591,\n#  step => 300 }\n\n# do some clever thing to get that data ready\n\nreturn {\nstart => $unixtimestamp,\nstep => $stepwidth,\ndata => {\ndsName1 => [ value1, value2, ... ],\ndsName2 => [ value1, value2, ... ],\ndsName3 => [ value1, value2, ... ],\n}\n};\n}\n"
                }
            ]
        },
        "NOTE": {
            "content": "If you are manipulating the TZ variable you should also call the POSIX function tzset(3) to\ninitialize all internal states of the library for properly operating in the timezone of your\nchoice.\n\nuse POSIX qw(tzset);\n$ENV{TZ} = 'CET';\nPOSIX::tzset();\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Tobias Oetiker <tobi@oetiker.ch>\n",
            "subsections": []
        }
    },
    "summary": "RRDs - Access RRDtool as a shared module",
    "flags": [],
    "examples": [],
    "see_also": []
}