-
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.
Merge pull request #23 from logchange/os-java-info
Added os and java information
- Loading branch information
Showing
19 changed files
with
510 additions
and
23 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
title: Added new metric `hofund_os_info` with information about name, version arch of the os running application. | ||
authors: | ||
- name: Peter Zmilczak | ||
nick: marwin1991 | ||
url: https://github.com/marwin1991 | ||
type: added #[added/changed/deprecated/removed/fixed/security/other] | ||
issues: | ||
- 22 | ||
merge_requests: | ||
- 23 |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
title: Added new metric `hofund_java_info` with information about version, vendor and jvm which is running application. | ||
authors: | ||
- name: Peter Zmilczak | ||
nick: marwin1991 | ||
url: https://github.com/marwin1991 | ||
type: added #[added/changed/deprecated/removed/fixed/security/other] | ||
issues: | ||
- 22 | ||
merge_requests: | ||
- 23 |
75 changes: 75 additions & 0 deletions
75
hofund-core/src/main/java/dev/logchange/hofund/java/HofundJavaInfo.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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package dev.logchange.hofund.java; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@Builder(access = AccessLevel.PRIVATE) | ||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class HofundJavaInfo { | ||
private final String version; | ||
|
||
private final JavaVendorInfo vendor; | ||
|
||
private final JavaRuntimeEnvironmentInfo runtime; | ||
|
||
private final JavaVirtualMachineInfo jvm; | ||
|
||
public static HofundJavaInfo get() { | ||
return HofundJavaInfo.builder() | ||
.version(System.getProperty("java.version")) | ||
.vendor(new JavaVendorInfo()) | ||
.runtime(new JavaRuntimeEnvironmentInfo()) | ||
.jvm(new JavaVirtualMachineInfo()) | ||
.build(); | ||
} | ||
|
||
|
||
|
||
|
||
@Getter | ||
public static class JavaVendorInfo { | ||
|
||
private final String name; | ||
|
||
private final String version; | ||
|
||
public JavaVendorInfo() { | ||
this.name = System.getProperty("java.vendor"); | ||
this.version = System.getProperty("java.vendor.version"); | ||
} | ||
} | ||
|
||
@Getter | ||
public static class JavaRuntimeEnvironmentInfo { | ||
|
||
private final String name; | ||
|
||
private final String version; | ||
|
||
public JavaRuntimeEnvironmentInfo() { | ||
this.name = System.getProperty("java.runtime.name"); | ||
this.version = System.getProperty("java.runtime.version"); | ||
} | ||
} | ||
|
||
@Getter | ||
public static class JavaVirtualMachineInfo { | ||
|
||
private final String name; | ||
|
||
private final String vendor; | ||
|
||
private final String version; | ||
|
||
public JavaVirtualMachineInfo() { | ||
this.name = System.getProperty("java.vm.name"); | ||
this.vendor = System.getProperty("java.vm.vendor"); | ||
this.version = System.getProperty("java.vm.version"); | ||
} | ||
} | ||
|
||
} | ||
|
56 changes: 56 additions & 0 deletions
56
hofund-core/src/main/java/dev/logchange/hofund/java/HofundJavaInfoMeter.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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class HofundJavaInfoMeter implements MeterBinder { | ||
|
||
private static final String NAME = "hofund_java_info"; | ||
private static final String DESCRIPTION = "Basic information about java that is running this application"; | ||
|
||
private final HofundJavaInfo info; | ||
private final AtomicInteger atomicInteger; | ||
|
||
public HofundJavaInfoMeter() { | ||
this.info = HofundJavaInfo.get(); | ||
this.atomicInteger = new AtomicInteger(1); | ||
} | ||
|
||
@Override | ||
public void bindTo(MeterRegistry meterRegistry) { | ||
Gauge.builder(NAME, atomicInteger, AtomicInteger::doubleValue) | ||
.description(DESCRIPTION) | ||
.tags(tags()) | ||
.register(meterRegistry); | ||
} | ||
|
||
private List<Tag> tags() { | ||
List<Tag> tags = new LinkedList<>(); | ||
|
||
tags.add(Tag.of("version", info.getVersion())); | ||
|
||
tags.add(Tag.of("vendor_name", info.getVendor().getName())); | ||
tags.add(Tag.of("vendor_version", info.getVendor().getVersion())); | ||
|
||
tags.add(Tag.of("runtime_name", info.getRuntime().getName())); | ||
tags.add(Tag.of("runtime_version", info.getRuntime().getVersion())); | ||
|
||
tags.add(Tag.of("jvm_name", info.getJvm().getName())); | ||
tags.add(Tag.of("jvm_vendor", info.getJvm().getVendor())); | ||
tags.add(Tag.of("jvm_version", info.getJvm().getVersion())); | ||
|
||
Collections.reverse(tags); | ||
|
||
return tags; | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
hofund-core/src/main/java/dev/logchange/hofund/os/HofundOsInfo.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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package dev.logchange.hofund.os; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder(access = AccessLevel.PRIVATE) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class HofundOsInfo { | ||
|
||
private final String name; | ||
|
||
private final String version; | ||
|
||
private final String arch; | ||
|
||
public static HofundOsInfo get() { | ||
String name = System.getProperty("os.name"); | ||
String version = System.getProperty("os.version"); | ||
String arch = System.getProperty("os.arch"); | ||
return HofundOsInfo.builder() | ||
.name(name) | ||
.version(version) | ||
.arch(arch) | ||
.build(); | ||
} | ||
|
||
} | ||
|
44 changes: 44 additions & 0 deletions
44
hofund-core/src/main/java/dev/logchange/hofund/os/HofundOsInfoMeter.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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package dev.logchange.hofund.os; | ||
|
||
import dev.logchange.hofund.git.HofundGitInfoProvider; | ||
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.LinkedList; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class HofundOsInfoMeter implements MeterBinder { | ||
|
||
private static final String NAME = "hofund_os_info"; | ||
private static final String DESCRIPTION = "Basic information about operating system that is running this application"; | ||
|
||
private final HofundOsInfo info; | ||
private final AtomicInteger atomicInteger; | ||
|
||
public HofundOsInfoMeter() { | ||
this.info = HofundOsInfo.get(); | ||
this.atomicInteger = new AtomicInteger(1); | ||
} | ||
|
||
@Override | ||
public void bindTo(MeterRegistry meterRegistry) { | ||
Gauge.builder(NAME, atomicInteger, AtomicInteger::doubleValue) | ||
.description(DESCRIPTION) | ||
.tags(tags()) | ||
.register(meterRegistry); | ||
} | ||
|
||
private List<Tag> tags() { | ||
List<Tag> tags = new LinkedList<>(); | ||
|
||
tags.add(Tag.of("name", info.getName())); | ||
tags.add(Tag.of("version", info.getVersion())); | ||
tags.add(Tag.of("arch", info.getArch())); | ||
|
||
return tags; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...a/dev/logchange/hofund/java/springboot/autoconfigure/HofundJavaInfoAutoConfiguration.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package dev.logchange.hofund.java.springboot.autoconfigure; | ||
|
||
import dev.logchange.hofund.java.HofundJavaInfoMeter; | ||
import dev.logchange.hofund.os.HofundOsInfoMeter; | ||
import io.micrometer.prometheus.PrometheusMeterRegistry; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@RequiredArgsConstructor | ||
@Configuration(proxyBeanMethods = false) | ||
//available since spring boot 2.4.0 | ||
//@ConditionalOnEnabledMetricsExport(value="prometheus") | ||
@ConditionalOnClass(PrometheusMeterRegistry.class) | ||
public class HofundJavaInfoAutoConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public HofundJavaInfoMeter hofundJavaInfoMeter() { | ||
return new HofundJavaInfoMeter(); | ||
} | ||
|
||
|
||
} |
29 changes: 29 additions & 0 deletions
29
.../java/dev/logchange/hofund/os/springboot/autoconfigure/HofundOsInfoAutoConfiguration.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package dev.logchange.hofund.os.springboot.autoconfigure; | ||
|
||
import dev.logchange.hofund.info.HofundInfoMeter; | ||
import dev.logchange.hofund.info.HofundInfoProvider; | ||
import dev.logchange.hofund.info.springboot.autoconfigure.HofundInfoProperties; | ||
import dev.logchange.hofund.os.HofundOsInfoMeter; | ||
import io.micrometer.prometheus.PrometheusMeterRegistry; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@RequiredArgsConstructor | ||
@Configuration(proxyBeanMethods = false) | ||
//available since spring boot 2.4.0 | ||
//@ConditionalOnEnabledMetricsExport(value="prometheus") | ||
@ConditionalOnClass(PrometheusMeterRegistry.class) | ||
public class HofundOsInfoAutoConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public HofundOsInfoMeter hofundOsInfoMeter() { | ||
return new HofundOsInfoMeter(); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.