@@ -93,6 +93,7 @@ import Data.Aeson.Types (defaultOptions, fieldLabelModifier)
93import Data.Char (isAlphaNum, toUpper)
93import Data.Char (isAlphaNum, toUpper)
94import qualified Data.HashMap.Strict as HM
94import qualified Data.HashMap.Strict as HM
95import Data.Monoid ((<>))
95import Data.Monoid ((<>))
96+import Data.Scientific (floatingOrInteger)
96import Data.Text (Text)
97import Data.Text (Text)
97import qualified Data.Text as T
98import qualified Data.Text as T
98import Data.Time.Clock (UTCTime)
99import Data.Time.Clock (UTCTime)
@@ -1229,6 +1230,21 @@ instance ToJSON DeviceRate where
1229 , "Rate" .= r
1230 , "Rate" .= r
1233+data MemoryConstraintSize = B | M | GB deriving (Eq, Show)
1235+data MemoryConstraint = MemoryConstraint Integer MemoryConstraintSize deriving (Eq, Show)
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
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"
1232data ContainerResources = ContainerResources {
1248data ContainerResources = ContainerResources {
1233 cpuShares :: Maybe Integer
1249 cpuShares :: Maybe Integer
1234 -- , cgroupParent :: Text -- 1.24: Missing from inspecting container details... Going to omit for now.
1250 -- , cgroupParent :: Text -- 1.24: Missing from inspecting container details... Going to omit for now.
@@ -1244,10 +1260,10 @@ data ContainerResources = ContainerResources {
1244 , cpusetMems :: Maybe Text
1260 , cpusetMems :: Maybe Text
1245 , devices :: [Device]
1261 , devices :: [Device]
1246 -- , diskQuota :: Integer -- Don't see this ins 1.24.
1262 -- , diskQuota :: Integer -- Don't see this ins 1.24.
1247− , kernelMemory :: Maybe Integer
1263+ , kernelMemory :: Maybe MemoryConstraint
1248− , memory :: Maybe Integer
1264+ , memory :: Maybe MemoryConstraint
1249− , memoryReservation :: Maybe Integer
1265+ , memoryReservation :: Maybe MemoryConstraint
1250− , memorySwap :: Maybe Integer
1266+ , memorySwap :: Maybe MemoryConstraint
1251 -- , memorySwappiness :: Integer -- 1.24: Missing from inspecting container details... Going to omit for now.
1267 -- , memorySwappiness :: Integer -- 1.24: Missing from inspecting container details... Going to omit for now.
1252 , oomKillDisable :: Bool
1268 , oomKillDisable :: Bool
1253 -- , pidsLimit :: Integer -- 1.24: Missing from inspecting container details... Going to omit for now.
1269 -- , pidsLimit :: Integer -- 1.24: Missing from inspecting container details... Going to omit for now.