Search in sources :

Example 1 with DirectoryInfo

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();
}
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)

Example 2 with DirectoryInfo

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;
}
Also used : PointHistoryCount(com.serotonin.m2m2.vo.bean.PointHistoryCount) HashMap(java.util.HashMap) DirectoryInfo(com.serotonin.util.DirectoryInfo) File(java.io.File) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 3 with DirectoryInfo

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;
}
Also used : DirectoryInfo(com.serotonin.util.DirectoryInfo) File(java.io.File)

Example 4 with DirectoryInfo

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;
}
Also used : ExtendedJdbcTemplate(com.serotonin.db.spring.ExtendedJdbcTemplate) DirectoryInfo(com.serotonin.util.DirectoryInfo) File(java.io.File)

Aggregations

DirectoryInfo (com.serotonin.util.DirectoryInfo)4 File (java.io.File)4 ExtendedJdbcTemplate (com.serotonin.db.spring.ExtendedJdbcTemplate)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 User (com.serotonin.m2m2.vo.User)1 PointHistoryCount (com.serotonin.m2m2.vo.bean.PointHistoryCount)1 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)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 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)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 HashMap (java.util.HashMap)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1