blob: 05914c4046959602210f445b96fed7401322d9ff (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.metricsproxy.service;
import ai.vespa.metricsproxy.core.MonitoringConfig;
import com.yahoo.container.di.componentgraph.Provider;
import java.time.Duration;
/**
* @author gjoranv
*/
public class SystemPollerProvider implements Provider<SystemPoller> {
private final SystemPoller poller;
/**
* @param services The list of VespaService instances to monitor for System metrics
* @param monitoringConfig The interval in seconds between each polling.
*/
public SystemPollerProvider (VespaServices services, MonitoringConfig monitoringConfig) {
if (runningOnLinux()) {
Duration interval = Duration.ofMinutes(monitoringConfig.intervalMinutes());
poller = new SystemPoller(services.getVespaServices(), interval);
poller.schedule(Duration.ofSeconds(5));
} else {
poller = null;
}
}
public void deconstruct() {
if (poller != null) poller.stop();
}
public SystemPoller get() {
if (poller == null) {
throw new IllegalStateException("System poller is only available on Linux, current OS is" + getOs());
}
return poller;
}
public static boolean runningOnLinux() {
return getOs().contains("nux");
}
private static String getOs() {
return System.getProperty("os.name");
}
}
|