stats into JSON

This commit is contained in:
rusefi 2020-07-30 23:44:36 -04:00
parent 2779b95e67
commit 71b2665799
3 changed files with 15 additions and 6 deletions

View File

@ -7,6 +7,7 @@ import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.binaryprotocol.IncomingDataBuffer;
import com.rusefi.binaryprotocol.IoHelper;
import com.rusefi.io.serial.AbstractIoStream;
import com.rusefi.io.serial.StreamStatistics;
import com.rusefi.io.tcp.BinaryProtocolServer;
import org.jetbrains.annotations.NotNull;
@ -23,7 +24,7 @@ import static com.devexperts.logging.Logging.getLogging;
* <p>
* 5/11/2015.
*/
public interface IoStream extends WriteStream, Closeable {
public interface IoStream extends WriteStream, Closeable, StreamStatistics {
Logging log = getLogging(IoStream.class);
static String printHexBinary(byte[] data) {

View File

@ -5,7 +5,7 @@ import com.rusefi.io.IoStream;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
public abstract class AbstractIoStream implements IoStream, StreamStatistics {
public abstract class AbstractIoStream implements IoStream {
private boolean isClosed;
protected StreamStats streamStats = new StreamStats();

View File

@ -271,17 +271,25 @@ public class Backend implements Closeable {
JsonArrayBuilder builder = Json.createArrayBuilder();
List<ApplicationConnectionState> applications = getApplications();
for (ApplicationConnectionState application : applications) {
JsonObject applicationObject = Json.createObjectBuilder()
JsonObjectBuilder b = Json.createObjectBuilder()
.add(UserDetails.USER_ID, application.getUserDetails().getUserId())
.add(UserDetails.USERNAME, application.getUserDetails().getUserName())
.add(AGE, application.getBirthday().getDuration())
.add(MAX_PACKET_GAP, application.getClientStream().getStreamStats().getMaxPacketGap())
;
JsonObject applicationObject = addStreamStats(b, application.getClientStream())
.build();
builder.add(applicationObject);
}
return new RsJson(builder.build());
}
private static JsonObjectBuilder addStreamStats(JsonObjectBuilder builder, IoStream stream) {
return builder
.add(MAX_PACKET_GAP, stream.getStreamStats().getMaxPacketGap())
.add("in", stream.getBytesIn())
.add("out", stream.getBytesOut());
}
@NotNull
private RsJson getControllersOnline() throws IOException {
JsonArrayBuilder builder = Json.createArrayBuilder();
@ -303,8 +311,8 @@ public class Backend implements Closeable {
.add(ControllerInfo.SIGNATURE, client.getSessionDetails().getControllerInfo().getSignature())
.add(ControllerInfo.VEHICLE_NAME, client.getSessionDetails().getControllerInfo().getVehicleName())
.add(ControllerInfo.ENGINE_MAKE, client.getSessionDetails().getControllerInfo().getEngineMake())
.add(ControllerInfo.ENGINE_CODE, client.getSessionDetails().getControllerInfo().getEngineCode())
.add(MAX_PACKET_GAP, client.getStream().getStreamStats().getMaxPacketGap());
.add(ControllerInfo.ENGINE_CODE, client.getSessionDetails().getControllerInfo().getEngineCode());
objectBuilder = addStreamStats(objectBuilder, client.getStream());
if (owner != null) {
objectBuilder = objectBuilder.add(ProxyClient.OWNER, owner.getUserName());
}