From 7b16f5c49766fb8d08835e2f2839d4514dc29f9a Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Wed, 3 Jul 2013 13:21:46 +0200 Subject: Finished statslog graph and splitter script. Also added needed javascript files, so they can be included into the svg files. This removes dependencies on external sources. The statslog-splitter can now automatically generated SVG or PNG charts together with an index.html in the output directory. This helps taking a quick view on all generated stats data. --- plugins/impstats/statslog-splitter.py | 56 ++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 8 deletions(-) (limited to 'plugins/impstats/statslog-splitter.py') diff --git a/plugins/impstats/statslog-splitter.py b/plugins/impstats/statslog-splitter.py index 82cc01cc..b342f94c 100755 --- a/plugins/impstats/statslog-splitter.py +++ b/plugins/impstats/statslog-splitter.py @@ -11,12 +11,17 @@ import sys import datetime import time import re +import os # Set default variables szInput = "rsyslog-stats.log" szOutputDir = "./" bSingleObjectOutput = True -bHelpOutput = True +bHelpOutput = False +bEnableCharts = False +szChartsFormat = "svg" + +# Helper variables nLogLineNum = 0 nLogFileCount = 0 @@ -37,14 +42,16 @@ for arg in sys.argv[-4:]: szInput = arg[8:] elif arg.find("--outputdir=") != -1: szOutputDir = arg[12:] - elif arg.find("--singlefile=") != -1: + elif arg.find("--singlefile") != -1: bSingleObjectOutput = True + elif arg.find("--enablecharts") != -1: + bEnableCharts = True + elif arg.find("--chartsformat=") != -1: + szChartsFormat = arg[15:] elif arg.find("--h") != -1 or arg.find("-h") != -1 or arg.find("--help") != -1: bHelpOutput = True -#sys.exit(0) - -if bHelpOutput == 1: +if bHelpOutput: print "\n\nStatslog-splitter command line options:" print "=======================================" print " --input= Contains the path and filename of your impstats logfile. " @@ -54,10 +61,10 @@ if bHelpOutput == 1: print " --h / -h / --help Displays this help message. \n" print " --singlefile Splits the stats logfile into single CSV Files" print " Default is enabled." - print " --enablecharts Generate Charts for each exported CSV File. + print " --enablecharts Generate Charts for each exported CSV File." print " Default is disabled." - print " --chartsformat= Format which should be used for Charts. - print " Default is svg format + print " --chartsformat= Format which should be used for Charts." + print " Default is svg format" print "\n Sampleline: ./statslog-splitter.py singlefile --input=rsyslog-stats.log --outputdir=/home/user/csvlogs/ --enablecharts --chartsformat=png" elif bSingleObjectOutput: inputfile = open(szInput, 'r') @@ -128,11 +135,44 @@ elif bSingleObjectOutput: #print "IMPStats Line found: " + line + # Close outfiles + for outFileName in outputFiles: + outputFiles[outFileName].close() + # Close input file inputfile.close() print "\n File " + szInput + " has been processed" print " " + str(nLogFileCount) + " Logfiles have been exported to " + szOutputDir + + if bEnableCharts: + # Open HTML Code + szHtmlCode = "
" + + # Default SVG Format! + if szChartsFormat.find("svg") != -1: + for outFileName in outputFiles: + iReturn = os.system("./statslog-graph.py --input=" + szOutputDir + "/" + outFileName + "") + print "Chart SVG generated for '" + outFileName + "': " + str(iReturn) + szHtmlCode += "
" + "


" + # Otherwise PNG Output! + else: + for outFileName in outputFiles: + iReturn = os.system("./statslog-graph.py --input=" + szOutputDir + "/" + outFileName + " --convertpng") + print "Chart PNG generated for '" + outFileName + "': " + str(iReturn) + szHtmlCode += "" + "

" + + print " " + str(nLogFileCount) + " Charts have been written " + szOutputDir + + # Close HTML Code + szHtmlCode += "
" + + # Write HTML Index site! + outHtmlFile = open(szOutputDir + "/index.html", 'w') + outHtmlFile.write(szHtmlCode) + outHtmlFile.close() + print " HTML Index with all charts has been written to " + szOutputDir + "/index.html" + print "\n\n" # Close Error log on exit -- cgit v1.2.3