Search in sources :

Example 1 with DiskInfoModel

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();
}
Also used : Path(java.nio.file.Path) SystemInfoModel(com.serotonin.m2m2.web.mvc.rest.v1.model.system.SystemInfoModel) User(com.serotonin.m2m2.vo.User) ArrayList(java.util.ArrayList) DiskInfoModel(com.serotonin.m2m2.web.mvc.rest.v1.model.system.DiskInfoModel) IOException(java.io.IOException) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) FileStore(java.nio.file.FileStore) FileSystem(java.nio.file.FileSystem) DirectoryInfo(com.serotonin.util.DirectoryInfo) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) File(java.io.File) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 User (com.serotonin.m2m2.vo.User)1 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)1 DiskInfoModel (com.serotonin.m2m2.web.mvc.rest.v1.model.system.DiskInfoModel)1 SystemInfoModel (com.serotonin.m2m2.web.mvc.rest.v1.model.system.SystemInfoModel)1 DirectoryInfo (com.serotonin.util.DirectoryInfo)1 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 File (java.io.File)1 IOException (java.io.IOException)1 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)1 FileStore (java.nio.file.FileStore)1 FileSystem (java.nio.file.FileSystem)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1