1. Stefan Saasen
  2. stash-log-parser

Commits

Stefan Saasen  committed f5bdf76

Add username to the request duration output

  • Participants
  • Parent commits 742c4b0
  • Branches master

Comments (0)

Files changed (2)

File logparser/src/Main.hs

View file
  • Ignore whitespace
 module Main where
 
 import qualified Data.ByteString.Lazy.Char8 as L
+import qualified Data.ByteString.Char8 as S
 import qualified Codec.Compression.BZip as BZip
 import Stash.Log.Parser
 import Stash.Log.Analyser
 generateCloneRequestDurations :: (Input -> [RequestDurationStat]) -> [FilePath] -> IO ()
 generateCloneRequestDurations g path = do
         plotData <- liftM g $ toLines path
-        printf "# Date | Clone duration (cache hit) | Clone duration (cache miss) | Fetch (hit) | Fetch (miss) | Shallow Clone (hit) | Shallow Clone (miss) | Push (hit) | Push (miss) | Ref adv (hit) | Ref adv (miss) | Client IP\n"
-        mapM_ (\(RequestDurationStat date clientIp [cm,fm,sm,pm,rm] [c,f,s,p,r])
-                -> printf "%s|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%s\n" (show date) c cm f fm s sm p pm r rm clientIp) plotData
+        printf "# Date | Clone duration (cache hit) | Clone duration (cache miss) | Fetch (hit) | Fetch (miss) | Shallow Clone (hit) | Shallow Clone (miss) | Push (hit) | Push (miss) | Ref adv (hit) | Ref adv (miss) | Client IP | Username \n"
+        mapM_ (\(RequestDurationStat date clientIp [cm,fm,sm,pm,rm] [c,f,s,p,r] username)
+                -> printf "%s|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%s|%s\n" (show date) c cm f fm s sm p pm r rm clientIp (S.unpack username)) plotData
 
 parseAndPrint :: (Show a) => (Input -> a) -> [FilePath] -> IO ()
 parseAndPrint f path = print . f . L.lines =<< readFiles path

File logparser/src/Stash/Log/GitOpsAnalyser.hs

View file
  • Ignore whitespace
 import qualified Data.HashMap.Strict as M
 import Data.String.Utils (split)
 import Data.List (foldl', groupBy)
-import Data.Maybe (isJust, mapMaybe)
+import Data.Maybe (isJust, mapMaybe, fromMaybe)
 import Data.Function (on)
 import Text.Printf (printf)
 import Stash.Log.Parser
    ,getClientIp                 :: !String
    ,cacheMissDurations          :: ![Int]
    ,cacheHitDurations           :: ![Int] -- clone, fetch, shallow clone, push, ref advertisement
+   ,requestUsername             :: !S.ByteString
 }
 
 -- | Parse and aggregate the log file input into a list of hourly GitOperationStats
                                     inc op      = if op line then (+duration) else id
                                     missOps     = map (inc . uncachedOperation) ops
                                     hitOps      = map (inc . cachedOperation) ops
+                                    username'   = fromMaybe "-" $ getUsername line
                                     !misses     = zipWith id missOps zero
                                     !hits       = zipWith id hitOps zero
-                               in RequestDurationStat (getDate line) (clientIp line) misses hits
+                               in RequestDurationStat (getDate line) (clientIp line) misses hits username'
 
 emptyStats :: GitOperationStats
 emptyStats = GitOperationStats "" zero zero