private void getLinuxEnvironment(Map<String, String> propertyMap) { // the following probably doesn't work on ALL linux Multimap<String, String> cpuInfo = propertiesFromLinuxFile("/proc/cpuinfo"); propertyMap.put("host.cpus", Integer.toString(cpuInfo.get("processor").size())); String s = "cpu cores"; propertyMap.put("host.cpu.cores", describe(cpuInfo, s)); propertyMap.put("host.cpu.names", describe(cpuInfo, "model name")); propertyMap.put("host.cpu.cachesize", describe(cpuInfo, "cache size")); Multimap<String, String> memInfo = propertiesFromLinuxFile("/proc/meminfo"); // TODO redo memInfo.toString() so we don't get square brackets propertyMap.put("host.memory.physical", memInfo.get("MemTotal").toString()); propertyMap.put("host.memory.swap", memInfo.get("SwapTotal").toString()); }
@Provides @Singleton Host provideHost(EnvironmentGetter environmentGetter) { return environmentGetter.getHost(); }
Host getHost() { return new Host.Builder() .addAllProperies(getProperties()) .build(); }
private Map<String, String> getProperties() { TreeMap<String, String> propertyMap = Maps.newTreeMap(); Map<String, String> sysProps = Maps.fromProperties(System.getProperties()); // Sometimes java.runtime.version is more descriptive than java.version String version = sysProps.get("java.version"); String alternateVersion = sysProps.get("java.runtime.version"); if (alternateVersion != null && alternateVersion.length() > version.length()) { version = alternateVersion; } propertyMap.put("host.availableProcessors", Integer.toString(Runtime.getRuntime().availableProcessors())); String osName = sysProps.get("os.name"); propertyMap.put("os.name", osName); propertyMap.put("os.version", sysProps.get("os.version")); propertyMap.put("os.arch", sysProps.get("os.arch")); if (osName.equals("Linux")) { getLinuxEnvironment(propertyMap); } return propertyMap; }
Host getHost() { return new Host.Builder() .addAllProperies(getProperties()) .build(); }
private Map<String, String> getProperties() { TreeMap<String, String> propertyMap = Maps.newTreeMap(); Map<String, String> sysProps = Maps.fromProperties(System.getProperties()); // Sometimes java.runtime.version is more descriptive than java.version String version = sysProps.get("java.version"); String alternateVersion = sysProps.get("java.runtime.version"); if (alternateVersion != null && alternateVersion.length() > version.length()) { version = alternateVersion; } propertyMap.put("host.availableProcessors", Integer.toString(Runtime.getRuntime().availableProcessors())); String osName = sysProps.get("os.name"); propertyMap.put("os.name", osName); propertyMap.put("os.version", sysProps.get("os.version")); propertyMap.put("os.arch", sysProps.get("os.arch")); if (osName.equals("Linux")) { getLinuxEnvironment(propertyMap); } return propertyMap; }
private void getLinuxEnvironment(Map<String, String> propertyMap) { // the following probably doesn't work on ALL linux Multimap<String, String> cpuInfo = propertiesFromLinuxFile("/proc/cpuinfo"); propertyMap.put("host.cpus", Integer.toString(cpuInfo.get("processor").size())); String s = "cpu cores"; propertyMap.put("host.cpu.cores", describe(cpuInfo, s)); propertyMap.put("host.cpu.names", describe(cpuInfo, "model name")); propertyMap.put("host.cpu.cachesize", describe(cpuInfo, "cache size")); Multimap<String, String> memInfo = propertiesFromLinuxFile("/proc/meminfo"); // TODO redo memInfo.toString() so we don't get square brackets propertyMap.put("host.memory.physical", memInfo.get("MemTotal").toString()); propertyMap.put("host.memory.swap", memInfo.get("SwapTotal").toString()); }
@Provides @Singleton Host provideHost(EnvironmentGetter environmentGetter) { return environmentGetter.getHost(); }