1. Stefan Saasen
  2. stash-log-parser

Commits

Stefan Saasen  committed f6b4db8

Show protocol usage per hour

  • Participants
  • Parent commits d2baf13
  • Branches master

Comments (0)

Files changed (4)

File gnuplot/generate-git-protocol.plot

View file
  • Ignore whitespace
+# 2012-08-22 18:32:08 6
+set datafile separator "|"
+set terminal png size 1400,1000 font "/Library/Fonts/Arial.ttf"
+set xdata time
+set logscale y
+set timefmt "%Y-%m-%d %H"
+set output "git-protocol.png"
+# time range must be in same format as data file
+#set xrange ["Mar-25-00:00:00":"Mar-26-00:00:00"]
+set yrange [1:*]
+#set autoscale ymax
+
+set ytics nomirror
+
+set grid
+set xlabel "Date"
+set ylabel "Protocol usage"
+set title "Git protocol usage per hour"
+set format x "%d %b"
+set key left top reverse Left
+#  0: Date
+#  1-6: clone, fetch, shallow clone, push, ref advertisement (sum cache hit & cache miss)
+#  7-11: cache hits
+#  12-16: cache miss'
+plot    "protocol-stats" using 1:2 with lines title "ssh", \
+        "protocol-stats" using 1:3 with lines title "http(s)"

File regenerate-graphs.sh

View file
  • Ignore whitespace
 
 time logparser plotConnHour ${LOG_FILE} +RTS -sstderr  > plot-all
 gnuplot < gnuplot/generate-max-conn-plot.plot
+
+
+time logparser plotProtocolStats ${LOG_FILE} > protocol-stats
+gnuplot < gnuplot/generate-git-protocol.plot

File src/Main.hs

View file
  • Ignore whitespace
           ,("plotConnMinute",       generatePlotDataConcurrentConn plotDataConcurrentConnMinute)
           ,("plotConnHour",         generatePlotDataConcurrentConn plotDataConcurrentConnHour)
           ,("plotGitOperations",    generatePlotDataGitOps plotGitOperations)
+          ,("plotProtocolStats",    generateProtocolData protocolStatsByHour)
           ,("protocol",             mapToTopList protocolCount)]
 
+generateProtocolData :: (Input -> [ProtocolStats]) -> FilePath -> IO ()
+generateProtocolData f path = do
+        plotData <- liftM f $ toLines path
+        mapM_ (\(ProtocolStats date ssh http) -> printf "%s|%d|%d\n" date ssh http) plotData
+
 generatePlotDataGitOps :: (Input -> [GitOperationStats]) -> FilePath -> IO ()
 generatePlotDataGitOps f path = do
         plotData <- liftM f $ toLines path

File src/Stash/Log/Analyser.hs

View file
  • Ignore whitespace
 , countRequestLines
 , Input
 , GitOperationStats(..)
+, ProtocolStats(..)
 , DateValuePair(..)
 , maxConcurrent
 , protocolCount
 , plotDataConcurrentConnMinute
 , plotDataConcurrentConnHour
 , plotGitOperations
+, protocolStatsByHour
 , showLines
 ) where
 
 
 type Input = [L.ByteString]
 
+data ProtocolStats = ProtocolStats {
+     getProtocolLogDate     :: !String
+    ,getSsh                 :: !Int
+    ,getHttp                :: !Int
+}
+
 data GitOperationStats = GitOperationStats {
      getOpStatDate              :: String
     ,cacheMisses                :: [Int] -- clone, fetch, shallow clone, push, ref advertisement
 isPush :: LogLine -> Bool
 isPush logLine = inLabel logLine "push"
 
+isSsh :: LogLine -> Bool
+isSsh logLine = getProtocol logLine == "ssh"
+
+isHttp :: LogLine -> Bool
+isHttp logLine = proto == "http" || proto == "https"
+                where proto = getProtocol logLine
+
 -- The concurrent connection data needs to be aggregated.
 -- Example
 --
 summarizeGitOperations formatLogDate = foldl' aggregate emptyStats . filter isOutgoingLogLine
                         where aggregate = updateStats formatLogDate
 
+protocolStatsByHour :: Input -> [ProtocolStats]
+protocolStatsByHour rawLines = let  groups = groupBy (logDateEqHour `on` getDate) $ parseLines rawLines
+                                    formatLogDate date = printf "%04d-%02d-%02d %02d" (getYear date) (getMonth date) (getDay date) (getHour date)
+                                in map (protocolStats formatLogDate) groups
+
+protocolStats :: (LogDate -> String) -> [LogLine] -> ProtocolStats
+protocolStats formatLogDate logLines = foldl' aggregate (ProtocolStats "" 0 0) logLines
+                        where aggregate (ProtocolStats date ssh http) logLine =
+                                    let !ssh'   = if isSsh logLine then ssh + 1 else ssh
+                                        !http'  = if isHttp logLine then http + 1 else http
+                                        !date'  = if null date then formatLogDate $ getDate logLine else date
+                                    in ProtocolStats date' ssh' http'
 
 showLines :: Input -> [Maybe LogLine]
 showLines = take 5 . map parseLogLine