Skip to content

Commit

Permalink
Merge pull request #52 from witx98/031-os-metric
Browse files Browse the repository at this point in the history
Added more precise OS metrics
  • Loading branch information
marwin1991 authored Nov 19, 2024
2 parents 159d6f4 + b4c16a4 commit 3b04531
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 11 deletions.
10 changes: 10 additions & 0 deletions changelog/unreleased/000031-os-metric.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: Added more precise OS metrics
authors:
- name: Mateusz Witkowski
nick: witx98
url: https://github.com/witx98
type: added #[added/changed/deprecated/removed/fixed/security/other]
issues:
- 31
merge_requests:
- 52
6 changes: 6 additions & 0 deletions hofund-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>${oshi-core.version}</version>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package dev.logchange.hofund.java;

import dev.logchange.hofund.os.HofundOsInfo;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.binder.MeterBinder;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import oshi.SystemInfo;
import oshi.software.os.OperatingSystem;

@Getter
@Builder(access = AccessLevel.PRIVATE)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class HofundOsInfo {

private final String name;

private final String version;

private final String arch;
private final String manufacturer;

public static HofundOsInfo get() {
String name = System.getProperty("os.name");
String version = System.getProperty("os.version");
String arch = System.getProperty("os.arch");
SystemInfo systemInfo = new SystemInfo();
OperatingSystem os = systemInfo.getOperatingSystem();
return HofundOsInfo.builder()
.name(name)
.version(version)
.name(os.getFamily())
.version(os.getVersionInfo().toString())
.arch(arch)
.manufacturer(os.getManufacturer())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private List<Tag> tags() {
List<Tag> tags = new LinkedList<>();

tags.add(Tag.of("name", info.getName()));
tags.add(Tag.of("manufacturer", info.getManufacturer()));
tags.add(Tag.of("version", info.getVersion()));
tags.add(Tag.of("arch", info.getArch()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import oshi.SystemInfo;
import oshi.software.os.OperatingSystem;

@Slf4j
@AutoConfigureObservability
Expand All @@ -24,16 +26,20 @@ void shouldContainsHofundOsInfo() {
//given:
String path = "http://localhost:" + port + "/actuator/prometheus";

String name = System.getProperty("os.name");
String version = System.getProperty("os.version");
OperatingSystem os = new SystemInfo().getOperatingSystem();

String name = os.getFamily();
String manufacturer = os.getManufacturer();
String version = os.getVersionInfo().toString();
String arch = System.getProperty("os.arch");

String expected =
"# HELP hofund_os_info Basic information about operating system that is running this application\n" +
"# TYPE hofund_os_info gauge\n" +
"hofund_os_info{arch=\"{arch}\",name=\"{name}\",version=\"{version}\"} 1"
"hofund_os_info{arch=\"{arch}\",manufacturer=\"{manufacturer}\",name=\"{name}\",version=\"{version}\"} 1"
.replace("{arch}", arch)
.replace("{name}", name)
.replace("{manufacturer}", manufacturer)
.replace("{version}", version);

//when:
Expand Down
6 changes: 6 additions & 0 deletions hofund-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>${oshi-core.version}</version>
</dependency>
</dependencies>

</project>
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<spring-boot.version>3.3.1</spring-boot.version>
<oshi-core.version>6.6.5</oshi-core.version>

<!-- TESTS -->
<mockwebserver.version>4.12.0</mockwebserver.version>
Expand Down

0 comments on commit 3b04531

Please sign in to comment.