-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use board info method merged into Pi4J V2 (snapshot)
- Loading branch information
Frank Delporte
committed
Apr 15, 2024
1 parent
93aa02b
commit 79ed866
Showing
10 changed files
with
77 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
/vite.generated.ts | ||
/SERVER_INSTALL.md | ||
/src/main/dev-bundle/ | ||
/src/main/bundles/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 12 additions & 46 deletions
58
src/main/java/com/pi4j/boardinfoservice/service/SystemInfoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,29 @@ | ||
package com.pi4j.boardinfoservice.service; | ||
|
||
import com.pi4j.boardinfo.model.DetectedBoard; | ||
import com.pi4j.boardinfo.util.BoardModelDetection; | ||
import com.pi4j.boardinfoservice.util.ExecUtil; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import com.pi4j.boardinfo.model.BoardInfo; | ||
import com.pi4j.boardinfo.model.BoardReading; | ||
import com.pi4j.boardinfo.model.JvmMemory; | ||
import com.pi4j.boardinfo.util.BoardInfoHelper; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Service | ||
public class SystemInfoService { | ||
|
||
private final Logger logger = LogManager.getLogger(SystemInfoService.class); | ||
private final DetectedBoard detectedBoard; | ||
private final BoardInfo boardInfo; | ||
|
||
public SystemInfoService() { | ||
detectedBoard = BoardModelDetection.getDetectedBoard(); | ||
} | ||
|
||
public DetectedBoard getDetectedBoard() { | ||
return detectedBoard; | ||
boardInfo = BoardInfoHelper.current(); | ||
} | ||
|
||
public Map<String, Object> getJvmMemory() { | ||
Map<String, Object> memory = new HashMap<>(); | ||
|
||
int mb = 1024 * 1024; | ||
Runtime instance = Runtime.getRuntime(); | ||
memory.put("total_mb", (instance.totalMemory() / mb)); | ||
memory.put("free_mb", (instance.freeMemory() / mb)); | ||
memory.put("used_mb", ((instance.totalMemory() - instance.freeMemory()) / mb)); | ||
memory.put("max_mb", (instance.maxMemory() / mb)); | ||
|
||
return memory; | ||
public BoardInfo getDetectedBoard() { | ||
return boardInfo; | ||
} | ||
|
||
public Map<String, Object> getBoardReadings() { | ||
Map<String, Object> boardVersion = new HashMap<>(); | ||
boardVersion.put("board", getCommandOutput("cat /proc/device-tree/model")); | ||
// https://raspberry-projects.com/pi/command-line/detect-rpi-hardware-version | ||
boardVersion.put("boardVersionCode", getCommandOutput("cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}'")); | ||
// https://linuxhint.com/commands-for-hardware-information-raspberry-pi/ | ||
boardVersion.put("temp", getCommandOutput("vcgencmd measure_temp")); | ||
boardVersion.put("uptimeInfo", getCommandOutput("uptime")); | ||
// https://linuxhint.com/find-hardware-information-raspberry-pi/ | ||
boardVersion.put("volt", getCommandOutput("vcgencmd measure_volts")); | ||
// https://www.baeldung.com/linux/total-physical-memory | ||
boardVersion.put("memory", getCommandOutput("cat /proc/meminfo | head -n 1")); | ||
return boardVersion; | ||
public JvmMemory getJvmMemory() { | ||
return BoardInfoHelper.getJvmMemory(); | ||
} | ||
|
||
private String getCommandOutput(String command) { | ||
ExecUtil execUtil = new ExecUtil(command); | ||
if (!execUtil.isFinished() || !execUtil.getErrorMessage().isEmpty()) { | ||
logger.error("Could not execute '{}': {}", command, execUtil.getErrorMessage()); | ||
return ""; | ||
} | ||
return execUtil.getOutputMessage(); | ||
public BoardReading getBoardReading() { | ||
return BoardInfoHelper.getBoardReading(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters