Skip to content

Commit

Permalink
Merge pull request #180 from sentrysoftware/feature/issue-172-add-har…
Browse files Browse the repository at this point in the history
…dware-module-back-to-metricshub

Issue #172: Added Hardware Module back to MetricsHub
  • Loading branch information
NassimBtk committed May 17, 2024
2 parents 24fbe90 + 45fdc84 commit 8d39dec
Show file tree
Hide file tree
Showing 85 changed files with 79,751 additions and 27 deletions.
7 changes: 7 additions & 0 deletions metricshub-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
<version>${project.version}</version>
</dependency>

<!-- MetricsHub Hardware -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>metricshub-hardware</artifactId>
<version>${project.version}</version>
</dependency>

<!-- MetricsHub Community Connectors -->
<dependency>
<groupId>org.sentrysoftware</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
import org.sentrysoftware.metricshub.engine.telemetry.Monitor;
import org.sentrysoftware.metricshub.engine.telemetry.TelemetryManager;
import org.sentrysoftware.metricshub.engine.telemetry.metric.AbstractMetric;
import org.sentrysoftware.metricshub.hardware.strategy.HardwarePostCollectStrategy;
import org.sentrysoftware.metricshub.hardware.strategy.HardwarePostDiscoveryStrategy;
import org.sentrysoftware.metricshub.hardware.strategy.HardwareStrategy;

/**
* Task responsible for running the monitoring process, including detection, discovery, and collection strategies.
Expand Down Expand Up @@ -107,7 +110,8 @@ public void run() {
telemetryManager.run(
new DetectionStrategy(telemetryManager, discoveryTime, clientsExecutor, extensionManager),
new DiscoveryStrategy(telemetryManager, discoveryTime, clientsExecutor, extensionManager),
new SimpleStrategy(telemetryManager, discoveryTime, clientsExecutor, extensionManager)
new SimpleStrategy(telemetryManager, discoveryTime, clientsExecutor, extensionManager),
new HardwarePostDiscoveryStrategy(telemetryManager, discoveryTime, clientsExecutor, extensionManager)
);

// Initialize the OpenTelemetry observers and LogEmitter after the discovery
Expand All @@ -124,9 +128,13 @@ public void run() {
new PrepareCollectStrategy(telemetryManager, collectTime, clientsExecutor, extensionManager),
new ProtocolHealthCheckStrategy(telemetryManager, collectTime, clientsExecutor, extensionManager),
new CollectStrategy(telemetryManager, collectTime, clientsExecutor, extensionManager),
new SimpleStrategy(telemetryManager, collectTime, clientsExecutor, extensionManager)
new SimpleStrategy(telemetryManager, collectTime, clientsExecutor, extensionManager),
new HardwarePostCollectStrategy(telemetryManager, collectTime, clientsExecutor, extensionManager)
);

// Run the hardware strategy
telemetryManager.run(new HardwareStrategy(telemetryManager, collectTime));

// Initialize metric observers
initAllObservers(telemetryManager);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
import org.sentrysoftware.metricshub.engine.strategy.simple.SimpleStrategy;
import org.sentrysoftware.metricshub.engine.telemetry.Monitor;
import org.sentrysoftware.metricshub.engine.telemetry.TelemetryManager;
import org.sentrysoftware.metricshub.hardware.strategy.HardwarePostCollectStrategy;
import org.sentrysoftware.metricshub.hardware.strategy.HardwarePostDiscoveryStrategy;
import org.sentrysoftware.metricshub.hardware.strategy.HardwareStrategy;
import picocli.CommandLine;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Command;
Expand All @@ -90,7 +93,8 @@
description = "This tool is the CLI version of the @|italic MetricsHub|@ engine. " +
"MetricsHub monitors diverse technologies, encompassing applications, servers, and devices, particularly those without readily available monitoring solutions.%n%n" +
"It natively leverages various system management protocols to discover the hardware components of a system " +
"and report their operational status.",
"and report their operational status.%n%n" +
"Additionally, MetricsHub measures the power consumption of the system, or makes an estimation if no power sensor is detected.",
parameterListHeading = "%n@|bold,underline Parameters|@:%n",
optionListHeading = "%n@|bold,underline Options|@:%n",
customSynopsis = {
Expand Down Expand Up @@ -338,6 +342,12 @@ public Integer call() throws Exception {
discoveryTime,
clientsExecutor,
CliExtensionManager.getExtensionManagerSingleton()
),
new HardwarePostDiscoveryStrategy(
telemetryManager,
discoveryTime,
clientsExecutor,
CliExtensionManager.getExtensionManagerSingleton()
)
);

Expand Down Expand Up @@ -383,9 +393,18 @@ public Integer call() throws Exception {
collectTime,
clientsExecutor,
CliExtensionManager.getExtensionManagerSingleton()
),
new HardwarePostCollectStrategy(
telemetryManager,
collectTime,
clientsExecutor,
CliExtensionManager.getExtensionManagerSingleton()
)
);

// Run the hardware strategy
telemetryManager.run(new HardwareStrategy(telemetryManager, collectTime));

// If iterations > 1, add a sleep time between iterations
if (i != iterations - 1 && sleepIteration > 0) {
printWriter.println(String.format("Pausing for %d seconds before the next iteration...", sleepIteration));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
import org.sentrysoftware.metricshub.engine.telemetry.metric.AbstractMetric;
import org.sentrysoftware.metricshub.engine.telemetry.metric.NumberMetric;
import org.sentrysoftware.metricshub.extension.snmp.SnmpConfiguration;
import org.sentrysoftware.metricshub.hardware.strategy.HardwarePostCollectStrategy;
import org.sentrysoftware.metricshub.hardware.strategy.HardwarePostDiscoveryStrategy;

@ExtendWith(MockitoExtension.class)
class MonitoringTaskTest {
Expand Down Expand Up @@ -150,13 +152,19 @@ void testRun() {
monitoringTask.run(); // Collect

verify(telemetryManagerMock, times(1))
.run(any(DetectionStrategy.class), any(DiscoveryStrategy.class), any(SimpleStrategy.class));
.run(
any(DetectionStrategy.class),
any(DiscoveryStrategy.class),
any(SimpleStrategy.class),
any(HardwarePostDiscoveryStrategy.class)
);
verify(telemetryManagerMock, times(4))
.run(
any(PrepareCollectStrategy.class),
any(ProtocolHealthCheckStrategy.class),
any(CollectStrategy.class),
any(SimpleStrategy.class)
any(SimpleStrategy.class),
any(HardwarePostCollectStrategy.class)
);
}
}
Expand Down
203 changes: 203 additions & 0 deletions metricshub-hardware/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.sentrysoftware</groupId>
<artifactId>metricshub-parent</artifactId>
<version>0.9.03-SNAPSHOT</version>
</parent>

<artifactId>metricshub-hardware</artifactId>

<name>MetricsHub Hardware Energy and Sustainability Module</name>
<description>MetricsHub Hardware Energy and Sustainability Post Processing Module</description>

<dependencies>
<!-- MetricsHub Engine -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>metricshub-engine</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.sentrysoftware</groupId>
<artifactId>metricshub-it-common</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.sentrysoftware</groupId>
<artifactId>metricshub-snmp-extension</artifactId>
<scope>test</scope>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.sentrysoftware</groupId>
<artifactId>metricshub-oscommand-extension</artifactId>
<scope>test</scope>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.snmp4j</groupId>
<artifactId>snmp4j-agent</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.snmp4j</groupId>
<artifactId>snmp4j</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>

<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>

<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>src/it/resources</directory>
</testResource>
</testResources>
<plugins>
<!-- surefire -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
<classpathDependencyExcludes>
<classpathDependencyExclude>org.apache.logging.log4j:log4j-slf4j-impl</classpathDependencyExclude>
</classpathDependencyExcludes>
</configuration>
</plugin>

<!-- jacoco -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.62</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
<configuration>
<excludes>
<!-- Exclude simple DTO, VO and POJO -->
</excludes>
</configuration>
</plugin>
<!-- build-helper-maven-plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/it/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<!-- failsafe -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<argLine>@{argLine}</argLine>
<includes>
<include>**/*IT.java</include>
</includes>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit 8d39dec

Please sign in to comment.