diff options
-rwxr-xr-x | plugins/impstats/statslog-graph.py | 35 | ||||
-rwxr-xr-x | plugins/impstats/statslog-splitter.py | 10 |
2 files changed, 34 insertions, 11 deletions
diff --git a/plugins/impstats/statslog-graph.py b/plugins/impstats/statslog-graph.py index 7edafb21..abd4d5c3 100755 --- a/plugins/impstats/statslog-graph.py +++ b/plugins/impstats/statslog-graph.py @@ -28,6 +28,7 @@ bBarChart = False bConvertPng = False bLogarithmicChart = False bFilledLineChart = False +bChartCalcDelta = False # Init variables aFields = [] @@ -44,8 +45,8 @@ iStartSeconds = 0 for arg in sys.argv[-4:]: if arg.find("--input=") != -1: szInput = arg[8:] - elif arg.find("--outputdir=") != -1: - szOutputFile = arg[12:] + elif arg.find("--outputfile=") != -1: + szOutputFile = arg[13:] elif arg.find("--maxdataxlabel=") != -1: nMaxDataCount = int(arg[16:]) elif arg.find("--xlabeldatetime") != -1: @@ -64,6 +65,8 @@ for arg in sys.argv[-4:]: bLogarithmicChart = True elif arg.find("--filledlinechart") != -1: bFilledLineChart = True + elif arg.find("--chartscalcdelta") != -1: + bChartCalcDelta = True elif arg.find("--h") != -1 or arg.find("-h") != -1 or arg.find("--help") != -1: bHelpOutput = True @@ -84,6 +87,7 @@ if bHelpOutput == True: print " --barchart Generates a Barchart (Cannot be used with --linechart)" print " --logarithmic Uses Logarithmic to scale the Y Axis, maybe useful in some cases. Default is OFF" print " --filledlinechart Use filled lines on Linechart, maybe useful in some cases. Default is OFF" + print " --chartscalcdelta If set, charts will use calculated delta values instead of cumulative values." print " --convertpng Generate PNG Output rather than SVG. " print " Default is SVG output." print " --h / -h / --help Displays this help message. \n" @@ -91,16 +95,19 @@ if bHelpOutput == True: else: # Generate output filename if len(szInput) > 0: - if szInput.rfind(".") == -1: - szOutputFile += szInput + ".svg" - else: - szOutputFile += szInput[:-4] + ".svg" + # Only set output filename if not specified + if len(szOutputFile) == 0: + if szInput.rfind(".") == -1: + szOutputFile += szInput + ".svg" + else: + szOutputFile += szInput[:-4] + ".svg" else: print "Error, no input file specified!" sys.exit(0) # Process inputfile inputfile = open(szInput, 'r') + aLineDataPrev = [] # Helper variable for previous line! for line in inputfile.readlines(): if nLineCount == 0: aFields = line.strip().split(";") @@ -137,7 +144,16 @@ else: # Set data field aData[field].append( iTimeStamp - iStartSeconds ) elif iFieldNum > 2: - aData[field].append( int(aLineData[iFieldNum]) ) + # Check if we need to calculate Deltas! + if bChartCalcDelta and len(aLineDataPrev) > 0: + iPreviousVal = int(aLineDataPrev[iFieldNum]) + iCurrentVal = int(aLineData[iFieldNum]) + if iCurrentVal != 0: # Calc DELTA + aData[field].append(iCurrentVal - iPreviousVal) + else: # Don't Calc delta value! + aData[field].append( iCurrentVal ) + else: + aData[field].append( int(aLineData[iFieldNum]) ) else: aData[field].append( aLineData[iFieldNum] ) @@ -147,8 +163,9 @@ else: # Increment counter nDataRecordCound += 1 - #print aData - #sys.exit(0) + # in case deltas need to be calculated, Store current line into previous line + if bChartCalcDelta: + aLineDataPrev = aLineData # Increment counter nLineCount += 1 diff --git a/plugins/impstats/statslog-splitter.py b/plugins/impstats/statslog-splitter.py index a32584cb..84668d9e 100755 --- a/plugins/impstats/statslog-splitter.py +++ b/plugins/impstats/statslog-splitter.py @@ -23,6 +23,7 @@ bLogarithmicChart = False bLineChart = True bBarChart = False bFilledLineChart = False +bChartCalcDelta = False szChartsFormat = "svg" # Helper variables @@ -72,6 +73,8 @@ for arg in sys.argv[-4:]: bBarChart = True elif arg.find("--filledlinechart") != -1: bFilledLineChart = True + elif arg.find("--chartscalcdelta") != -1: + bChartCalcDelta = True elif arg.find("--h") != -1 or arg.find("-h") != -1 or arg.find("--help") != -1: bHelpOutput = True @@ -89,10 +92,11 @@ if bHelpOutput: print " Default is disabled." print " --chartsformat=<svg|png> Format which should be used for Charts." print " Default is svg format" - print " --logarithmic Uses Logarithmic to scale the Y Axis, maybe useful in some cases. Default is OFF" + print " --logarithmic Uses Logarithmic to scale the Y Axis, maybe useful in some cases. Default is OFF." print " --linechart If set, line charts will be generated (Default)." print " --barchart If set, bar charts will be generated." - print " --filledlinechart Use filled lines on Linechart, maybe useful in some cases. Default is OFF" + print " --filledlinechart Use filled lines on Linechart, maybe useful in some cases. Default is OFF." + print " --chartscalcdelta If set, charts will use calculated delta values instead of cumulative values." print "\n Sampleline: ./statslog-splitter.py singlefile --input=rsyslog-stats.log --outputdir=/home/user/csvlogs/ --enablecharts --chartsformat=png" elif bSingleObjectOutput: inputfile = open(szInput, 'r') @@ -206,6 +210,8 @@ elif bSingleObjectOutput: szChartAddArgs += " --logarithmic" if bFilledLineChart: szChartAddArgs += " --filledlinechart" + if bChartCalcDelta: + szChartAddArgs += " --chartscalcdelta" # Default SVG Format! if szChartsFormat.find("svg") != -1: |