use of com.serotonin.util.DirectoryInfo 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();
}
use of com.serotonin.util.DirectoryInfo in project ma-core-public by infiniteautomation.
the class SystemSettingsDwr method getDatabaseSize.
@DwrPermission(admin = true)
public Map<String, Object> getDatabaseSize() {
Map<String, Object> data = new HashMap<>();
// Database size
Long dbSize = Common.databaseProxy.getDatabaseSizeInBytes();
if (dbSize != null) {
data.put("databaseSize", DirectoryUtils.bytesDescription(dbSize));
} else {
data.put("databaseSize", "(" + translate("common.unknown") + ")");
dbSize = 0L;
}
// Do we have any NoSQL Data
long noSqlSize = 0L;
if (Common.databaseProxy.getNoSQLProxy() != null) {
String pointValueStoreName = Common.envProps.getString("db.nosql.pointValueStoreName", "mangoTSDB");
noSqlSize = Common.databaseProxy.getNoSQLProxy().getDatabaseSizeInBytes(pointValueStoreName);
data.put("noSqlDatabaseSize", DirectoryUtils.bytesDescription(noSqlSize));
}
// Filedata data
DirectoryInfo fileDatainfo = DirectoryUtils.getSize(new File(Common.getFiledataPath()));
long filedataSize = fileDatainfo.getSize();
data.put("filedataCount", fileDatainfo.getCount());
data.put("filedataSize", DirectoryUtils.bytesDescription(filedataSize));
data.put("totalSize", DirectoryUtils.bytesDescription(dbSize + filedataSize + noSqlSize));
// Point history counts.
List<PointHistoryCount> counts = DataPointDao.instance.getTopPointHistoryCounts();
int sum = 0;
for (PointHistoryCount c : counts) sum += c.getCount();
data.put("historyCount", sum);
data.put("topPoints", counts);
data.put("eventCount", EventDao.instance.getEventCount());
return data;
}
use of com.serotonin.util.DirectoryInfo in project ma-core-public by infiniteautomation.
the class DerbyProxy method getDatabaseSizeInBytes.
@Override
public Long getDatabaseSizeInBytes() {
String dataDir = getUrl("");
File dbData = new File(dataDir);
if (dbData.exists()) {
DirectoryInfo dbInfo = DirectoryUtils.getSize(dbData);
return dbInfo.getSize();
} else
return null;
}
use of com.serotonin.util.DirectoryInfo in project ma-core-public by infiniteautomation.
the class H2Proxy method getDatabaseSizeInBytes.
@Override
public Long getDatabaseSizeInBytes() {
ExtendedJdbcTemplate ejt = new ExtendedJdbcTemplate();
ejt.setDataSource(this.getDataSource());
String dataDir = ejt.queryForObject("call DATABASE_PATH()", new Object[] {}, String.class, null);
if (dataDir == null) {
return null;
}
// Good until we change to MVStore
File dbData = new File(dataDir + ".h2.db");
if (dbData.exists()) {
DirectoryInfo dbInfo = DirectoryUtils.getSize(dbData);
return dbInfo.getSize();
} else
return null;
}
Aggregations