Skip to content

Commit

Permalink
RWSPU-45: Fixing some 64bitgit add . failing architectures
Browse files Browse the repository at this point in the history
  • Loading branch information
kaweesi committed Sep 14, 2016
1 parent b8a49f0 commit 305aabd
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public static JSONObject generateRwandaSPHEMTDHISDataValueSets() {
JSONArray jsonToBePushed;
JSONArray jsonDataValueSets = new JSONArray();
SystemMonitorService systemMonitorService = Context.getService(SystemMonitorService.class);
OSAndHardwareIndicators osshi = new OSAndHardwareIndicators();

String systemId = OSAndHardwareIndicators.getHostName() + "-" + (OSAndHardwareIndicators.getMacAddress() != null
? OSAndHardwareIndicators.getMacAddress().replace(":", "") : "");
String systemId = osshi.getHostName() + "-" + (osshi.getMacAddress() != null
? osshi.getMacAddress().replace(":", "") : "");

String dhisOrgUnitUid = DHISMapping
.getDHISMappedObjectValue(systemMonitorService.getCurrentConfiguredDHISOrgUnit().getPropertyValue());
Expand All @@ -48,23 +49,23 @@ public static JSONObject generateRwandaSPHEMTDHISDataValueSets() {

String openmrsAPPName = WebConstants.WEBAPP_NAME;

Integer uptime = OSAndHardwareIndicators.PROCESSOR_SYSTEM_UPTIME.intValue();
Integer uptime = osshi.PROCESSOR_SYSTEM_UPTIME.intValue();

String processor = OSAndHardwareIndicators.getLinuxProcessorName();
String processor = osshi.getLinuxProcessorName();

Integer openmrsUptime = systemMonitorService.getOpenMRSSystemUpTime().intValue();

Long freeMemory = OSAndHardwareIndicators.MEMORY_AVAILABLE;
Long freeMemory = osshi.MEMORY_AVAILABLE;

Long usedMemory = OSAndHardwareIndicators.MEMORY_USED;
Long usedMemory = osshi.MEMORY_USED;

Long totalMemory = OSAndHardwareIndicators.MEMORY_TOTAL;
Long totalMemory = osshi.MEMORY_TOTAL;

String operatingSystem = SystemPropertiesIndicators.OS_NAME + ", Family: " + OSAndHardwareIndicators.OS_FAMILY
+ ", Manufacturer: " + OSAndHardwareIndicators.OS_MANUFACTURER + ", Version Name: "
+ OSAndHardwareIndicators.OS_VERSION_NAME + ", Version Number: "
+ OSAndHardwareIndicators.OS_VERSION_NUMBER + ", Build Number: "
+ OSAndHardwareIndicators.OS_VERSION_BUILDNUMBER;
String operatingSystem = SystemPropertiesIndicators.OS_NAME + ", Family: " + osshi.OS_FAMILY
+ ", Manufacturer: " + osshi.OS_MANUFACTURER + ", Version Name: "
+ osshi.OS_VERSION_NAME + ", Version Number: "
+ osshi.OS_VERSION_NUMBER + ", Build Number: "
+ osshi.OS_VERSION_BUILDNUMBER;

String operatingSystemArch = SystemPropertiesIndicators.OS_ARCH;

Expand Down Expand Up @@ -101,7 +102,7 @@ public static JSONObject generateRwandaSPHEMTDHISDataValueSets() {
JSONObject serverRealLocation = null;
try {
serverRealLocation = CurlEmulator
.get(SystemMonitorConstants.IP_INFO_URL + OSAndHardwareIndicators.getIpAddress(), null, null);
.get(SystemMonitorConstants.IP_INFO_URL + osshi.getIpAddress(), null, null);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (SocketException e) {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,99 +25,100 @@
import oshi.software.os.OperatingSystemVersion;

public class OSAndHardwareIndicators {
private static SystemInfo si = new SystemInfo();
private SystemInfo si = new SystemInfo();

private static CentralProcessor p = getCentralProcessor();
private CentralProcessor p = getCentralProcessor();

private static HardwareAbstractionLayer hal = si.getHardware();
private HardwareAbstractionLayer hal = si.getHardware();

private static GlobalMemory memory = getMemory();
private GlobalMemory memory = getMemory();

private static OperatingSystem os = getOperatingSystem();
private OperatingSystem os = getOperatingSystem();

private static Sensors s = si.getHardware().getSensors();
private Sensors s = si.getHardware().getSensors();

private static OperatingSystemVersion version = os != null ? os.getVersion() : null;
private OperatingSystemVersion version = os != null ? os.getVersion() : null;

private static PowerSource[] psArr = /*si.getHardware().getPowerSources()*/null;;
private PowerSource[] psArr = /*
* si.getHardware().getPowerSources( )
*/null;;

public static String PROCESSOR_NAME = getLinuxProcessorName();
public String PROCESSOR_NAME = getLinuxProcessorName();

public static String PROCESSOR_VENDOR = p != null ? p.getVendor() : null;
public String PROCESSOR_VENDOR = p != null ? p.getVendor() : null;

public static Double PROCESSOR_SYSTEM_LOAD = p != null ? p.getSystemLoadAverage() : null;
public Double PROCESSOR_SYSTEM_LOAD = p != null ? p.getSystemLoadAverage() : null;

public static String PROCESSOR_SERIAL_NUMBER = p != null ? p.getSystemSerialNumber() : null;
public String PROCESSOR_SERIAL_NUMBER = p != null ? p.getSystemSerialNumber() : null;

public static Integer PROCESSOR_LOGICAL_COUNT = p != null ? p.getLogicalProcessorCount() : null;
public Integer PROCESSOR_LOGICAL_COUNT = p != null ? p.getLogicalProcessorCount() : null;

public static Integer PROCESSOR_PHYSICAL_COUNT = p != null ? p.getPhysicalProcessorCount() : null;
public Integer PROCESSOR_PHYSICAL_COUNT = p != null ? p.getPhysicalProcessorCount() : null;

public static Integer PROCESSOR_THREAD_COUNT = p != null ? p.getThreadCount() : null;
public Integer PROCESSOR_THREAD_COUNT = p != null ? p.getThreadCount() : null;

/**
* Total Physical Memory (RAM) in Megabytes(MB)
*/
public static Long MEMORY_TOTAL = memory != null ? memory.getTotal() / 1048576
public Long MEMORY_TOTAL = memory != null ? memory.getTotal() / 1048576
: Runtime.getRuntime().maxMemory() / 1048576;

/**
* Used Physical Memory (RAM) in Megabytes(MB)
*/
public static Long MEMORY_USED = memory != null ? (memory.getTotal() - memory.getAvailable()) / 1048576
public Long MEMORY_USED = memory != null ? (memory.getTotal() - memory.getAvailable()) / 1048576
: Runtime.getRuntime().totalMemory() / 1048576;

/**
* Available Physical Memory (RAM) in Megabytes(MB)
*/
public static Long MEMORY_AVAILABLE = memory != null ? memory.getAvailable() / 1048576
public Long MEMORY_AVAILABLE = memory != null ? memory.getAvailable() / 1048576
: Runtime.getRuntime().freeMemory() / 1048576;

/**
* Total Swap memory in Megabytes(MB)
*/
public static Long MEMORY_SWAP_TOTAL = memory != null ? memory.getSwapTotal() / 1048576 : null;
public Long MEMORY_SWAP_TOTAL = memory != null ? memory.getSwapTotal() / 1048576 : null;

/**
* Used Swap Memory in Megabytes(MB)
*/
public static Long MEMORY_SWAP_USED = memory != null ? memory.getSwapUsed() / 1048576 : null;
public Long MEMORY_SWAP_USED = memory != null ? memory.getSwapUsed() / 1048576 : null;

/**
* Free Swap Memory in Megabytes(MB)
*/
public static Long MEMORY_SWAP_FREE = memory != null ? (memory.getSwapTotal() - memory.getSwapUsed()) / 1048576
: null;
public Long MEMORY_SWAP_FREE = memory != null ? (memory.getSwapTotal() - memory.getSwapUsed()) / 1048576 : null;

/**
* CPU Voltage in Volts (V)
*/
public static Double CPU_VOLTAGE = /*s.getCpuVoltage()*/null;
public Double CPU_VOLTAGE = /* s.getCpuVoltage() */null;

/**
* CPU Temperature in Degrees celsius (°C)
*/
public static Double CPU_TEMPERATURE = /*s.getCpuTemperature()*/null;
public Double CPU_TEMPERATURE = /* s.getCpuTemperature() */null;

public static int[] FAN_SPEED = /*s.getFanSpeeds()*/null;
public int[] FAN_SPEED = /* s.getFanSpeeds() */null;

public static String OS_FAMILY = os != null ? os.getFamily() : "";
public String OS_FAMILY = os != null ? os.getFamily() : "";

public static String OS_MANUFACTURER = os != null ? os.getManufacturer() : "";
public String OS_MANUFACTURER = os != null ? os.getManufacturer() : "";

public static String OS_VERSION_NAME = version != null ? version.getCodeName() : System.getProperty("os.version");
public String OS_VERSION_NAME = version != null ? version.getCodeName() : System.getProperty("os.version");

public static String OS_VERSION_BUILDNUMBER = version.getBuildNumber();
public String OS_VERSION_BUILDNUMBER = version != null ? version.getBuildNumber() : "";

public static String OS_VERSION_NUMBER = version != null ? version.getVersion() : System.getProperty("os.name");
public String OS_VERSION_NUMBER = version != null ? version.getVersion() : System.getProperty("os.name");

/**
* Time from when System started in minutes
*/
public static Long PROCESSOR_SYSTEM_UPTIME = p != null ? p.getSystemUptime() / 60
public Long PROCESSOR_SYSTEM_UPTIME = p != null ? p.getSystemUptime() / 60
: ManagementFactory.getRuntimeMXBean().getUptime() / 60;

public static String getHostName() {
public String getHostName() {
try {
return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
Expand All @@ -126,7 +127,7 @@ public static String getHostName() {
return null;
}

private static OperatingSystem getOperatingSystem() {
private OperatingSystem getOperatingSystem() {
OperatingSystem os = null;

try {
Expand All @@ -137,7 +138,7 @@ private static OperatingSystem getOperatingSystem() {
return os;
}

private static GlobalMemory getMemory() {
private GlobalMemory getMemory() {
GlobalMemory memory = null;
try {
memory = hal.getMemory();
Expand All @@ -147,7 +148,7 @@ private static GlobalMemory getMemory() {
return memory;
}

public static String getIpAddress() throws SocketException, UnknownHostException {
public String getIpAddress() throws SocketException, UnknownHostException {
try {
@SuppressWarnings("static-access")
String publicIp = new CurlEmulator().sendNormalHtmlGET("http://ipinfo.io/ip");
Expand All @@ -161,39 +162,48 @@ public static String getIpAddress() throws SocketException, UnknownHostException
return InetAddress.getLocalHost().getHostAddress();
}

public static JSONArray getNetworkInformation() {
JSONArray json = new JSONArray();

for (NetworkIF net : si.getHardware().getNetworkIFs()) {
JSONObject js = new JSONObject();
public JSONArray getNetworkInformation() {
JSONArray json = null;

if (net != null) {
js.put("name", net.getDisplayName());
js.put("macAddress", net.getMacaddr());
js.put("speed", net.getSpeed());
js.put("packetsReceived", net.getPacketsRecv());
js.put("packetsSent", net.getPacketsSent());
js.put("mtu", net.getMTU());
json.put(js);
try {
for (NetworkIF net : si.getHardware().getNetworkIFs()) {
json = new JSONArray();
JSONObject js = new JSONObject();

if (net != null) {
js.put("name", net.getDisplayName());
js.put("macAddress", net.getMacaddr());
js.put("speed", net.getSpeed());
js.put("packetsReceived", net.getPacketsRecv());
js.put("packetsSent", net.getPacketsSent());
js.put("mtu", net.getMTU());
json.put(js);
}
}
} catch (NoClassDefFoundError e) {
e.printStackTrace();
}
return json;
}

public static String getMacAddress() {
String macAdd = null;
public String getMacAddress() {
String macAdd = "";

JSONArray networkInformation = getNetworkInformation();

for (int i = 0; i < getNetworkInformation().length(); i++) {
if (getNetworkInformation().getJSONObject(i) != null
&& StringUtils.isNotBlank(getNetworkInformation().getJSONObject(i).getString("macAddress"))) {
macAdd = getNetworkInformation().getJSONObject(i).getString("macAddress");
break;
if (networkInformation != null) {
for (int i = 0; i < networkInformation.length(); i++) {
if (networkInformation.getJSONObject(i) != null
&& StringUtils.isNotBlank(networkInformation.getJSONObject(i).getString("macAddress"))) {
macAdd = networkInformation.getJSONObject(i).getString("macAddress");
break;
}
}
}
return macAdd;
}

public static JSONArray getDisksInformation() {
public JSONArray getDisksInformation() {
JSONArray json = new JSONArray();

for (HWDiskStore disk : si.getHardware().getDiskStores()) {
Expand All @@ -210,7 +220,7 @@ public static JSONArray getDisksInformation() {
return json;
}

public static JSONArray getPowerInformation() {
public JSONArray getPowerInformation() {
JSONArray json = new JSONArray();

for (PowerSource ps : psArr) {
Expand All @@ -226,7 +236,7 @@ public static JSONArray getPowerInformation() {
return json;
}

public static String getLinuxProcessorName() {
public String getLinuxProcessorName() {
if (p != null && "Linux".equals(System.getProperties().getProperty("os.name"))
&& StringUtils.isBlank(p.getName())) {
String[] cmds = { "/bin/sh", "-c", "cat /proc/cpuinfo | grep 'name' | uniq" };
Expand All @@ -237,7 +247,7 @@ public static String getLinuxProcessorName() {
}
}

private static CentralProcessor getCentralProcessor() {
private CentralProcessor getCentralProcessor() {
CentralProcessor p = null;
try {
p = si.getHardware().getProcessor();
Expand All @@ -246,13 +256,15 @@ private static CentralProcessor getCentralProcessor() {
// (x86)\Apache Software Foundation\Tomcat
// 6.0\temp\1472550968944.openmrs-lib-cache\systemmonitor\com\sun\jna\win32-x86\jnidispatch.dll:
// Can't find dependent libraries thrown on some Windows servers
e.printStackTrace();
// e.printStackTrace();
p = null;
} catch (NoClassDefFoundError e) {
p = null;
}
return p;
}

private static String executeCommand(String[] commands) {
private String executeCommand(String[] commands) {
StringBuffer output = new StringBuffer();

Process p;
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/resources/dhis-dataelementsMetadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
{
"lastUpdated": "2016-07-14T08:00:52.280+0000",
"created": "2016-07-11T09:06:52.731+0000",
"name": "Patient CD4 Count Test Results - Yesterday",
"name": "Patient CD4 Count Test Results - New",
"id": "QoIyYyc7Z36",
"href": "http://82.196.9.250:8080/api/dataElements/QoIyYyc7Z36"
},
Expand Down Expand Up @@ -184,7 +184,7 @@
{
"lastUpdated": "2016-07-14T08:01:07.195+0000",
"created": "2016-07-11T09:07:21.967+0000",
"name": "Patient Viral Load Test Results - Yesterday",
"name": "Patient Viral Load Test Results - New",
"id": "uaUc1zJbaEC",
"href": "http://82.196.9.250:8080/api/dataElements/uaUc1zJbaEC"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void test_hibernateCriteriaRestrictions() throws IOException {

@Test
public void testGetIp() throws SocketException, UnknownHostException {
System.out.println("IP ADDR: " + OSAndHardwareIndicators.getIpAddress());
System.out.println("IP ADDR: " + new OSAndHardwareIndicators().getIpAddress());
}

@Ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* @TODO Re-write a version of this library that supports lower java version
* instead of requiring 1.8
*/
@Ignore
public class TestOSHILibrary {

@Test
Expand Down Expand Up @@ -87,7 +88,7 @@ public void test_systemNetwork() throws IOException, UnknownHostException {
System.out.println("IP ADDRESS: " + InetAddress.getLocalHost().getHostAddress());
System.out.println("NETWORK SPEED: " + net.getSpeed());

String ipInfoUrl = "http://ipinfo.io/" + OSAndHardwareIndicators.getIpAddress();
String ipInfoUrl = "http://ipinfo.io/" + new OSAndHardwareIndicators().getIpAddress();
String googleIpInfoUrl = "http://ipinfo.io/8.8.8.8";
System.out.println("ipInfoUrl: " + ipInfoUrl);
System.out.println("CurlEmulator.get(googleIpInfoUrl): " + CurlEmulator.get(googleIpInfoUrl, null, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ public String getDataForClientPushing() {
? Context.getAdministrationService().getGlobalProperty(ConfigurableGlobalProperties.DHISAPI_URL)
+ SystemMonitorConstants.DHIS_API_DATAVALUES_URL
: "";
String systemId = OSAndHardwareIndicators.getHostName() + "-" + (OSAndHardwareIndicators.getMacAddress() != null
? OSAndHardwareIndicators.getMacAddress().replace(":", "") : "");
OSAndHardwareIndicators osshi = new OSAndHardwareIndicators();

String systemId = osshi.getHostName() + "-" + (osshi.getMacAddress() != null
? osshi.getMacAddress().replace(":", "") : "");
JSONObject allDataValues = prepareClientMonitoredData();
JSONObject allDHISValuesJSON = new JSONObject();

Expand Down

0 comments on commit 305aabd

Please sign in to comment.