More work on Linux network metrics.
This commit is contained in:
parent
9f8191d0e5
commit
e7560831e8
|
@ -4,8 +4,8 @@ plugins {
|
||||||
id "nebula.ospackage" version "8.5.6"
|
id "nebula.ospackage" version "8.5.6"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
|
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'groovy'
|
apply plugin: 'groovy'
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ subprojects {
|
||||||
}
|
}
|
||||||
annotationProcessor(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}")
|
annotationProcessor(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}")
|
||||||
implementation "org.slf4j:slf4j-api:${slf4jVersion}"
|
implementation "org.slf4j:slf4j-api:${slf4jVersion}"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
|
@ -32,9 +33,17 @@ subprojects {
|
||||||
'Plugin-Description': "${pluginDescription}"
|
'Plugin-Description': "${pluginDescription}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task copyJar(type: Copy, dependsOn:[jar]) {
|
task fatJar(type: Jar) {
|
||||||
|
duplicatesStrategy(DuplicatesStrategy.INCLUDE)
|
||||||
|
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
|
||||||
|
with jar
|
||||||
|
}
|
||||||
|
|
||||||
|
task copyJar(type: Copy, dependsOn:[fatJar]) {
|
||||||
from jar // here it automatically reads jar file produced from jar task
|
from jar // here it automatically reads jar file produced from jar task
|
||||||
into "../output/"
|
into "../output/"
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package sysmon.plugins.os_aix;
|
||||||
import org.pf4j.Extension;
|
import org.pf4j.Extension;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import oshi.SystemInfo;
|
||||||
|
import oshi.hardware.HardwareAbstractionLayer;
|
||||||
import sysmon.shared.Measurement;
|
import sysmon.shared.Measurement;
|
||||||
import sysmon.shared.MetricExtension;
|
import sysmon.shared.MetricExtension;
|
||||||
import sysmon.shared.MetricResult;
|
import sysmon.shared.MetricResult;
|
||||||
|
@ -11,11 +13,15 @@ import sysmon.shared.PluginHelper;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
@Extension
|
@Extension
|
||||||
public class AixDiskExtension implements MetricExtension {
|
public class AixDiskExtension implements MetricExtension {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(AixProcessorExtension.class);
|
private static final Logger log = LoggerFactory.getLogger(AixProcessorExtension.class);
|
||||||
|
|
||||||
|
private final SystemInfo systemInfo;
|
||||||
|
private final HardwareAbstractionLayer hardwareAbstractionLayer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSupported() {
|
public boolean isSupported() {
|
||||||
|
|
||||||
|
@ -32,6 +38,15 @@ public class AixDiskExtension implements MetricExtension {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public AixDiskExtension() {
|
||||||
|
|
||||||
|
systemInfo = new SystemInfo();
|
||||||
|
hardwareAbstractionLayer = systemInfo.getHardware();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "aix-disk";
|
return "aix-disk";
|
||||||
|
@ -50,6 +65,15 @@ public class AixDiskExtension implements MetricExtension {
|
||||||
@Override
|
@Override
|
||||||
public MetricResult getMetrics() {
|
public MetricResult getMetrics() {
|
||||||
|
|
||||||
|
long writeBytes = hardwareAbstractionLayer.getDiskStores().get(0).getWriteBytes();
|
||||||
|
log.warn(String.format("Disk 0 - Write Bytes: %d", writeBytes));
|
||||||
|
|
||||||
|
long readBytes = hardwareAbstractionLayer.getDiskStores().get(0).getReadBytes();
|
||||||
|
log.warn(String.format("Disk 0 - Read Bytes: %d", readBytes));
|
||||||
|
|
||||||
|
long memAvailable = hardwareAbstractionLayer.getMemory().getAvailable();
|
||||||
|
log.warn(String.format("Memory - Available: %d", memAvailable));
|
||||||
|
|
||||||
List<String> iostat = PluginHelper.executeCommand("iostat -d 1 1");
|
List<String> iostat = PluginHelper.executeCommand("iostat -d 1 1");
|
||||||
AixDiskStat diskStat = processCommandOutput(iostat);
|
AixDiskStat diskStat = processCommandOutput(iostat);
|
||||||
|
|
||||||
|
|
|
@ -49,25 +49,25 @@ public class LinuxDiskProcLine {
|
||||||
== =====================================
|
== =====================================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private Long readsCompleted = 0L; // successfully
|
private long readsCompleted; // successfully
|
||||||
//private Long readsMerged = 0L;
|
//private long readsMerged;
|
||||||
private Long sectorsRead = 0L; // 512 bytes pr. sector
|
private long sectorsRead; // 512 bytes pr. sector
|
||||||
private Long timeSpentReading = 0L; // ms
|
private long timeSpentReading; // ms
|
||||||
private Long writesCompleted = 0L; // successfully
|
private long writesCompleted; // successfully
|
||||||
//private Long writesMerged = 0L;
|
//private long writesMerged;
|
||||||
private Long sectorsWritten = 0L; // 512 bytes pr. sector
|
private long sectorsWritten; // 512 bytes pr. sector
|
||||||
private Long timeSpentWriting = 0L; // ms
|
private long timeSpentWriting; // ms
|
||||||
//private Long ioInProgress = 0L;
|
//private long ioInProgress;
|
||||||
private Long timeSpentOnIo = 0L; // ms
|
private long timeSpentOnIo; // ms
|
||||||
//private Long timeSpentOnIoWeighted = 0L;
|
//private long timeSpentOnIoWeighted;
|
||||||
|
|
||||||
//private Long discardsCompleted = 0L; // successfully
|
//private long discardsCompleted; // successfully
|
||||||
//private Long discardsMerged = 0L;
|
//private long discardsMerged;
|
||||||
//private Long sectorsDiscarded = 0L; // 512 bytes pr. sector
|
//private long sectorsDiscarded; // 512 bytes pr. sector
|
||||||
//private Long timeSpentDiscarding = 0L; // ms
|
//private long timeSpentDiscarding; // ms
|
||||||
|
|
||||||
//private Long flushRequestsCompleted = 0L;
|
//private long flushRequestsCompleted;
|
||||||
//private Long timeSpentFlushing = 0L; // ms
|
//private long timeSpentFlushing; // ms
|
||||||
|
|
||||||
|
|
||||||
public LinuxDiskProcLine(List<String> procLines) {
|
public LinuxDiskProcLine(List<String> procLines) {
|
||||||
|
|
|
@ -1,90 +0,0 @@
|
||||||
package sysmon.plugins.os_linux;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class LinuxNetworkDevProcLine {
|
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(LinuxNetworkDevProcLine.class);
|
|
||||||
|
|
||||||
private static final Pattern pattern1 = Pattern.compile("^\\s+([a-z]{2,}[0-9]+):.*");
|
|
||||||
private static final Pattern pattern2 = Pattern.compile("^\\s+([a-z]{2,}[0-9]+):\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)");
|
|
||||||
|
|
||||||
private long rxBytes;
|
|
||||||
private long rxPackets;
|
|
||||||
private long rxErrs;
|
|
||||||
|
|
||||||
private long txBytes;
|
|
||||||
private long txPackets;
|
|
||||||
private long txErrs;
|
|
||||||
|
|
||||||
/*
|
|
||||||
Inter-| Receive | Transmit
|
|
||||||
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
|
|
||||||
env2: 657010764 483686 0 0 0 0 0 0 55416850 431020 0 0 0 0 0 0
|
|
||||||
env3: 6900272 41836 0 0 0 0 0 0 7667444 41849 0 0 0 0 0 0
|
|
||||||
lo: 3098805 14393 0 0 0 0 0 0 3098805 14393 0 0 0 0 0 0
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
public LinuxNetworkDevProcLine(List<String> procLines) {
|
|
||||||
|
|
||||||
Matcher matcher1;
|
|
||||||
Matcher matcher2;
|
|
||||||
for(String procLine : procLines) {
|
|
||||||
|
|
||||||
matcher1 = pattern1.matcher(procLine);
|
|
||||||
if(matcher1.matches()) {
|
|
||||||
|
|
||||||
if(matcher1.group(1).equals("lo")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
matcher2 = pattern2.matcher(procLine);
|
|
||||||
if(matcher2.matches() && matcher2.groupCount() == 17) {
|
|
||||||
|
|
||||||
rxBytes += Long.parseLong(matcher2.group(2));
|
|
||||||
rxPackets += Long.parseLong(matcher2.group(3));
|
|
||||||
rxErrs += Long.parseLong(matcher2.group(4));
|
|
||||||
|
|
||||||
txBytes += Long.parseLong(matcher2.group(10));
|
|
||||||
txPackets += Long.parseLong(matcher2.group(11));
|
|
||||||
txErrs += Long.parseLong(matcher2.group(12));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public long getRxBytes() {
|
|
||||||
return rxBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getRxPackets() {
|
|
||||||
return rxPackets;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getRxErrs() {
|
|
||||||
return rxErrs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTxBytes() {
|
|
||||||
return txBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTxPackets() {
|
|
||||||
return txPackets;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTxErrs() {
|
|
||||||
return txErrs;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,21 +1,91 @@
|
||||||
package sysmon.plugins.os_linux;
|
package sysmon.plugins.os_linux;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class LinuxNetworkDevStat {
|
public class LinuxNetworkDevStat {
|
||||||
|
|
||||||
private final long rxBytes;
|
private static final Logger log = LoggerFactory.getLogger(LinuxNetworkDevStat.class);
|
||||||
private final long rxPackets;
|
|
||||||
private final long txBytes;
|
private static final Pattern pattern1 = Pattern.compile("^\\s+([a-z]{2,}[0-9]+):.*");
|
||||||
private final long txPackets;
|
private static final Pattern pattern2 = Pattern.compile("^\\s+([a-z]{2,}[0-9]+):\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)");
|
||||||
|
|
||||||
|
private long rxBytes;
|
||||||
|
private long rxPackets;
|
||||||
|
private long rxErrs;
|
||||||
|
|
||||||
|
private long txBytes;
|
||||||
|
private long txPackets;
|
||||||
|
private long txErrs;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Inter-| Receive | Transmit
|
||||||
|
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
|
||||||
|
env2: 657010764 483686 0 0 0 0 0 0 55416850 431020 0 0 0 0 0 0
|
||||||
|
env3: 6900272 41836 0 0 0 0 0 0 7667444 41849 0 0 0 0 0 0
|
||||||
|
lo: 3098805 14393 0 0 0 0 0 0 3098805 14393 0 0 0 0 0 0
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
public LinuxNetworkDevStat(List<String> procLines) {
|
||||||
|
|
||||||
|
Matcher matcher1;
|
||||||
|
Matcher matcher2;
|
||||||
|
for(String procLine : procLines) {
|
||||||
|
|
||||||
|
matcher1 = pattern1.matcher(procLine);
|
||||||
|
if(matcher1.matches()) {
|
||||||
|
|
||||||
|
if(matcher1.group(1).equals("lo")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
matcher2 = pattern2.matcher(procLine);
|
||||||
|
if(matcher2.matches() && matcher2.groupCount() == 17) {
|
||||||
|
|
||||||
|
rxBytes += Long.parseLong(matcher2.group(2));
|
||||||
|
rxPackets += Long.parseLong(matcher2.group(3));
|
||||||
|
rxErrs += Long.parseLong(matcher2.group(4));
|
||||||
|
|
||||||
|
txBytes += Long.parseLong(matcher2.group(10));
|
||||||
|
txPackets += Long.parseLong(matcher2.group(11));
|
||||||
|
txErrs += Long.parseLong(matcher2.group(12));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public LinuxNetworkDevStat(LinuxNetworkDevProcLine previous, LinuxNetworkDevProcLine current) {
|
public long getRxBytes() {
|
||||||
rxBytes = current.getRxBytes() - previous.getRxBytes();
|
return rxBytes;
|
||||||
rxPackets = current.getRxPackets() - previous.getRxPackets();
|
}
|
||||||
txBytes = current.getTxBytes() - previous.getTxBytes();
|
|
||||||
txPackets = current.getTxPackets() - previous.getTxPackets();
|
public long getRxPackets() {
|
||||||
|
return rxPackets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getRxErrs() {
|
||||||
|
return rxErrs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTxBytes() {
|
||||||
|
return txBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTxPackets() {
|
||||||
|
return txPackets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTxErrs() {
|
||||||
|
return txErrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,5 +102,4 @@ public class LinuxNetworkDevStat {
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,23 +45,12 @@ public class LinuxNetworkExtension implements MetricExtension {
|
||||||
@Override
|
@Override
|
||||||
public MetricResult getMetrics() {
|
public MetricResult getMetrics() {
|
||||||
|
|
||||||
// LinuxNetworkDevStat = 2 x reading from /proc/net/dev ?
|
LinuxNetworkSockStat sockStat = processSockOutput(PluginHelper.readFile("/proc/net/sockstat"));
|
||||||
LinuxNetworkDevProcLine proc1 = processDevOutput(PluginHelper.readFile("/proc/net/dev"));
|
LinuxNetworkDevStat devStat = processDevOutput(PluginHelper.readFile("/proc/net/dev"));
|
||||||
try {
|
|
||||||
Thread.sleep(1 * 1000); // TODO: Configure sample collect time
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
log.warn("getMetrics() - sleep interrupted");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
LinuxNetworkDevProcLine proc2 = processDevOutput(PluginHelper.readFile("/proc/net/dev"));
|
|
||||||
|
|
||||||
// LinuxNetworkSockStat = 1 x reading from /proc/net/sockstats
|
|
||||||
LinuxNetworkSockStat stat = processSockOutput(PluginHelper.readFile("/proc/net/sockstat"));
|
|
||||||
|
|
||||||
|
|
||||||
Map<String, String> tagsMap = stat.getTags();
|
|
||||||
Map<String, Object> fieldsMap = stat.getFields();
|
|
||||||
|
|
||||||
|
Map<String, String> tagsMap = sockStat.getTags();
|
||||||
|
Map<String, Object> fieldsMap = sockStat.getFields();
|
||||||
|
fieldsMap.putAll(devStat.getFields());
|
||||||
|
|
||||||
return new MetricResult("network", new Measurement(tagsMap, fieldsMap));
|
return new MetricResult("network", new Measurement(tagsMap, fieldsMap));
|
||||||
}
|
}
|
||||||
|
@ -70,8 +59,8 @@ public class LinuxNetworkExtension implements MetricExtension {
|
||||||
return new LinuxNetworkSockStat(inputLines);
|
return new LinuxNetworkSockStat(inputLines);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected LinuxNetworkDevProcLine processDevOutput(List<String> inputLines) {
|
protected LinuxNetworkDevStat processDevOutput(List<String> inputLines) {
|
||||||
return new LinuxNetworkDevProcLine(inputLines);
|
return new LinuxNetworkDevStat(inputLines);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
import spock.lang.Specification
|
import spock.lang.Specification
|
||||||
import sysmon.plugins.os_linux.LinuxDiskExtension
|
|
||||||
import sysmon.plugins.os_linux.LinuxDiskProcLine
|
|
||||||
import sysmon.plugins.os_linux.LinuxDiskStat
|
|
||||||
import sysmon.plugins.os_linux.LinuxNetworkDevProcLine
|
|
||||||
import sysmon.plugins.os_linux.LinuxNetworkDevStat
|
import sysmon.plugins.os_linux.LinuxNetworkDevStat
|
||||||
import sysmon.plugins.os_linux.LinuxNetworkExtension
|
import sysmon.plugins.os_linux.LinuxNetworkExtension
|
||||||
import sysmon.plugins.os_linux.LinuxNetworkSockStat
|
import sysmon.plugins.os_linux.LinuxNetworkSockStat
|
||||||
|
@ -40,7 +36,7 @@ class LinuxNetworkTest extends Specification {
|
||||||
|
|
||||||
when:
|
when:
|
||||||
LinuxNetworkExtension extension = new LinuxNetworkExtension()
|
LinuxNetworkExtension extension = new LinuxNetworkExtension()
|
||||||
LinuxNetworkDevProcLine procLine = extension.processDevOutput(lines)
|
LinuxNetworkDevStat procLine = extension.processDevOutput(lines)
|
||||||
|
|
||||||
then:
|
then:
|
||||||
procLine.getRxBytes() == 663911036L
|
procLine.getRxBytes() == 663911036L
|
||||||
|
@ -51,14 +47,15 @@ class LinuxNetworkTest extends Specification {
|
||||||
procLine.getTxErrs() == 0L
|
procLine.getTxErrs() == 0L
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
void "test dev utilization"() {
|
void "test dev utilization"() {
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
def testFile1 = new File(getClass().getResource('/proc_net_dev1.txt').toURI())
|
def testFile1 = new File(getClass().getResource('/proc_net_dev1.txt').toURI())
|
||||||
def testFile2 = new File(getClass().getResource('/proc_net_dev2.txt').toURI())
|
def testFile2 = new File(getClass().getResource('/proc_net_dev2.txt').toURI())
|
||||||
LinuxNetworkExtension extension = new LinuxNetworkExtension()
|
LinuxNetworkExtension extension = new LinuxNetworkExtension()
|
||||||
LinuxNetworkDevProcLine procLine1 = extension.processDevOutput(testFile1.readLines())
|
LinuxNetworkDevStat procLine1 = extension.processDevOutput(testFile1.readLines())
|
||||||
LinuxNetworkDevProcLine procLine2 = extension.processDevOutput(testFile2.readLines())
|
LinuxNetworkDevStat procLine2 = extension.processDevOutput(testFile2.readLines())
|
||||||
|
|
||||||
when:
|
when:
|
||||||
LinuxNetworkDevStat networkDevStat = new LinuxNetworkDevStat(procLine1, procLine2)
|
LinuxNetworkDevStat networkDevStat = new LinuxNetworkDevStat(procLine1, procLine2)
|
||||||
|
@ -68,7 +65,6 @@ class LinuxNetworkTest extends Specification {
|
||||||
networkDevStat.getFields().get("rxBytes") == 31501L
|
networkDevStat.getFields().get("rxBytes") == 31501L
|
||||||
networkDevStat.getFields().get("txBytes") == 46460L
|
networkDevStat.getFields().get("txBytes") == 46460L
|
||||||
networkDevStat.getFields().get("txPackets") == 341L
|
networkDevStat.getFields().get("txPackets") == 341L
|
||||||
|
}*/
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue