📄 dz_graph_temperature.in
字号:
#! @PERL@# $Id: dz_graph_temperature.in,v 1.2 2004/02/29 18:16:44 vtt Exp $# This script will create a set of graphs for different time intervals.# These values are set forth by configure script.$RRD_ORDER = "@RRD_ORDER@";$RRD_DIR = "@RRD_DIR@";$RRD_TRACE = "@RRD_DIR@/trace";$RRD_OUT = "@RRD_DIR@/html";$RRD = "${RRD_DIR}/dz.rrd";# This is the mapping from the interval ("xxx ago") and the name of the file# the graph for this interval will be written into. Note that the file name# doesn't contain the extension - that'll be up to your taste, with default# to PNG.%intervals = ( "1 hour ago" => "temp-1h", "3 hours ago" => "temp-3h", "6 hours ago" => "temp-6h", "32 hours ago" => "temp-32h", "8 days ago" => "temp-8d", "5 weeks ago" => "temp-5w", "13 months ago" => "temp-13m", "3 years ago" => "temp-3y");# This is the default format. Check RRD documentation on available formats.# VT: FIXME: It may happen that the file extension is not necessarily a# lowercase format, then, we'll have to provide the mapping.$image_format = "PNG";$ext = lc($image_format);# Image size - your taste may differ$width = 800;$height = 400;# Colors available# VT: FIXME: It may be a good idea to read the color map from an external# source - that'll allow to customize the colors.# VT: FIXME: Extend the list so more than 6 colors are available@colors = ( "ff0000", "00ff00", "0000ff", "ffff00", "ff00ff", "00ffff" );# 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 RRD databaseunless ( -r "${RRD}" ) { die "No RRD database (${RRD}) found or it isn't readable, can't regenerate the RRD database";}# Let's collect the device addresses. If everything's done right, then the# number of entries will be exactly the same as the number of entries in the# RRD database (see dz_create_rrd script).# VT: FIXME:## - It is possible to gather a list of devices even without the device order# file, but directly from RRD## - In any case, device order file provides the device order *to write to# RRD*, which probably is not the order you want to plot them in. Another# file may be created to list that order.@devices = ();open(IN, ${RRD_ORDER}) or die "Can't open ${RRD_ORDER} for reading, can't regenerate the RRD database";while ( $line = <IN> ) { chop($line); push(@devices, $line);}# Let's remember current date. Technically, we don't need it since rrdgraph# defaults to 'now', but just in case we ever need to change it, let it be.$current_date = `@DATE@ +"%s"|@TR@ -d "\n"`;foreach $interval ( keys %intervals ) { $target = $intervals{$interval}; $start_date = `@DATE@ -d \"$interval\" +\"%s\"|@TR@ -d "\n"`; $interval_title = "last ".`@ECHO@ "$interval"|@SED@ -e "s/ ago//;"|@TR@ -d "\n"`; $start_date_title = `@DATE@ -d \"$interval\" +\"%X %A %x\"|@TR@ -d "\n"`; $title = "Temperature, C: $interval_title (since $start_date_title)"; $command = "@RRDTOOL@ graph ${RRD_OUT}/${target}.${ext} \\\n"; $command .= " --start $start_date \\\n"; $command .= " --end $current_date \\\n"; $command .= " --imgformat ${image_format} \\\n"; $command .= " --title \"$title\" \\\n"; $command .= " --width $width \\\n"; $command .= " --height $height \\\n"; # VT: This is questionable, but works to my taste if ( ($interval eq "1 hour ago") || ($interval eq "3 hours ago") ) { $command .= " --rigid \\\n"; } # VT: This looks nicer than default to me $command .= " --alt-autoscale \\\n"; # VT: Let's say that this is a default color scheme... # VT: FIXME: Think about a customizable color scheme later $command .= " --color BACK#2c2450 \\\n"; $command .= " --color CANVAS#003300 \\\n"; $command .= " --color SHADEA#666699 \\\n"; $command .= " --color SHADEB#000011 \\\n"; $command .= " --color GRID#2c2450 \\\n"; $command .= " --color MGRID#777777 \\\n"; $command .= " --color FONT#ddb104 \\\n"; $command .= " --color FRAME#2c2450 \\\n"; $command .= " --color ARROW#ff0000 \\\n"; # Now that the command part is done, let's collect the definitions # VT: FIXME: When I become old and smart, I will look up the information # that rrdinfo gives me - and then I'll be able to figure out what type # to request. Since I'm not yet that old and smart, I will just say that # I want the "LAST" entry for anything that is less than a week, and # "AVERAGE" for everything else. Actually, looking up the database # information will possibly be simpler in the long run, but it's # midnight right now and I want to see the result RIGHT AWAY. if ( ($interval eq "1 hour ago") || ($interval eq "3 hours ago") || ($interval eq "6 hours ago") || ($interval eq "32 hours ago") ) { $RRA_CF = "LAST"; } else { $RRA_CF = "AVERAGE"; } # Get the DEF lines foreach $device ( @devices ) { $command .= " DEF:def_$device=${RRD}:$device:$RRA_CF \\\n"; } # Get the LINE lines $color_offset = 0; $total_colors = scalar @colors; foreach $device ( @devices ) { # VT: FIXME: Again, when I'm old and smart, I'll read the mapping # from device address to the zone name, if it is available. Humans # like familiar names, you know. $color = @colors[$color_offset++ % $total_colors]; $command .= " LINE1:def_$device#$color:\"$device\\n\" \\\n"; } # Don't forget to terminate the command - actually, just remove the last # endline and backslash chop($command); chop($command); # rrdgraph has a habit of displaying the image size - it's nice, of # course, if we're making an HTML page, but doesn't necessarily help # when this script is run from a cron job. Let's quiet it down. Since # there's no standard way of quieting it down, we have to be rude and # just gag it altogether. $command .= "> /dev/null"; # VT: FIXME: This command gets synthesized on the fly, executed and # discarded. However, once the things settle down, one may want to # customize the graphs, and make some of them prettier. For that, it # would be a good idea to just make this script produce the other script # with the literal commands embedded into it, and give the user ability # to customize *that* script by directly editing it. # VT: Don't forget to embed the date invocation into that script, as # opposed to literal values embedded into this command. system($command);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -