Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,6 @@
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>6.6.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,26 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import oshi.SystemInfo;
import oshi.hardware.GlobalMemory;

/**
* Configuration for system metrics exposed to Prometheus through Spring Actuator.
* Prometheus ingests the metrics from Actuator through a Kubernetes object defined in the k8s-manifest.
*
* @see <a href= "https://github.com/Patina-Network/k8s-manifests/blob/main/base/production/codebloom/servicemonitor.yaml">Service Monitor</a>
*/
@Configuration
@EnableConfigurationProperties(CommitShaProperties.class)
public class SystemMetricsConfig {

@Bean
public SystemInfo systemInfo() {
return new SystemInfo();
}

/**
* Add commit sha to metrics so that the deployed version of the code being run on the instance is known.
*/
@Bean
public MeterBinder applicationInfoMetrics(CommitShaProperties commitShaProperties) {
return registry -> {
var tags = Tags.of(Tag.of("sha", commitShaProperties.getSha()));
registry.gauge("application.info", tags, 1, n -> 1.0);
};
}

@Bean
public MeterBinder systemMemoryMetrics(SystemInfo systemInfo) {
return registry -> {
GlobalMemory memory = systemInfo.getHardware().getMemory();
registry.gauge("system.info.memory.total", memory, GlobalMemory::getTotal);
registry.gauge("system.info.memory.available", memory, GlobalMemory::getAvailable);
registry.gauge("system.info.memory.used", memory, m -> m.getTotal() - m.getAvailable());
registry.gauge(
"system.info.memory.usage",
memory,
m -> (double) (m.getTotal() - m.getAvailable()) / m.getTotal() * 100);
};
}
}
Loading