module Network.Memcache.Stats (
getValue
, getPid
, getUptime
, getTime
, getVersion
, getPointerSize
, getRusageUser
, getRusageSystem
, getCurrItems
, getTotalItems
, getBytes
, getCurrConnections
, getTotalConnections
, getConnectionStructures
, getCmdGet
, getCmdSet
, getGetHits
, getGetMisses
, getEvictions
, getBytesRead
, getBytesWritten
, getLimitMaxbytes
, getThreads
) where
import Data.Int
import Data.Word
import Data.List.Split
import Network.Memcache.Client
getValue :: String -> StatsList -> Maybe String
getValue key statsList = lookup key statsList
getPid :: StatsList -> Maybe Word32
getPid = getValueAs "pid"
getUptime :: StatsList -> Maybe Word32
getUptime = getValueAs "uptime"
getTime :: StatsList -> Maybe Word32
getTime = getValueAs "time"
getVersion :: StatsList -> Maybe String
getVersion = getValue "version"
getPointerSize :: StatsList -> Maybe Int32
getPointerSize = getValueAs "pointer_size"
getRusageUser :: StatsList -> Maybe (Word32, Word32)
getRusageUser sl = do
ru <- getValue "rusage_user" sl
case splitOn "." ru of
(second:microsec:[]) -> return (read second, read microsec)
_ -> fail "invalid rusage_user"
getRusageSystem :: StatsList -> Maybe (Word32, Word32)
getRusageSystem sl = do
ru <- getValue "rusage_system" sl
case splitOn "." ru of
(second:microsec:[]) -> return (read second, read microsec)
_ -> fail "invalid rusage_system"
getCurrItems :: StatsList -> Maybe Word64
getCurrItems = getValueAs "curr_items"
getTotalItems :: StatsList -> Maybe Word64
getTotalItems = getValueAs "total_items"
getBytes :: StatsList -> Maybe Word64
getBytes = getValueAs "bytes"
getCurrConnections :: StatsList -> Maybe Word32
getCurrConnections = getValueAs "curr_connections"
getTotalConnections :: StatsList -> Maybe Word32
getTotalConnections = getValueAs "total_connections"
getConnectionStructures :: StatsList -> Maybe Word32
getConnectionStructures = getValueAs "connection_structures"
getCmdGet :: StatsList -> Maybe Word64
getCmdGet = getValueAs "cmd_get"
getCmdSet :: StatsList -> Maybe Word64
getCmdSet = getValueAs "cmd_set"
getGetHits :: StatsList -> Maybe Word64
getGetHits = getValueAs "get_hits"
getGetMisses :: StatsList -> Maybe Word64
getGetMisses = getValueAs "get_misses"
getEvictions :: StatsList -> Maybe Word64
getEvictions = getValueAs "evictions"
getBytesRead :: StatsList -> Maybe Word64
getBytesRead = getValueAs "bytes_read"
getBytesWritten :: StatsList -> Maybe Word64
getBytesWritten = getValueAs "bytes_written"
getLimitMaxbytes :: StatsList -> Maybe Word64
getLimitMaxbytes = getValueAs "limit_maxbytes"
getThreads :: StatsList -> Maybe Word32
getThreads = getValueAs "threads"
getValueAs :: (Read a) => String -> StatsList -> Maybe a
getValueAs key statsList = do
value <- getValue key statsList
return (read value)