Skip to content

Commit ad5fbe2

Browse files
committedSep 26, 2016
Initial commit
0 parents  commit ad5fbe2

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed
 

‎.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

‎.gitignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Build files
2+
*.class
3+
build/
4+
target/
5+
6+
# IDE files
7+
*.iml
8+
.idea/
9+
.settings/
10+
.classpath
11+
.project
12+
13+
# Package Files
14+
*.jar
15+
16+
# Virtual machine crash logs
17+
hs_err_pid*
18+
19+
# MacOSX files
20+
.DS_Store
21+

‎pom.xml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<artifactId>c2mon-daq-parent</artifactId>
9+
<groupId>cern.c2mon.daq</groupId>
10+
<version>1.8.0-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>c2mon-daq-hostmetrics</artifactId>
14+
<version>0.0.1-SNAPSHOT</version>
15+
16+
<dependencies>
17+
<!-- C2MON dependencies -->
18+
<dependency>
19+
<groupId>cern.c2mon.daq</groupId>
20+
<artifactId>c2mon-daq-core</artifactId>
21+
</dependency>
22+
23+
<!-- 3rd party dependencies -->
24+
<dependency>
25+
<groupId>com.github.dblock</groupId>
26+
<artifactId>oshi-core</artifactId>
27+
<version>3.2</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.projectlombok</groupId>
31+
<artifactId>lombok</artifactId>
32+
</dependency>
33+
</dependencies>
34+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package cern.c2mon.daq.hostmetrics;
2+
3+
import cern.c2mon.daq.common.EquipmentMessageHandler;
4+
import cern.c2mon.daq.common.IEquipmentMessageSender;
5+
import cern.c2mon.daq.tools.equipmentexceptions.EqIOException;
6+
import cern.c2mon.shared.common.datatag.ValueUpdate;
7+
import lombok.extern.slf4j.Slf4j;
8+
import oshi.SystemInfo;
9+
import oshi.hardware.HardwareAbstractionLayer;
10+
11+
import java.util.concurrent.Executors;
12+
13+
import static java.util.concurrent.TimeUnit.SECONDS;
14+
15+
/**
16+
* Simple {@link EquipmentMessageHandler} implementation that uses the OSHI
17+
* library to publish metrics about the current host.
18+
*
19+
* @author Justin Lewis Salmon
20+
*/
21+
@Slf4j
22+
public class HostMetricsMessageHandler extends EquipmentMessageHandler {
23+
24+
@Override
25+
public void connectToDataSource() throws EqIOException {
26+
IEquipmentMessageSender sender = getEquipmentMessageSender();
27+
sender.confirmEquipmentStateOK();
28+
29+
HardwareAbstractionLayer hal = new SystemInfo().getHardware();
30+
31+
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> {
32+
sender.update("mem.avail", new ValueUpdate(hal.getMemory().getAvailable()));
33+
sender.update("mem.swap.used", new ValueUpdate(hal.getMemory().getSwapUsed()));
34+
sender.update("cpu.loadavg", new ValueUpdate(hal.getProcessor().getSystemLoadAverage()));
35+
}, 0, 1, SECONDS);
36+
}
37+
38+
@Override
39+
public void disconnectFromDataSource() throws EqIOException {}
40+
41+
@Override
42+
public void refreshAllDataTags() {}
43+
44+
@Override
45+
public void refreshDataTag(long dataTagId) {}
46+
}

0 commit comments

Comments
 (0)
Please sign in to comment.