Skip to content

Commit

Permalink
Merge pull request #23 from logchange/os-java-info
Browse files Browse the repository at this point in the history
Added os and java information
  • Loading branch information
marwin1991 authored Feb 16, 2024
2 parents 2b9e9c9 + 11b0244 commit 5f5c912
Show file tree
Hide file tree
Showing 19 changed files with 510 additions and 23 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 1.8
distribution: 'temurin'
java-version: 21

- name: Build with Maven
run: mvn --batch-mode package -DskipTests

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 1.8
distribution: 'temurin'
java-version: 21

- name: Test and Integration Test with Maven
run: mvn --batch-mode verify
run: mvn --batch-mode test

- name: Verify javadocs
run: mvn install -DskipTests && mvn javadoc:javadoc
2 changes: 1 addition & 1 deletion .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Test files
run: ls -l && ls -l ./changelog && echo "v${GITHUB_REF/refs\/tags\//}" && ls -l ./changelog/v${GITHUB_REF/refs\/tags\//}
- name: Check if file exissts
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/create-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
token: ${{ secrets.LOGCHANGE_PAT_TOKEN }}

- name: Set up JDK 1.8
uses: actions/setup-java@v1
- name: Set up JDK 21
uses: actions/setup-java@v4
if: "!contains(github.event.head_commit.message, 'Releasing new version')"
with:
java-version: 1.8
distribution: 'temurin'
java-version: 21
token: ${{ secrets.LOGCHANGE_PAT_TOKEN }}

- name: Release and Generate CHANGELOG
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Maven Central Repository
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: 1.8
distribution: 'temurin'
java-version: 21
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
Expand Down
10 changes: 10 additions & 0 deletions changelog/unreleased/000001-os-info.yml
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
10 changes: 10 additions & 0 deletions changelog/unreleased/000002-java-info.yml
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
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");
}
}

}

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;
}

}
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();
}

}

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;
}

}
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();
}


}
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();
}


}
Loading

0 comments on commit 5f5c912

Please sign in to comment.