⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dz_regenerate_rrd.in

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 IN
字号:
#! @PERL@# $Id: dz_regenerate_rrd.in,v 1.2 2004/02/29 18:16:44 vtt Exp $# This script repopulates the RRD database with the data found in the trace# file. Following assumptions are made:## 	- The database has been created with dz_create_rrd script (as a# 	  matter of fact, it is called before actual processing);#	- The database start time is exactly the same as the first entry#	  timestamp in the trace file;#	- The database has exactly as many entries as the device order file;#	- If the database has more entries than there are in the trace file,#	  the extra entries go to the end (in other words, 'U' will be#	  *appended* to make up for missing entries)# Rotate the database, and create a new one$rc = system("\@prefix@/bin/dz_rotate_rrd");if ( $rc ) {    die "dz_rotate_rrd returned $rc\n";}$rc = system("\@prefix@/bin/dz_create_rrd");if ( $rc ) {    die "dz_create_rrd returned $rc\n";}# These values are set forth by configure script.$RRD_ORDER = "@RRD_ORDER@";$RRD_DIR = "@RRD_DIR@";$RRD_TRACE = "@RRD_DIR@/trace";$RRD = "${RRD_DIR}/dz.rrd";# Let's see if we have the rrdtoolunless ( "@RRDTOOL@" ne "/bin/false" ) {    die "Sorry, you don't have rrdtool - install it and/or rerun configure";}# If the order file doesn't exist, then you know whatunless ( -r "${RRD_ORDER}" ) {    die "No order file (${RRD_ORDER}) found or it isn't readable, can't regenerate the RRD database.";}# Same for the trace fileunless ( -r "${RRD_TRACE}" ) {    die "No trace file (${RRD_TRACE}) found or it isn't readable, can't regenerate the RRD database.";}# Same for the RRD databaseunless ( -r "${RRD}" ) {    die "No RRD database (${RRD}) found or it isn't readable, can't regenerate the RRD database.";}# Let's see if the number of entries in the order file matches the RRD# database structure$order_entries = `@WC@ -l ${RRD_ORDER}|@TR@ -s " "|@CUT@ -f 2 -d " "|@TR@ -d "\n"`;$rrd_entries = `@RRDTOOL@ info ${RRD} |@GREP@ "^ds"|@GREP@ ".type ="|@WC@ -l|@TR@ -d " \n"`;unless ( $order_entries eq $rrd_entries ) {    print "Count mismatch: ${RRD_ORDER} contains $order_entries entries, whereas RRD ${RRD} reports $rrd_entries\n";    exit 16;}# Now we know that the RRD database should contain $rrd_entries entries, and# if the data from the trace file contains less, then we'll just append 'U'# as necessary.# Before we start, though, let's see how long will it take us... It is known# that the trace file containing 544082 entries takes about 18 min to# execute on a box with a bogomips of 3322.67. Let's see what we have# here...# This is how many records per second we made - 503.77962962963. This number# is quite clumsy, so the hell with it and let it be 500.#$records_per_second = 544082 / (18 * 60); $records_per_second = 500;$actual_records = `@WC@ -l ${RRD_TRACE}|@TR@ -s " "|@CUT@ -f 2 -d " "|@TR@ -d "\n"`;$will_take = $actual_records / $records_per_second;# VT: FIXME: Take bogomips into account (though the dependency is not# necessarily linear)$will_take_seconds = $will_take % 60;$will_take_minutes = ($will_take - $will_take_seconds)/ 60;# Round it off$will_take = sprintf("%.0f", $will_take);$will_take_minutes = sprintf("%.0f", $will_take_minutes);if ( $will_take_minutes < 1 ) {    $will_take_minutes = 0;}print "Relax...\n\n";print "    At about $records_per_second records per second,\n";print "    the whole process is going to take about $will_take_minutes min $will_take_seconds sec\n";print "    We're going to be done at about ".`@DATE@ -d "-$will_take seconds ago"`;$start_time = `@DATE@ +"%s"|@TR@ -d "\n"`;open(IN, ${RRD_TRACE}) or die "Can't open for reading: ${RRD_TRACE}";$line_number = 0;while ( $line = <IN> ) {    $line_number++;    chop($line);        ( $timestamp, @readings ) = split(/:/, $line);        $data = $timestamp;    $count = 0;        foreach $temperature ( @readings ) {            $count++;        $data = $data.":".$temperature;    }        # Just in case, let's see if the number of entries in the trace file    # is not *more* than the entries in the database        if ( $count > $rrd_entries ) {            die "${RRD_TRACE}:$line_number: $count entries found, $rrd_entries expected";    }        # Append missing entries        while ( $count < $rrd_entries ) {            $data = $data.":U";        $count++;    }        # Update the record        #print "$data\n";        system("@RRDTOOL@ update $RRD $data");        #print "rc: $rc\n";}$stop_time = `@DATE@ +"%s"|@TR@ -d "\n"`;$spent_time = $stop_time - $start_time;# VT: Let's hackif ( $spent_time eq 0 ) {    # I don't like divizion by zero errors...        $spent_time = 1;}$records_per_second = $actual_records / $spent_time;$spent_seconds = $spent_time % 60;$spent_minutes = ($spent_time - $spent_seconds)/ 60;$error = $will_take - $spent_time;print "\n";if ( $will_take_minutes > 0 ) {    if ( $error > 0 ) {        print "See! We finished faster!\n";    } else {        print "Oh well, it took longer than expected...\n";    }}print "\n";print "    Actual records per second: $records_per_second\n";print "    Actual time taken:         $spent_minutes min $spent_seconds sec\n";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -