Browse Source

docker features

master
gsd 1 year ago
parent
commit
3b4347bd9e
  1. 48
      src/main/java/app/controllers/other/DockerController.java
  2. 37
      src/main/java/app/entities/server/DockerStats.java
  3. 1
      src/main/java/app/entities/server/Server.java

48
src/main/java/app/controllers/other/DockerController.java

@ -0,0 +1,48 @@
package app.controllers.other;
import app.annotations.enums.AuthMethod;
import app.annotations.interfaces.CheckWebAccess;
import app.entities.Stats;
import app.entities.server.DockerStats;
import jakarta.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/api/docker")
public class DockerController {
private Stats stats;
@Autowired
DockerController(Stats stats) {
this.stats = stats;
}
@GetMapping
@CheckWebAccess(auth_method = AuthMethod.SECRET_KEY)
public List<SrvDc> getContainerOnServer(HttpServletRequest httpServletRequest) {
return stats.getServers().entrySet().stream().map(e -> new SrvDc(e.getKey(), e.getValue().getDc())).collect(Collectors.toList());
}
@PostMapping("/{srv}")
@CheckWebAccess(auth_method = AuthMethod.SECRET_KEY)
public ResponseEntity setStats(HttpServletRequest httpServletRequest, @PathVariable String srv, @RequestBody DockerStats dockerStats) {
if (!stats.getServers().containsKey(srv)) return new ResponseEntity<>(HttpStatus.NOT_FOUND);
stats.getServers().get(srv).setDockerStats(dockerStats);
return ResponseEntity.ok().build();
}
@Data
@AllArgsConstructor
public class SrvDc {
String srv;
String container;
}
}

37
src/main/java/app/entities/server/DockerStats.java

@ -0,0 +1,37 @@
package app.entities.server;
import lombok.Data;
@Data
public class DockerStats {
CPU cpu = new CPU();
MEM mem = new MEM();
NET net = new NET();
IO io = new IO();
float utime = 0;
@Data
public class CPU {
float percent;
}
@Data
public class MEM {
float percent;
float usage;
float limit;
}
@Data
public class NET {
float input;
float output;
}
@Data
public class IO {
float input;
float output;
}
}

1
src/main/java/app/entities/server/Server.java

@ -31,6 +31,7 @@ public class Server extends ExternalValveClient {
HashMap<String, Long> uniq = new HashMap<>();
List<RCONPlayer> players = new ArrayList<>();
long last_update = 0;
DockerStats dockerStats = new DockerStats();
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private String db;

Loading…
Cancel
Save