changeset 188:711ef14d18d2

add object to determine available memory on linux
author smith@nwoca.org
date Thu, 26 Mar 2015 17:26:44 +0100
parents 6d5b9cf9fd97
children a80191d5a6ca
files init20.gradle
diffstat 1 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/init20.gradle	Thu Mar 05 17:14:22 2015 +0000
+++ b/init20.gradle	Thu Mar 26 17:26:44 2015 +0100
@@ -55,11 +55,14 @@
     }
 }
 
+gradle.ext.runtimeInfo = new RuntimeInfo()
+
 gradle.ext.branch = new BranchInfo(System.getenv('bamboo_planRepository_branch'))
 gradle.ext.branchName = gradle.branch.name
 gradle.ext.branchStream = gradle.branch.stream
 gradle.ext.branchHash = gradle.branch.hash
 println "${gradle.hgRepositoryUrl} ${gradle.branch}"
+println "$gradle.runtimeInfo"
 
 loadEnvironments()
 
@@ -496,6 +499,28 @@
 }
 
 
+@ToString(includeNames=true)
+class RuntimeInfo {
+    // OS memory in megabytes, zero if unknown
+    int systemMemory = 0
+    int systemFreeMemory = 0
+
+    RuntimeInfo() {
+        try {
+            new File('/proc/meminfo').readLines().findAll { it.startsWith 'Mem' }.collect { it.split(/\s+/) }.each {
+                int value = (it[1] as Long) / 1024
+                if (it[0].startsWith('MemTotal')) { systemMemory = value }
+                if (it[0].startsWith('MemFree')) { systemFreeMemory = value }
+            }
+
+        } catch (e) {  }
+
+    }
+
+}
+
+
+
 @ToString
 class BranchInfo {
     def name