#!/usr/bin/awk -f # http://apfelboymchen.net/gnu/shell/ # # Copyright (C) 2011 Moritz Orbach # # This is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # birth: 21.06.2011 # # USAGE # - while :; do date +%s; date; cat /proc/drbd; sleep 30;done | tee drbd.out # - run the sync or verify # - ./rrddrbd.awk drbd.out > awk2rrd.out # - while read line; do rrdtool update database.rrd "$line"; done < awk2rrd.out # # PITFALLS # You have to "rrdtool create" the database with the "--start" parameter! # Otherwise RRD will refuse to fill the database, because the database then will # start at the creation date. # # birth: 2011-06-29 01:24:51.064926690 +0200 # function print_row() { printf("%s", time) for (c in column) { printf(":%s", column[c]) column[c] = "0:0:0" } print "" } # timestamp /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*/ { if (time != "") { # found a new one! print finished row print_row() } time = $0 #print ">"device"<" #print "ARGH " device " " column[device] } /^ *[0-9]*:/ { sub(/:/, "", $1) device = $1 #print "device: " device } /finish/ { gsub(/,/, "") # thousands separator gsub(/\(|\)/, "", $5) # braces around the average column[device] = sprintf("%s:%s:%s", $4, $5, $7) #print "argh " device " " column[device] } END { print_row() }