Skip to content

Commit

Permalink
fixup! Address issues caused by missing sigar lib
Browse files Browse the repository at this point in the history
  • Loading branch information
kovrus committed Aug 21, 2015
1 parent 2a81122 commit b89af8a
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

public abstract class SysNodeObjectReference extends NestedObjectExpression {

public static final SysNodeExpression UNKNOWN_VALUE_EXPRESSION = new SysNodeExpression() {
@Override
public Short value() {
return -1;
}
};

protected abstract class ChildExpression<T> extends SysNodeExpression<T> {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ReferenceImplementation<Object[]> getChildImplementation(String name) {
Object value = child.value();
values[i++] = value;
} else {
values[i++] = null;
i++;
}
}
return new SimpleObjectExpression<Object[]>() {
Expand All @@ -58,8 +58,6 @@ public Object[] value() {
}

};


}

@Override
Expand All @@ -84,4 +82,4 @@ public Object apply(@Nullable ReferenceImplementation input) {
}
return values;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ abstract class MemoryExpression extends SysNodeExpression<Object> {
public static final String PROBE_TIMESTAMP = "probe_timestamp";

public NodeMemoryExpression(final OsStats stats) {
addChildImplementations(stats.mem());
if (stats.mem() == null) {
childImplementations.put(FREE, UNKNOWN_VALUE_EXPRESSION);
childImplementations.put(USED, UNKNOWN_VALUE_EXPRESSION);
childImplementations.put(FREE_PERCENT, UNKNOWN_VALUE_EXPRESSION);
childImplementations.put(USED_PERCENT, UNKNOWN_VALUE_EXPRESSION);
} else {
addChildImplementations(stats.mem());
}
childImplementations.put(PROBE_TIMESTAMP, new SysNodeExpression<Long>() {
@Override
public Long value() {
Expand All @@ -51,37 +58,25 @@ private void addChildImplementations(final OsStats.Mem mem) {
childImplementations.put(FREE, new MemoryExpression() {
@Override
public Long value() {
if (mem != null) {
return mem.actualFree().bytes();
}
return -1L;
return mem.actualFree().bytes();
}
});
childImplementations.put(USED, new MemoryExpression() {
@Override
public Long value() {
if (mem != null) {
return mem.actualUsed().bytes();
}
return -1L;
return mem.actualUsed().bytes();
}
});
childImplementations.put(FREE_PERCENT, new MemoryExpression() {
@Override
public Short value() {
if (mem != null) {
return mem.freePercent();
}
return -1;
return mem.freePercent();
}
});
childImplementations.put(USED_PERCENT, new MemoryExpression() {
@Override
public Short value() {
if (mem != null) {
return mem.usedPercent();
}
return -1;
return mem.usedPercent();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,53 +45,46 @@ static class TCPConnectionsExpression extends SysNodeObjectReference {
private static final String EMBRYONIC_DROPPED = "embryonic_dropped";

protected TCPConnectionsExpression(NetworkStats stats) {
addChildImplementations(stats.tcp());
if (stats.tcp() == null) {
childImplementations.put(INITIATED, UNKNOWN_VALUE_EXPRESSION);
childImplementations.put(ACCEPTED, UNKNOWN_VALUE_EXPRESSION);
childImplementations.put(CURR_ESTABLISHED, UNKNOWN_VALUE_EXPRESSION);
childImplementations.put(DROPPED, UNKNOWN_VALUE_EXPRESSION);
childImplementations.put(EMBRYONIC_DROPPED, UNKNOWN_VALUE_EXPRESSION);
} else {
addChildImplementations(stats.tcp());
}
}

private void addChildImplementations(final NetworkStats.Tcp tcp) {
childImplementations.put(INITIATED, new TCPConnectionsChildExpression() {
@Override
public Long value() {
if (tcp != null) {
return tcp.activeOpens();
}
return VALUE_UNAVAILABLE;
return tcp.activeOpens();
}
});
childImplementations.put(ACCEPTED, new TCPConnectionsChildExpression() {
@Override
public Long value() {
if (tcp != null) {
return tcp.passiveOpens();
}
return VALUE_UNAVAILABLE;
return tcp.passiveOpens();
}
});
childImplementations.put(CURR_ESTABLISHED, new TCPConnectionsChildExpression() {
@Override
public Long value() {
if (tcp != null) {
return tcp.currEstab();
}
return VALUE_UNAVAILABLE;
return tcp.currEstab();
}
});
childImplementations.put(DROPPED, new TCPConnectionsChildExpression() {
@Override
public Long value() {
if (tcp != null) {
return tcp.estabResets();
}
return VALUE_UNAVAILABLE;
return tcp.estabResets();
}
});
childImplementations.put(EMBRYONIC_DROPPED, new TCPConnectionsChildExpression() {
@Override
public Long value() {
if (tcp != null) {
return tcp.attemptFails();
}
return VALUE_UNAVAILABLE;
return tcp.attemptFails();
}
});
}
Expand All @@ -111,53 +104,46 @@ static class TCPPacketsExpression extends SysNodeObjectReference {
private static final String RST_SENT = "rst_sent";

protected TCPPacketsExpression(NetworkStats stats) {
addChildImplementations(stats.tcp());
if (stats.tcp() == null) {
childImplementations.put(SENT, UNKNOWN_VALUE_EXPRESSION);
childImplementations.put(RECEIVED, UNKNOWN_VALUE_EXPRESSION);
childImplementations.put(RETRANSMITTED, UNKNOWN_VALUE_EXPRESSION);
childImplementations.put(ERRORS_RECEIVED, UNKNOWN_VALUE_EXPRESSION);
childImplementations.put(RST_SENT, UNKNOWN_VALUE_EXPRESSION);
} else {
addChildImplementations(stats.tcp());
}
}

private void addChildImplementations(final NetworkStats.Tcp tcp) {
childImplementations.put(SENT, new TCPPacketsChildExpression() {
@Override
public Long value() {
if (tcp != null) {
return tcp.outSegs();
}
return VALUE_UNAVAILABLE;
return tcp.outSegs();
}
});
childImplementations.put(RECEIVED, new TCPPacketsChildExpression() {
@Override
public Long value() {
if (tcp != null) {
return tcp.inSegs();
}
return VALUE_UNAVAILABLE;
return tcp.inSegs();
}
});
childImplementations.put(RETRANSMITTED, new TCPPacketsChildExpression() {
@Override
public Long value() {
if (tcp != null) {
return tcp.retransSegs();
}
return VALUE_UNAVAILABLE;
return tcp.retransSegs();
}
});
childImplementations.put(ERRORS_RECEIVED, new TCPPacketsChildExpression() {
@Override
public Long value() {
if (tcp != null) {
return tcp.inErrs();
}
return VALUE_UNAVAILABLE;
return tcp.inErrs();
}
});
childImplementations.put(RST_SENT, new TCPPacketsChildExpression() {
@Override
public Long value() {
if (tcp != null) {
return tcp.outRsts();
}
return VALUE_UNAVAILABLE;
return tcp.outRsts();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,58 +40,46 @@ abstract class CpuExpression extends SysNodeExpression<Object> {

@Inject
public NodeOsCpuExpression(OsStats stats) {
addChildImplementations(stats.cpu());
if (stats.cpu() == null) {
childImplementations.put(SYS, UNKNOWN_VALUE_EXPRESSION);
childImplementations.put(USER, UNKNOWN_VALUE_EXPRESSION);
childImplementations.put(IDLE, UNKNOWN_VALUE_EXPRESSION);
childImplementations.put(USAGE, UNKNOWN_VALUE_EXPRESSION);
childImplementations.put(STOLEN, UNKNOWN_VALUE_EXPRESSION);
} else {
addChildImplementations(stats.cpu());
}
}

private void addChildImplementations(final OsStats.Cpu cpu) {
childImplementations.put(SYS, new CpuExpression() {
@Override
public Short value() {
if (cpu != null) {
return cpu.sys();
} else {
return -1;
}
return cpu.sys();
}
});
childImplementations.put(USER, new CpuExpression() {
@Override
public Short value() {
if (cpu != null) {
return cpu.user();
} else {
return -1;
}
return cpu.user();
}
});
childImplementations.put(IDLE, new CpuExpression() {
@Override
public Short value() {
if (cpu != null) {
return cpu.idle();
} else {
return -1;
}
return cpu.idle();
}
});
childImplementations.put(USAGE, new CpuExpression() {
@Override
public Short value() {
if (cpu != null) {
return (short) (cpu.sys() + cpu.user());
} else {
return -1;
}
return (short) (cpu.sys() + cpu.user());
}
});
childImplementations.put(STOLEN, new CpuExpression() {
@Override
public Short value() {
if (cpu != null) {
return cpu.stolen();
} else {
return -1;
}
return cpu.stolen();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,32 @@ public class NodeProcessCpuExpression extends SysNodeObjectReference {
public static final String SYSTEM = "system";

public NodeProcessCpuExpression(ProcessStats stats) {
addChildImplementations(stats.cpu());
if (stats.cpu() == null) {
childImplementations.put(PERCENT, UNKNOWN_VALUE_EXPRESSION);
childImplementations.put(USER, UNKNOWN_VALUE_EXPRESSION);
childImplementations.put(SYSTEM, UNKNOWN_VALUE_EXPRESSION);
} else {
addChildImplementations(stats.cpu());
}
}

private void addChildImplementations(final ProcessStats.Cpu cpu) {
childImplementations.put(PERCENT, new SysNodeExpression<Short>() {
@Override
public Short value() {
if (cpu != null) {
return cpu.getPercent();
} else {
return -1;
}
return cpu.getPercent();
}
});
childImplementations.put(USER, new SysNodeExpression<Long>() {
@Override
public Long value() {
if (cpu != null) {
return cpu.getUser().millis();
} else {
return -1L;
}
return cpu.getUser().millis();
}
});
childImplementations.put(SYSTEM, new SysNodeExpression<Long>() {
@Override
public Long value() {
if (cpu != null) {
return cpu.getSys().millis();
} else {
return -1L;
}
return cpu.getSys().millis();
}
});
}
Expand Down

0 comments on commit b89af8a

Please sign in to comment.