Skip to content

Commit

Permalink
Working on actuator info
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Delporte committed Jun 11, 2024
1 parent 1d14818 commit 6c254de
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
package com.pi4j.spring.boot;

import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

public class ContextConditions extends AnyNestedCondition {

public ContextConditions() {
super(ConfigurationPhase.REGISTER_BEAN);
}

/**
* TODO are these still needed? Can't we use Pi4jActuatorConfiguration.boardInfo ?
*/
@ConditionalOnProperty(prefix = "os", name = "arch", havingValue = "armv6l")
static class Armv6l {
}

@ConditionalOnProperty(prefix = "os", name = "arch", havingValue = "armv7l")
static class Armv7l {
}

@ConditionalOnProperty(prefix = "os", name = "arch", havingValue = "armv8l")
static class Armv8l {
}

@ConditionalOnProperty(prefix = "os", name = "arch", havingValue = "aarch64")
static class Aarch64 {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,20 @@ public void contribute(Builder builder) {
builder.withDetail("os.architecture", os.getArchitecture());
builder.withDetail("os.version", os.getVersion());
builder.withDetail("os.architecture", os.getArchitecture());

var boardModel = boardInfo.getBoardModel();
builder.withDetail("board.name", boardModel.getName());
builder.withDetail("board.description", boardModel.getLabel());
builder.withDetail("board.model.label", boardModel.getModel().getLabel());
builder.withDetail("board.cpu.label", boardModel.getCpu().getLabel());
builder.withDetail("board.soc", boardModel.getSoc().name());

var java = boardInfo.getJavaInfo();
builder.withDetail("java.version", java.getVersion());
builder.withDetail("java.runtime", java.getRuntime());
builder.withDetail("java.vendor", java.getVendor());
builder.withDetail("java.vendor.version", java.getVendorVersion());

var boardReading = BoardInfoHelper.getBoardReading();
builder.withDetail("reading.volt.value", boardReading.getVoltValue());
builder.withDetail("reading.temperature.celsius", boardReading.getTemperatureInCelsius());
Expand All @@ -56,26 +59,50 @@ public void contribute(Builder builder) {

try {
// TODO https://github.com/Pi4J/pi4j-springboot/issues/11
//builder.withDetail("pi4jPlatforms", context.platforms().all());
builder.withDetail("platform.name", context.platform().name());
builder.withDetail("platform.value", context.platform().describe().value().toString());
} catch (Exception ex) {
logger.error("Could not return the Pi4J Platforms: {}", ex.getMessage());
logger.error("Could not return the Pi4J Default Platform: {}", ex.getMessage());
}

try {
// TODO https://github.com/Pi4J/pi4j-springboot/issues/11
//builder.withDetail("pi4jDefaultPlatform", context.platform());
for (var entry : context.platforms().all().entrySet()) {
builder.withDetail("platform." + getAsKeyName(entry.getKey()) + ".name", entry.getValue().name());
builder.withDetail("platform." + getAsKeyName(entry.getKey()) + ".description", entry.getValue().description());
builder.withDetail("platform." + getAsKeyName(entry.getKey()) + ".value", entry.getValue().describe().value().toString());
}
} catch (Exception ex) {
logger.error("Could not return the Pi4J Default Platform: {}", ex.getMessage());
logger.error("Could not return the Pi4J Platforms: {}", ex.getMessage());
}

try {
// TODO https://github.com/Pi4J/pi4j-springboot/issues/11
//builder.withDetail("pi4jProviders", context.providers().all());
for (var entry : context.providers().all().entrySet()) {
builder.withDetail("provider." + getAsKeyName(entry.getKey()) + ".name", entry.getValue().name());
builder.withDetail("provider." + getAsKeyName(entry.getKey()) + ".description", entry.getValue().description());
builder.withDetail("provider." + getAsKeyName(entry.getKey()) + ".type.name", entry.getValue().type().name());
}
} catch (Exception ex) {
logger.error("Could not return the Pi4J Providers: {}", ex.getMessage());
}

try {
builder.withDetail("pi4jRegistry", context.registry().all());
for (var entry : context.registry().all().entrySet()) {
builder.withDetail("registry." + getAsKeyName(entry.getKey()) + ".name", entry.getValue().name());
builder.withDetail("registry." + getAsKeyName(entry.getKey()) + ".config.name", entry.getValue().config().name());
builder.withDetail("registry." + getAsKeyName(entry.getKey()) + ".config.name", entry.getValue().config().platform());
builder.withDetail("registry." + getAsKeyName(entry.getKey()) + ".config.provider", entry.getValue().config().provider());
builder.withDetail("registry." + getAsKeyName(entry.getKey()) + ".type.name", entry.getValue().type().name());
builder.withDetail("registry." + getAsKeyName(entry.getKey()) + ".description", entry.getValue().description());
builder.withDetail("registry." + getAsKeyName(entry.getKey()) + ".value", entry.getValue().describe().value().toString());
}
} catch (Exception ex) {
logger.error("Could not return the Pi4J Registry: {}", ex.getMessage());
}
}

private String getAsKeyName(String key) {
return key.toLowerCase().trim().replace(" ", "-");
}
}

0 comments on commit 6c254de

Please sign in to comment.