use of com.serotonin.m2m2.web.mvc.rest.v1.model.system.DiskInfoModel in project ma-modules-public by infiniteautomation.
the class ServerRestController method getSystemInfo.
@ApiOperation(value = "System Info", notes = "Provides disk use, db sizes and point, event counts", response = Map.class)
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/system-info")
public ResponseEntity<SystemInfoModel> getSystemInfo(HttpServletRequest request) {
RestProcessResult<SystemInfoModel> result = new RestProcessResult<SystemInfoModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (user.isAdmin()) {
SystemInfoModel model = new SystemInfoModel();
// Database size
model.setSqlDbSizeBytes(Common.databaseProxy.getDatabaseSizeInBytes());
// Do we have any NoSQL Data
if (Common.databaseProxy.getNoSQLProxy() != null) {
String pointValueStoreName = Common.envProps.getString("db.nosql.pointValueStoreName", "mangoTSDB");
model.setNoSqlDbSizeBytes(Common.databaseProxy.getNoSQLProxy().getDatabaseSizeInBytes(pointValueStoreName));
}
// Filedata data
DirectoryInfo fileDatainfo = DirectoryUtils.getSize(new File(Common.getFiledataPath()));
model.setFileDataSizeBytes(fileDatainfo.getSize());
// Point history counts.
model.setTopPoints(DataPointDao.instance.getTopPointHistoryCounts());
model.setEventCount(EventDao.instance.getEventCount());
// Disk Info
FileSystem fs = FileSystems.getDefault();
List<DiskInfoModel> disks = new ArrayList<DiskInfoModel>();
model.setDisks(disks);
for (Path root : fs.getRootDirectories()) {
try {
FileStore store = Files.getFileStore(root);
DiskInfoModel disk = new DiskInfoModel();
disk.setName(root.getRoot().toString());
disk.setTotalSpaceBytes(store.getTotalSpace());
disk.setUsableSpaceBytes(store.getUsableSpace());
disks.add(disk);
} catch (IOException e) {
}
}
// CPU Info
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
model.setLoadAverage(osBean.getSystemLoadAverage());
// OS Info
model.setArchitecture(osBean.getArch());
model.setOperatingSystem(osBean.getName());
model.setOsVersion(osBean.getVersion());
return result.createResponseEntity(model);
} else {
result.addRestMessage(HttpStatus.UNAUTHORIZED, new TranslatableMessage("common.default", "User not admin"));
}
}
return result.createResponseEntity();
}
Aggregations