@@ -93,6 +93,7 @@ import Data.Aeson.Types (defaultOptions, fieldLabelModifier)
9393import Data.Char (isAlphaNum, toUpper)
9494import qualified Data.HashMap.Strict as HM
9595import Data.Monoid ((<>))
96+import Data.Scientific (floatingOrInteger)
9697import Data.Text (Text)
9798import qualified Data.Text as T
9899import Data.Time.Clock (UTCTime)
@@ -1229,6 +1230,21 @@ instance ToJSON DeviceRate where
12291230 , "Rate" .= r
12301231 ]
12311232
1233+data MemoryConstraintSize = B | M | GB deriving (Eq, Show)
1234+
1235+data MemoryConstraint = MemoryConstraint Integer MemoryConstraintSize deriving (Eq, Show)
1236+
1237+instance ToJSON MemoryConstraint where
1238+ toJSON (MemoryConstraint x B) = toJSON x
1239+ toJSON (MemoryConstraint x M) = toJSON $ x * 1024
1240+ toJSON (MemoryConstraint x GB) = toJSON $ x * 1024 * 1024
1241+
1242+instance FromJSON MemoryConstraint where
1243+ parseJSON (JSON.Number x) = case (floatingOrInteger x) of
1244+ Left _ -> fail "Failed to parse MemoryConstraint"
1245+ Right i -> return $ MemoryConstraint i B -- | The docker daemon will always return the number as bytes (integer), regardless of how we set them (using M or GB)
1246+ parseJSON _ = fail "Failed to parse MemoryConstraint"
1247+
12321248data ContainerResources = ContainerResources {
12331249 cpuShares :: Maybe Integer
12341250 -- , cgroupParent :: Text -- 1.24: Missing from inspecting container details... Going to omit for now.
@@ -1244,10 +1260,10 @@ data ContainerResources = ContainerResources {
12441260 , cpusetMems :: Maybe Text
12451261 , devices :: [Device]
12461262 -- , diskQuota :: Integer -- Don't see this ins 1.24.
1247− , kernelMemory :: Maybe Integer
1248− , memory :: Maybe Integer
1249− , memoryReservation :: Maybe Integer
1250− , memorySwap :: Maybe Integer
1263+ , kernelMemory :: Maybe MemoryConstraint
1264+ , memory :: Maybe MemoryConstraint
1265+ , memoryReservation :: Maybe MemoryConstraint
1266+ , memorySwap :: Maybe MemoryConstraint
12511267 -- , memorySwappiness :: Integer -- 1.24: Missing from inspecting container details... Going to omit for now.
12521268 , oomKillDisable :: Bool
12531269 -- , pidsLimit :: Integer -- 1.24: Missing from inspecting container details... Going to omit for now.