View Javadoc
1   package com.guinetik.hexafun.examples.sysmon;
2   
3   /**
4    * Output port for retrieving system metrics.
5    *
6    * <p>This interface abstracts the source of system metrics, allowing
7    * the domain to remain independent of how metrics are obtained.
8    * Implementations can read from the real OS, return mock data, or
9    * fetch from remote monitoring systems.</p>
10   *
11   * <h2>Hexagonal Architecture Role</h2>
12   * <p>This is a <strong>driven port</strong> (output port) - the application
13   * core calls out to infrastructure through this interface.</p>
14   */
15  public interface MetricsProvider {
16  
17      /**
18       * Get current CPU usage percentage.
19       *
20       * @return CPU usage as percentage (0-100)
21       */
22      double getCpuUsage();
23  
24      /**
25       * Get current memory usage percentage.
26       *
27       * @return Memory usage as percentage (0-100)
28       */
29      double getMemoryUsage();
30  
31      /**
32       * Get current disk usage percentage.
33       *
34       * @return Disk usage as percentage (0-100)
35       */
36      double getDiskUsage();
37  
38      /**
39       * Get all system metrics at once.
40       *
41       * <p>Default implementation calls individual methods, but implementations
42       * may override for efficiency (e.g., single OS call).</p>
43       *
44       * @return SystemMetrics containing all current values
45       */
46      default SystemMetrics getAllMetrics() {
47          return new SystemMetrics(getCpuUsage(), getMemoryUsage(), getDiskUsage());
48      }
49  }