Refactoring of component names.
Plugins tests.
This commit is contained in:
parent
b1edee145a
commit
d1fc7582ac
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,5 +3,6 @@
|
|||
.classpath
|
||||
.project
|
||||
.gradle
|
||||
output
|
||||
build
|
||||
bin
|
||||
|
|
|
@ -20,11 +20,11 @@ dependencies {
|
|||
|
||||
application {
|
||||
// Define the main class for the application.
|
||||
mainClassName = 'org.sysmon.agent.Application'
|
||||
mainClassName = 'org.sysmon.client.Application'
|
||||
}
|
||||
|
||||
run {
|
||||
systemProperty 'pf4j.pluginsDir', '../plugins/test/'
|
||||
systemProperty 'pf4j.pluginsDir', '../plugins/output/'
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
|
@ -1,4 +1,4 @@
|
|||
package org.sysmon.agent;
|
||||
package org.sysmon.client;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
|
@ -30,11 +30,12 @@ public class AgentRouteBuilder extends RouteBuilder {
|
|||
log.info(">>> Enabling extension: " + ext.getDescription());
|
||||
|
||||
// Setup Camel route for this extension
|
||||
from("timer:collect?period=10000")
|
||||
from("timer:collect?period=5000")
|
||||
.bean(ext, "getMetrics")
|
||||
//.doTry()
|
||||
.process(new MetricEnrichProcessor())
|
||||
.choice().when(exchangeProperty("skip").isEqualTo(true))
|
||||
.log("Skipping: ${body}")
|
||||
.stop()
|
||||
.otherwise()
|
||||
.to("seda:metrics");
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This Java source file was generated by the Gradle 'init' task.
|
||||
*/
|
||||
package org.sysmon.agent;
|
||||
package org.sysmon.client;
|
||||
|
||||
import org.apache.camel.main.Main;
|
||||
import org.slf4j.Logger;
|
|
@ -1,4 +1,4 @@
|
|||
package org.sysmon.agent;
|
||||
package org.sysmon.client;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
||||
|
@ -12,13 +12,15 @@ public class MetricEnrichProcessor implements Processor {
|
|||
|
||||
public void process(Exchange exchange) throws Exception {
|
||||
MetricResult result = exchange.getIn().getBody(MetricResult.class);
|
||||
result.setHostname(hostname);
|
||||
|
||||
// We make sure MetricResults with no measurements are not sent further down the line
|
||||
if(result.getMeasurements().size() < 1) {
|
||||
if(result == null || result.getMeasurements().size() < 1) {
|
||||
exchange.setProperty("skip", true);
|
||||
return;
|
||||
}
|
||||
|
||||
result.setHostname(hostname);
|
||||
|
||||
exchange.getIn().setHeader("component", result.getName());
|
||||
exchange.getIn().setBody(result);
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
# to configure camel main
|
||||
# here you can configure options on camel main (see MainConfigurationProperties class)
|
||||
camel.main.name = sysmon-agent
|
||||
camel.main.name = sysmon-client
|
||||
|
||||
# enable tracing
|
||||
#camel.main.tracing = true
|
||||
|
@ -39,4 +39,4 @@ camel.main.lightweight = true
|
|||
# camel.main.auto-startup = false
|
||||
|
||||
# configure beans
|
||||
#camel.beans.metricProcessor = #class:org.sysmon.agent.MetricProcessor
|
||||
#camel.beans.metricProcessor = #class:org.sysmon.client.MetricProcessor
|
|
@ -1,4 +1,4 @@
|
|||
package org.sysmon.agent
|
||||
package org.sysmon.client
|
||||
|
||||
import spock.lang.Specification
|
||||
|
1
plugins/.gitignore
vendored
1
plugins/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
test
|
|
@ -29,7 +29,7 @@ subprojects {
|
|||
|
||||
task copyJar(type: Copy, dependsOn:[jar]) {
|
||||
from jar // here it automatically reads jar file produced from jar task
|
||||
into "../test/"
|
||||
into "../output/"
|
||||
}
|
||||
|
||||
tasks.assemble.dependsOn {
|
||||
|
@ -46,7 +46,7 @@ subprojects {
|
|||
}
|
||||
|
||||
task customCleanUp(type:Delete) {
|
||||
delete "test"
|
||||
delete "output"
|
||||
//delete files("${buildDir}/test/*.jar")
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public class AixProcessorExtension implements MetricExtension {
|
|||
List<String> mpstat = PluginHelper.executeCommand("mpstat", "-a");
|
||||
List<AixProcessorStat> processorStats = processCommandOutput(mpstat);
|
||||
for(AixProcessorStat stat : processorStats) {
|
||||
result.addMetricMeasurement(new MeasurementPair(String.format("cpu%d", stat.getCpuNum()), stat.getUtilizationPercentage()));
|
||||
result.addMeasurement(new MeasurementPair(String.format("cpu%d", stat.getCpuNum()), stat.getUtilizationPercentage()));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
27
plugins/sysmon-aix/src/test/groovy/AixProcessorTest.groovy
Normal file
27
plugins/sysmon-aix/src/test/groovy/AixProcessorTest.groovy
Normal file
|
@ -0,0 +1,27 @@
|
|||
import org.sysmon.plugins.sysmon_aix.AixProcessorExtension
|
||||
import org.sysmon.plugins.sysmon_aix.AixProcessorStat
|
||||
import spock.lang.Specification
|
||||
|
||||
class AixProcessorTest extends Specification {
|
||||
|
||||
void "test mpstat output processing"() {
|
||||
|
||||
setup:
|
||||
def testFile = new File(getClass().getResource('/mpstat1.txt').toURI())
|
||||
List<String> lines = testFile.readLines("UTF-8")
|
||||
|
||||
when:
|
||||
AixProcessorExtension extension = new AixProcessorExtension()
|
||||
List<AixProcessorStat> stats = extension.processCommandOutput(lines)
|
||||
|
||||
then:
|
||||
stats[0].getCombinedWorkTime() == 85.1f
|
||||
stats[0].getCombinedTime() == 100.0f
|
||||
stats[0].getSystemTime() == 18.4f
|
||||
stats[0].getUserTime() == 66.7f
|
||||
stats[0].getWaitTime() == 0.0f
|
||||
stats[0].getIdleTime() == 14.9f
|
||||
|
||||
}
|
||||
|
||||
}
|
15
plugins/sysmon-aix/src/test/resources/mpstat1.txt
Normal file
15
plugins/sysmon-aix/src/test/resources/mpstat1.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
System configuration: lcpu=8 ent=0.2 mode=Uncapped
|
||||
|
||||
cpu min maj mpcs mpcr dev soft dec ph cs ics bound rq push S3pull S3grd S0rd S1rd S2rd S3rd S4rd S5rd sysc us sy wa id pc %ec ilcs vlcs S3hrd S4hrd S5hrd
|
||||
cpu min maj mpcs mpcr dev soft dec ph cs ics bound rq push S3pull S3grd S0rd S1rd S2rd S3rd S4rd S5rd sysc us sy wa id pc %ec ilcs vlcs S3hrd S4hrd S5hrd %nsp
|
||||
0 22324631 12995 2450 1 117140 14071941 37427759 4 25044259 445796 1 3 0 0 0 99.9 0.1 0.0 0.0 0.0 0.0 77548535 66.7 18.4 0.0 14.9 0.00 0.1 237843 38774212 100.0 0.0 0.0 150
|
||||
1 275936 176 7 350 68318 1505 3604407 41 31072 25403 0 0 0 0 0 24.5 75.5 0.0 0.0 0.0 0.0 608541 0.2 0.8 0.0 99.0 0.00 0.0 916 3701367 100.0 0.0 0.0 150
|
||||
2 4713 1 0 351 58162 833 2400472 13 24152 23991 0 0 0 0 0 0.7 99.3 0.0 0.0 0.0 0.0 1445 0.0 1.0 0.0 99.0 0.00 0.0 163 2483263 100.0 0.0 0.0 150
|
||||
3 4587 2 0 351 57777 836 2400544 17 24094 23987 0 0 0 0 0 0.7 99.3 0.0 0.0 0.0 0.0 1199 0.0 0.4 0.0 99.6 0.00 0.0 167 2482920 100.0 0.0 0.0 150
|
||||
4 5 0 0 351 56903 784 2400095 16 23999 23965 0 0 0 0 0 0.0 100.0 0.0 0.0 0.0 0.0 7 0.0 1.0 0.0 99.0 0.00 0.0 153 2481522 100.0 0.0 0.0 150
|
||||
5 13 0 0 351 57171 815 2399248 12 23965 23962 0 0 0 0 0 0.0 100.0 0.0 0.0 0.0 0.0 0 0.0 0.4 0.0 99.6 0.00 0.0 145 2480922 100.0 0.0 0.0 150
|
||||
6 23529 102 0 351 56443 805 2401503 6 24217 24124 0 0 0 0 0 0.9 99.1 0.0 0.0 0.0 0.0 461 0.0 1.0 0.0 99.0 0.00 0.0 162 2482459 100.0 0.0 0.0 150
|
||||
7 1523 75 0 351 56335 783 4150673 11 24209 24040 0 0 0 0 0 1.1 98.9 0.0 0.0 0.0 0.0 471 0.0 0.9 0.0 99.1 0.00 0.0 479 4231232 100.0 0.0 0.0 150
|
||||
U - - - - - - - - - - - - - - - - - - - - - - - - 0.0 99.9 0.25 99.8 - - - - -
|
||||
ALL 22634937 13351 2457 2457 528249 14078302 57184701 120 25219967 615268 1 3 0 0 0 99.3 0.7 0.0 0.0 0.0 0.0 78160659 0.0 0.0 0.0 99.9 0.00 0.2 240028 59117897 100.0 0.0 0.0 0
|
15
plugins/sysmon-aix/src/test/resources/mpstat2.txt
Normal file
15
plugins/sysmon-aix/src/test/resources/mpstat2.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
System configuration: lcpu=8 ent=0.2 mode=Uncapped
|
||||
|
||||
cpu min maj mpcs mpcr dev soft dec ph cs ics bound rq push S3pull S3grd S0rd S1rd S2rd S3rd S4rd S5rd sysc us sy wa id pc %ec ilcs vlcs S3hrd S4hrd S5hrd
|
||||
cpu min maj mpcs mpcr dev soft dec ph cs ics bound rq push S3pull S3grd S0rd S1rd S2rd S3rd S4rd S5rd sysc us sy wa id pc %ec ilcs vlcs S3hrd S4hrd S5hrd %nsp
|
||||
0 22334111 14138 2450 1 117391 14078152 37441241 4 25056579 446411 1 4 0 0 0 99.9 0.1 0.0 0.0 0.0 0.0 77590574 66.7 18.4 0.0 14.9 0.00 0.1 237925 38789423 100.0 0.0 0.0 150
|
||||
1 275936 176 7 350 68538 1505 3605599 41 31080 25411 0 0 0 0 0 24.5 75.5 0.0 0.0 0.0 0.0 608541 0.2 0.8 0.0 99.0 0.00 0.0 916 3702787 100.0 0.0 0.0 150
|
||||
2 4713 1 0 351 58375 833 2401267 13 24160 23999 0 0 0 0 0 0.7 99.3 0.0 0.0 0.0 0.0 1445 0.0 1.0 0.0 99.0 0.00 0.0 163 2484279 100.0 0.0 0.0 150
|
||||
3 4587 2 0 351 57986 836 2401339 17 24102 23995 0 0 0 0 0 0.6 99.4 0.0 0.0 0.0 0.0 1199 0.0 0.4 0.0 99.6 0.00 0.0 167 2483932 100.0 0.0 0.0 150
|
||||
4 5 0 0 351 57114 786 2400891 16 24007 23973 0 0 0 0 0 0.0 100.0 0.0 0.0 0.0 0.0 7 0.0 1.0 0.0 99.0 0.00 0.0 154 2482537 100.0 0.0 0.0 150
|
||||
5 13 0 0 351 57379 815 2400045 12 23973 23970 0 0 0 0 0 0.0 100.0 0.0 0.0 0.0 0.0 0 0.0 0.4 0.0 99.6 0.00 0.0 145 2481936 100.0 0.0 0.0 150
|
||||
6 23529 102 0 351 56651 805 2402300 6 24225 24132 0 0 0 0 0 0.9 99.1 0.0 0.0 0.0 0.0 461 0.0 1.0 0.0 99.0 0.00 0.0 162 2483472 100.0 0.0 0.0 150
|
||||
7 1523 75 0 351 56544 783 4152029 11 24217 24048 0 0 0 0 0 1.1 98.9 0.0 0.0 0.0 0.0 471 0.0 0.9 0.0 99.1 0.00 0.0 479 4232805 100.0 0.0 0.0 150
|
||||
U - - - - - - - - - - - - - - - - - - - - - - - - 0.0 99.9 0.25 99.8 - - - - -
|
||||
ALL 22644417 14494 2457 2457 529978 14084515 57204711 120 25232343 615939 1 4 0 0 0 99.3 0.7 0.0 0.0 0.0 0.0 78202698 0.0 0.0 0.0 99.9 0.00 0.2 240111 59141171 100.0 0.0 0.0 0
|
|
@ -46,7 +46,7 @@ public class LinuxDiskExtension implements MetricExtension {
|
|||
try {
|
||||
copyCurrentValues();
|
||||
readProcFile();
|
||||
result.setMetricMeasurementList(calculate());
|
||||
result.addMeasurements(calculate());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public class LinuxMemoryExtension implements MetricExtension {
|
|||
|
||||
MetricResult result = new MetricResult("memory");
|
||||
try {
|
||||
result.setMetricMeasurementList(readProcFile());
|
||||
result.addMeasurements(readProcFile());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ package org.sysmon.plugins.sysmon_linux;
|
|||
import org.pf4j.Extension;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.sysmon.shared.MetricExtension;
|
||||
import org.sysmon.shared.MeasurementPair;
|
||||
import org.sysmon.shared.MetricExtension;
|
||||
import org.sysmon.shared.MetricResult;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -20,8 +20,8 @@ public class LinuxProcessorExtension implements MetricExtension {
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger(LinuxProcessorExtension.class);
|
||||
|
||||
private List<LinuxProcessorStat> currentProcessorStats;
|
||||
private List<LinuxProcessorStat> previousProcessorStats;
|
||||
private List<LinuxProcessorProcLine> currentProcessorProc;
|
||||
private List<LinuxProcessorProcLine> previousProcessorProc;
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -43,44 +43,25 @@ public class LinuxProcessorExtension implements MetricExtension {
|
|||
@Override
|
||||
public MetricResult getMetrics() {
|
||||
|
||||
if(currentProcessorStats != null && currentProcessorStats.size() > 0) {
|
||||
previousProcessorStats = new ArrayList<>(currentProcessorStats);
|
||||
if(currentProcessorProc != null && currentProcessorProc.size() > 0) {
|
||||
previousProcessorProc = new ArrayList<>(currentProcessorProc);
|
||||
}
|
||||
currentProcessorProc = processFileOutput(readProcFile());
|
||||
|
||||
MetricResult result = new MetricResult("processor");
|
||||
currentProcessorStats = processFileOutput(readProcFile());
|
||||
result.setMetricMeasurementList(calculateDifference());
|
||||
if(previousProcessorProc == null || previousProcessorProc.size() != currentProcessorProc.size()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
for(int i = 0; i < currentProcessorProc.size(); i++) {
|
||||
LinuxProcessorStat stat = new LinuxProcessorStat(currentProcessorProc.get(i), previousProcessorProc.get(i));
|
||||
result.addMeasurement(stat.getMeasurements());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private List<MeasurementPair> calculateDifference() {
|
||||
|
||||
List<MeasurementPair> measurementList = new ArrayList<>();
|
||||
|
||||
if(previousProcessorStats == null || previousProcessorStats.size() != currentProcessorStats.size()) {
|
||||
return measurementList;
|
||||
}
|
||||
|
||||
for(int i = 0; i < currentProcessorStats.size(); i++) {
|
||||
|
||||
LinuxProcessorStat curStat = currentProcessorStats.get(i);
|
||||
LinuxProcessorStat preStat = previousProcessorStats.get(i);
|
||||
|
||||
long workTimeDiff = curStat.getCombinedTime() - preStat.getCombinedTime();
|
||||
long idleTimeDiff = curStat.getCombinedIdleTime() - preStat.getCombinedIdleTime();
|
||||
float percentUsage = (float) (workTimeDiff - idleTimeDiff) / workTimeDiff;
|
||||
|
||||
Integer pct = (int) (percentUsage * 100);
|
||||
measurementList.add(new MeasurementPair(curStat.getCpuName(), pct));
|
||||
|
||||
}
|
||||
|
||||
return measurementList;
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected List<String> readProcFile() {
|
||||
|
||||
|
@ -95,12 +76,12 @@ public class LinuxProcessorExtension implements MetricExtension {
|
|||
}
|
||||
|
||||
|
||||
protected List<LinuxProcessorStat> processFileOutput(List<String> inputLines) {
|
||||
protected List<LinuxProcessorProcLine> processFileOutput(List<String> inputLines) {
|
||||
|
||||
List<LinuxProcessorStat> processorStats = new ArrayList<>();
|
||||
List<LinuxProcessorProcLine> processorStats = new ArrayList<>();
|
||||
for(String line : inputLines) {
|
||||
if(line.matches("^cpu\\d+.*")) {
|
||||
processorStats.add(new LinuxProcessorStat(line));
|
||||
processorStats.add(new LinuxProcessorProcLine(line));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
package org.sysmon.plugins.sysmon_linux;
|
||||
|
||||
public class LinuxProcessorProcLine {
|
||||
|
||||
private final String cpuName;
|
||||
private final Long userTime;
|
||||
private final Long niceTime;
|
||||
private final Long systemTime;
|
||||
private final Long idleTime;
|
||||
private final Long ioWaitTime;
|
||||
private final Long irqTime;
|
||||
private final Long softIrqTime;
|
||||
private final Long stealTime;
|
||||
private final Long guestTime;
|
||||
private final Long guestNiceTime;
|
||||
|
||||
|
||||
public LinuxProcessorProcLine(String procString) {
|
||||
|
||||
String[] splitStr = procString.trim().split("\\s+");
|
||||
if(splitStr.length != 11) {
|
||||
throw new UnsupportedOperationException("Linux proc CPU string error: " + procString);
|
||||
}
|
||||
|
||||
this.cpuName = splitStr[0];
|
||||
this.userTime = Long.parseLong(splitStr[1]);
|
||||
this.niceTime = Long.parseLong(splitStr[2]);
|
||||
this.systemTime = Long.parseLong(splitStr[3]);
|
||||
this.idleTime = Long.parseLong(splitStr[4]);
|
||||
this.ioWaitTime = Long.parseLong(splitStr[5]);
|
||||
this.irqTime = Long.parseLong(splitStr[6]);
|
||||
this.softIrqTime = Long.parseLong(splitStr[7]);
|
||||
this.stealTime = Long.parseLong(splitStr[8]);
|
||||
this.guestTime = Long.parseLong(splitStr[9]);
|
||||
this.guestNiceTime = Long.parseLong(splitStr[10]);
|
||||
|
||||
}
|
||||
|
||||
public String getCpuName() {
|
||||
return cpuName;
|
||||
}
|
||||
|
||||
public Long getUserTime() {
|
||||
return userTime;
|
||||
}
|
||||
|
||||
public Long getNiceTime() {
|
||||
return niceTime;
|
||||
}
|
||||
|
||||
public Long getSystemTime() {
|
||||
return systemTime;
|
||||
}
|
||||
|
||||
public Long getIdleTime() {
|
||||
return idleTime;
|
||||
}
|
||||
|
||||
public Long getIoWaitTime() {
|
||||
return ioWaitTime;
|
||||
}
|
||||
|
||||
public Long getIrqTime() {
|
||||
return irqTime;
|
||||
}
|
||||
|
||||
public Long getSoftIrqTime() {
|
||||
return softIrqTime;
|
||||
}
|
||||
|
||||
public Long getStealTime() {
|
||||
return stealTime;
|
||||
}
|
||||
|
||||
public Long getGuestTime() {
|
||||
return guestTime;
|
||||
}
|
||||
|
||||
public Long getGuestNiceTime() {
|
||||
return guestNiceTime;
|
||||
}
|
||||
|
||||
public Long getCombinedIdleTime() {
|
||||
return idleTime + ioWaitTime;
|
||||
}
|
||||
|
||||
public Long getCombinedWorkTime() {
|
||||
return userTime + niceTime + systemTime + irqTime + softIrqTime + stealTime + guestTime + guestNiceTime;
|
||||
}
|
||||
|
||||
public Long getCombinedTime() {
|
||||
return getCombinedIdleTime() + getCombinedWorkTime();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,95 +1,30 @@
|
|||
package org.sysmon.plugins.sysmon_linux;
|
||||
|
||||
import org.sysmon.shared.MeasurementPair;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LinuxProcessorStat {
|
||||
|
||||
private final String cpuName;
|
||||
private final Long userTime;
|
||||
private final Long niceTime;
|
||||
private final Long systemTime;
|
||||
private final Long idleTime;
|
||||
private final Long ioWaitTime;
|
||||
private final Long irqTime;
|
||||
private final Long softIrqTime;
|
||||
private final Long stealTime;
|
||||
private final Long guestTime;
|
||||
private final Long guestNiceTime;
|
||||
private final float utilizationPercentage;
|
||||
|
||||
public LinuxProcessorStat(LinuxProcessorProcLine current, LinuxProcessorProcLine previous) {
|
||||
cpuName = current.getCpuName();
|
||||
|
||||
LinuxProcessorStat(String procString) {
|
||||
|
||||
String[] splitStr = procString.trim().split("\\s+");
|
||||
if(splitStr.length != 11) {
|
||||
throw new UnsupportedOperationException("Linux proc CPU string error: " + procString);
|
||||
}
|
||||
|
||||
this.cpuName = splitStr[0];
|
||||
this.userTime = Long.parseLong(splitStr[1]);
|
||||
this.niceTime = Long.parseLong(splitStr[2]);
|
||||
this.systemTime = Long.parseLong(splitStr[3]);
|
||||
this.idleTime = Long.parseLong(splitStr[4]);
|
||||
this.ioWaitTime = Long.parseLong(splitStr[5]);
|
||||
this.irqTime = Long.parseLong(splitStr[6]);
|
||||
this.softIrqTime = Long.parseLong(splitStr[7]);
|
||||
this.stealTime = Long.parseLong(splitStr[8]);
|
||||
this.guestTime = Long.parseLong(splitStr[9]);
|
||||
this.guestNiceTime = Long.parseLong(splitStr[10]);
|
||||
long workTimeDiff = current.getCombinedTime() - previous.getCombinedTime();
|
||||
long idleTimeDiff = current.getCombinedIdleTime() - previous.getCombinedIdleTime();
|
||||
|
||||
float utilization = (float) (workTimeDiff - idleTimeDiff) / workTimeDiff;
|
||||
utilizationPercentage = (utilization * 100);
|
||||
}
|
||||
|
||||
public String getCpuName() {
|
||||
return cpuName;
|
||||
|
||||
public MeasurementPair getMeasurements() {
|
||||
return new MeasurementPair(cpuName, utilizationPercentage);
|
||||
}
|
||||
|
||||
public Long getUserTime() {
|
||||
return userTime;
|
||||
}
|
||||
|
||||
public Long getNiceTime() {
|
||||
return niceTime;
|
||||
}
|
||||
|
||||
public Long getSystemTime() {
|
||||
return systemTime;
|
||||
}
|
||||
|
||||
public Long getIdleTime() {
|
||||
return idleTime;
|
||||
}
|
||||
|
||||
public Long getIoWaitTime() {
|
||||
return ioWaitTime;
|
||||
}
|
||||
|
||||
public Long getIrqTime() {
|
||||
return irqTime;
|
||||
}
|
||||
|
||||
public Long getSoftIrqTime() {
|
||||
return softIrqTime;
|
||||
}
|
||||
|
||||
public Long getStealTime() {
|
||||
return stealTime;
|
||||
}
|
||||
|
||||
public Long getGuestTime() {
|
||||
return guestTime;
|
||||
}
|
||||
|
||||
public Long getGuestNiceTime() {
|
||||
return guestNiceTime;
|
||||
}
|
||||
|
||||
public Long getCombinedIdleTime() {
|
||||
return idleTime + ioWaitTime;
|
||||
}
|
||||
|
||||
public Long getCombinedWorkTime() {
|
||||
return userTime + niceTime + systemTime + irqTime + softIrqTime + stealTime + guestTime + guestNiceTime;
|
||||
}
|
||||
|
||||
public Long getCombinedTime() {
|
||||
return getCombinedIdleTime() + getCombinedWorkTime();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
import org.sysmon.plugins.sysmon_linux.LinuxProcessorExtension
|
||||
import org.sysmon.plugins.sysmon_linux.LinuxProcessorProcLine
|
||||
import org.sysmon.plugins.sysmon_linux.LinuxProcessorStat
|
||||
import spock.lang.Specification
|
||||
|
||||
class LinuxProcessorTest extends Specification {
|
||||
|
||||
void "test proc file processing"() {
|
||||
|
||||
setup:
|
||||
def testFile = new File(getClass().getResource('/proc1.txt').toURI())
|
||||
List<String> lines = testFile.readLines("UTF-8")
|
||||
|
||||
when:
|
||||
LinuxProcessorExtension extension = new LinuxProcessorExtension()
|
||||
List<LinuxProcessorProcLine> procLines = extension.processFileOutput(lines)
|
||||
|
||||
then:
|
||||
procLines[0].getSystemTime() == 4686l
|
||||
procLines[0].getUserTime() == 27477l
|
||||
procLines[0].getIdleTime() == 281276l
|
||||
procLines[0].getIoWaitTime() == 252l
|
||||
|
||||
}
|
||||
|
||||
|
||||
void "test processor utlization"() {
|
||||
|
||||
setup:
|
||||
def testFile1 = new File(getClass().getResource('/proc1.txt').toURI())
|
||||
def testFile2 = new File(getClass().getResource('/proc2.txt').toURI())
|
||||
LinuxProcessorProcLine processorProcLine1 = new LinuxProcessorProcLine(testFile1.readLines().get(1))
|
||||
LinuxProcessorProcLine processorProcLine2 = new LinuxProcessorProcLine(testFile2.readLines().get(1))
|
||||
|
||||
when:
|
||||
LinuxProcessorStat processorStat = new LinuxProcessorStat(processorProcLine1, processorProcLine2)
|
||||
|
||||
then:
|
||||
processorStat.getMeasurements().getName() == "cpu0"
|
||||
processorStat.getMeasurements().getValue() == 42.13362f
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
9
plugins/sysmon-linux/src/test/resources/proc1.txt
Normal file
9
plugins/sysmon-linux/src/test/resources/proc1.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
cpu 209203 14 38118 2255635 1987 0 431 0 0 0
|
||||
cpu0 27477 3 4686 281276 252 0 4 0 0 0
|
||||
cpu1 25578 1 4701 283363 243 0 12 0 0 0
|
||||
cpu2 21817 0 4598 284376 279 0 377 0 0 0
|
||||
cpu3 26782 5 4810 281794 296 0 3 0 0 0
|
||||
cpu4 25568 0 4813 281555 237 0 6 0 0 0
|
||||
cpu5 25460 0 5313 282740 210 0 20 0 0 0
|
||||
cpu6 28989 1 4390 280404 220 0 3 0 0 0
|
||||
cpu7 27530 0 4804 280125 247 0 2 0 0 0
|
9
plugins/sysmon-linux/src/test/resources/proc2.txt
Normal file
9
plugins/sysmon-linux/src/test/resources/proc2.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
cpu 211854 14 38286 2260226 2000 0 434 0 0 0
|
||||
cpu0 27848 3 4706 281811 254 0 4 0 0 0
|
||||
cpu1 25908 1 4713 283951 244 0 12 0 0 0
|
||||
cpu2 22137 0 4625 284942 281 0 378 0 0 0
|
||||
cpu3 27193 5 4828 282288 298 0 3 0 0 0
|
||||
cpu4 25874 0 4836 282159 239 0 6 0 0 0
|
||||
cpu5 25756 0 5337 283350 211 0 22 0 0 0
|
||||
cpu6 29300 1 4418 280991 221 0 3 0 0 0
|
||||
cpu7 27834 0 4819 280731 249 0 2 0 0 0
|
|
@ -17,7 +17,7 @@ dependencies {
|
|||
|
||||
application {
|
||||
// Define the main class for the application.
|
||||
mainClassName = 'org.sysmon.collector.Application'
|
||||
mainClassName = 'org.sysmon.server.Application'
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
|
@ -1,7 +1,6 @@
|
|||
package org.sysmon.collector;
|
||||
package org.sysmon.server;
|
||||
|
||||
import org.apache.camel.main.Main;
|
||||
import org.apache.camel.support.SimpleRegistry;
|
||||
import org.influxdb.InfluxDB;
|
||||
import org.influxdb.InfluxDBFactory;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.sysmon.collector;
|
||||
package org.sysmon.server;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.camel.model.rest.RestBindingMode;
|
|
@ -1,4 +1,4 @@
|
|||
package org.sysmon.collector;
|
||||
package org.sysmon.server;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
|
@ -1,4 +1,4 @@
|
|||
package org.sysmon.collector.bean;
|
||||
package org.sysmon.server.bean;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
|
@ -1,4 +1,4 @@
|
|||
package org.sysmon.collector.bean;
|
||||
package org.sysmon.server.bean;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
# to configure camel main
|
||||
# here you can configure options on camel main (see MainConfigurationProperties class)
|
||||
camel.main.name = sysmon-collector
|
||||
camel.main.name = sysmon-server
|
||||
|
||||
# enable tracing
|
||||
#camel.main.tracing = true
|
||||
|
@ -39,5 +39,5 @@ camel.main.lightweight = true
|
|||
# camel.main.auto-startup = false
|
||||
|
||||
# configure beans
|
||||
#camel.beans.incomingMetricProcessor = #class:org.sysmon.collector.bean.IncomingMetricProcessor
|
||||
#camel.beans.hello = #class:org.sysmon.collector.bean.Hello
|
||||
#camel.beans.incomingMetricProcessor = #class:org.sysmon.server.bean.IncomingMetricProcessor
|
||||
#camel.beans.hello = #class:org.sysmon.server.bean.Hello
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
rootProject.name = 'sysmon'
|
||||
include('shared', 'agent', 'collector', 'plugins')
|
||||
include('shared', 'client', 'server', 'plugins')
|
||||
|
||||
new File(rootDir, "plugins").listFiles().each {
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ public class MetricResult implements Serializable {
|
|||
private List<MeasurementPair> measurements = new ArrayList<>();
|
||||
|
||||
public MetricResult() {
|
||||
|
||||
}
|
||||
|
||||
public MetricResult(String name) {
|
||||
|
@ -23,11 +22,11 @@ public class MetricResult implements Serializable {
|
|||
this.timestamp = Instant.now().toEpochMilli();
|
||||
}
|
||||
|
||||
public void setMetricMeasurementList(List<MeasurementPair> measurementList) {
|
||||
public void addMeasurements(List<MeasurementPair> measurementList) {
|
||||
this.measurements = measurementList;
|
||||
}
|
||||
|
||||
public void addMetricMeasurement(MeasurementPair measurement) {
|
||||
public void addMeasurement(MeasurementPair measurement) {
|
||||
measurements.add(measurement);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue