Skip to content

Instantly share code, notes, and snippets.

@jul
Last active June 13, 2024 17:44
Show Gist options
  • Save jul/d9713a07718550170e06be13a760c4c1 to your computer and use it in GitHub Desktop.
Save jul/d9713a07718550170e06be13a760c4c1 to your computer and use it in GitHub Desktop.
compare to normalized rrd created by munin (encuring ds name is 42 foreach rra)
#!/usr/bin/env bash
set -e
[ -z "$2" ] && ( echo "give two rrd with a data serie named 42 to compare their series in ratio of first rrd "; exit 1; )
X=${X:-200}
Y=${Y:-43}
S=${S:-$(( $( date +'%s' ) - ( 24 * 3600 * 7 * 1 ) )) }
TRM=${TRM:-"dumb $X $Y"}
LC_ALL=C rrdtool xport --json -t -s $S -e now \
DEF:x=$1:42:AVERAGE \
VDEF:y=x,MAXIMUM \
VDEF:l=x,MINIMUM \
CDEF:z=x,l,-,y,l,-,/ \
DEF:a=$2:42:AVERAGE \
VDEF:d=a,MAXIMUM \
VDEF:k=a,MINIMUM \
CDEF:e=a,k,-,d,k,-,/,y,l,-,*,l,+ \
XPORT:x:ratio \
XPORT:e:ratio | \
jq -j -c -r '.data[] | .[0]," ",.[1]," ",.[2], "\n"' - > this.csv
gnuplot -p \
-e "set xdata time;set terminal $TRM;
set timefmt \"%s\";set xtics rotate by 45 right;
set format x \"%m/%d/%Y %H:%M\";
plot \"this.csv\" using 1:2 with l title \"$( echo $1 | tr "_" "-" )\", \
\"this.csv\" using 1:3 with line lines \"-\" title \"$( echo $2 | tr "_" "-" )\" ";
# plot the rrd way
LC_ALL=C rrdtool graph graph.png --start $S --end now \
-w $(( $X * 4 )) \
-h $(( $Y * 4 )) \
--watermark "`date`" \
--title "$1 vs $2" \
--font DEFAULT:7: \
DEF:x=$1:42:AVERAGE \
DEF:a=$2:42:AVERAGE \
VDEF:y=x,MAXIMUM \
VDEF:l=x,MINIMUM \
CDEF:z=x,l,-,y,l,-,/ \
VDEF:d=a,MAXIMUM \
VDEF:k=a,MINIMUM \
CDEF:e=a,k,-,d,k,-,/,y,l,-,*,l,+ \
LINE1:x#FF00FF:"$1" \
LINE2:e#0000FF:"ratio of $2" \
GPRINT:x:LAST:"Cur\: %5.2lf" \
GPRINT:x:AVERAGE:"Avg\: %5.2lf" \
GPRINT:x:MAX:"Max\: %5.2lf" \
GPRINT:x:MIN:"Min\: %5.2lf"
@jul
Copy link
Author

jul commented Jun 13, 2024

$X=80 Y=40 ./compre_rrd.sh pierrot.home-ibm_acpi-CPU-g.rrd pierrot.home-hddtemp_smartctl-ada0-g.rrd 

                                                                                
    1 +---------------------------------------------------------------------+   
      |     +     +     +    +     +     +    ##     +     #   ##     +     |   
      |                             pierrot.ho##-ibm_acpi-C#U-g##rd +.....+ |   
      |                    pierrot.home-hddtem##smartctl-ad#0-g##rd ####### |   
      |                                       ##           #   ##           |   
      |                                      ###           #   ##           |   
      |                                      ###           #   ##           |   
  0.8 |-+                                    ###           #   ##         +-|   
      |                                      ###           #   ##  +        |   
      |                      ###############################   ##  :        |   
      |                      #                                 :   :        |   
      |    +                 #                                 +   :        |   
      |    :                 #                                 :   :        |   
      |    :                 #                                 :   :        |   
  0.6 |-+  :                #        +       +    +          + :   : +    +-|   
      |    :                #        :       :    :          : :   : :      |   
      |    :                #        :       :   +:     +    :++   : :      |   
      |    :        +       #        :     ++: + ::    +:  ++:::   + :      |   
      |    :        :    ## #        ::    ::: : ::    ::  :::::   :::      |   
      |    :        :    ## #       +::++++:+: :+++ +++:+++:::+ : +++:      |   
      |    :        :    ## #       ::::::::::::::: ::::::::::: : ::::      |   
      |    :        :    ## #       ::::::::::::::::::::::::::: : ::::      |   
  0.4 |-+  :        + +  ## #       :++++:++++++++++++:++++++++ +++:++++  +-|   
      |    :       :: : # ##        ::   :  : :   ::: : ::::::  ::::  ::    |   
      |    :       :: : # ##        ::   :  : :   ::  : ::::::  :::+  ::    |   
      |    :++++  +:+ + # ##        +:   +  + +   ++  + ++++:+  +:+   ++    |   
      |    :::::  ::::: # ##        ::                      :    :          |   
      |   ############### ##        :+                      +    :          |   
      |    :+:++++##:++++++:        +                            :          |   
  0.2 |-+  :::: ::##: :::   :       :                            :        +-|   
      |    :::: + ##: + +   +       :                            +          |   
      |   :: ::   ##:   :   :       :                                       |   
      |   :: ::   # :   :   :       :                                       |   
      |   ++ ++   # +   +   :++++++:                                        |   
      |           #         ::::::::                                        |   
      |     +     #     +   :+::::::     +     +     +     +    +     +     |   
    0 +---------------------------------------------------------------------+   
  06/12/06/1206/12/06/12/06/13/06/13/06/13/06/1306/13/06/13/06/13/2024 12:00    
                                                                              

@jul
Copy link
Author

jul commented Jun 13, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment