示例#1
0
        private void Refresh_DiskUsages()
        {
            if (RequiresUpdate && !disposed)
            {
                Logger.LogMessage("Begin DiskUsage Refresh...", LogType.Debug);

                List <DiskUsage> temp  = new List <DiskUsage>();
                String           raw   = _client.GetCommandRawResponse("/bin/df -h");
                String[]         lines = raw.Split(new string[] { Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string line in lines)
                {
                    Match match = Regex.Match(line, @"(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\d+)%\s+(.+)");
                    if (match.Success)
                    {
                        try
                        {
                            String fileSystem = match.Groups[1].Value;
                            Logger.LogMessage(" - Disk: '" + fileSystem + "'", LogType.Debug);
                            XmlNode node = ParseXMLConfig("nas4free/mounts/mount[devicespecialfile=\"" + fileSystem + "\"]");
                            if (node != null)
                            {
                                Logger.LogMessage("   - Found mount config", LogType.Debug);
                                String  sSize     = match.Groups[2].Value;
                                String  sUsed     = match.Groups[3].Value;
                                String  sFree     = match.Groups[4].Value;
                                String  sUsedPcnt = match.Groups[5].Value;
                                XmlNode innerNode = node.SelectSingleNode("sharename");
                                if (innerNode != null)
                                {
                                    Logger.LogMessage("   - Found sharename node", LogType.Debug);
                                    String sMount = innerNode.InnerText;
                                    if (!string.IsNullOrEmpty(sMount))
                                    {
                                        DiskUsage du = new DiskUsage(sMount);
                                        du.FileSystem = fileSystem;
                                        du.TotalSpace = sSize;
                                        du.UsedSpace  = sUsed;
                                        du.FreeSpace  = sFree;
                                        int iTemp = 0;
                                        int.TryParse(sUsedPcnt, out iTemp);
                                        du.PercentUsed = iTemp;
                                        du.PoolStatus  = String.Empty;
                                        Logger.LogMessage("   - Adding disk" + fileSystem, LogType.Debug);
                                        temp.Add(du);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.LogMessage("   - Error: " + ex.Message, LogType.Debug);
                        }
                    }
                }

                String zfsRaw = _client.GetCommandRawResponse("/sbin/zpool list -H");
                lines = zfsRaw.Split(new String[] { Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string line in lines)
                {
                    Match match = Regex.Match(line, @"(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\d+)%\s+(\S+)\s+(\S+)\s+(.+)");
                    if (match.Success)
                    {
                        String poolName = match.Groups[1].Value;
                        Logger.LogMessage(" - Pool: '" + poolName + "'", LogType.Debug);
                        XmlNode node = ParseXMLConfig("nas4free/zfs/pools/pool[name=\"" + poolName + "\"]");
                        if (node != null)
                        {
                            try
                            {
                                Logger.LogMessage("   - Found pool config", LogType.Debug);
                                String sSize    = match.Groups[2].Value;
                                String sAlloc   = match.Groups[3].Value;
                                String sFree    = match.Groups[4].Value;
                                String sCap     = match.Groups[5].Value;
                                String sDedup   = match.Groups[6].Value;
                                String sHealth  = match.Groups[7].Value;
                                String sAltRoot = match.Groups[8].Value;
                                String zfsRaw2  = _client.GetCommandRawResponse("/sbin/zfs list -H -o used,available " + poolName);
                                Match  match2   = Regex.Match(zfsRaw2, @"(\S+)\s+(\S+)");
                                if (match2.Success)
                                {
                                    sAlloc = match2.Groups[1].Value;
                                    sFree  = match2.Groups[2].Value;
                                }
                                DiskUsage du = new DiskUsage(poolName);
                                du.FileSystem = poolName;
                                du.TotalSpace = sSize;
                                du.UsedSpace  = sAlloc;
                                du.FreeSpace  = sFree;
                                int iTemp = 0;
                                int.TryParse(sCap, out iTemp);
                                du.PercentUsed = iTemp;
                                du.PoolStatus  = sHealth;
                                Logger.LogMessage("   - Adding pool '" + poolName + "'", LogType.Debug);
                                temp.Add(du);
                            }
                            catch (Exception ex)
                            {
                                Logger.LogMessage("   - Error: " + ex.Message, LogType.Debug);
                            }
                        }
                    }
                    temp = temp.OrderBy(t => t.Name).ToList();
                }
                lock (_diskUsages)
                {
                    _diskUsages = temp;
                    Logger.LogMessage(" - Updated DiskUsage", LogType.Debug);
                }
            }
        }
        private void Refresh_DiskUsages()
        {
            if (RequiresUpdate && !disposed)
            {
                Logger.LogMessage("Begin DiskUsage Refresh...", LogType.Debug);

                List<DiskUsage> temp = new List<DiskUsage>();
                String raw = _client.GetCommandRawResponse("/bin/df -h");
                String[] lines = raw.Split(new string[] { Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string line in lines)
                {
                    Match match = Regex.Match(line, @"(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\d+)%\s+(.+)");
                    if (match.Success)
                    {
                        try
                        {
                            String fileSystem = match.Groups[1].Value;
                            Logger.LogMessage(" - Disk: '" + fileSystem + "'", LogType.Debug);
                            XmlNode node = ParseXMLConfig("nas4free/mounts/mount[devicespecialfile=\"" + fileSystem + "\"]");
                            if (node != null)
                            {
                                Logger.LogMessage("   - Found mount config", LogType.Debug);
                                String sSize = match.Groups[2].Value;
                                String sUsed = match.Groups[3].Value;
                                String sFree = match.Groups[4].Value;
                                String sUsedPcnt = match.Groups[5].Value;
                                XmlNode innerNode = node.SelectSingleNode("sharename");
                                if (innerNode != null)
                                {
                                    Logger.LogMessage("   - Found sharename node", LogType.Debug);
                                    String sMount = innerNode.InnerText;
                                    if (!string.IsNullOrEmpty(sMount))
                                    {
                                        DiskUsage du = new DiskUsage(sMount);
                                        du.FileSystem = fileSystem;
                                        du.TotalSpace = sSize;
                                        du.UsedSpace = sUsed;
                                        du.FreeSpace = sFree;
                                        int iTemp = 0;
                                        int.TryParse(sUsedPcnt, out iTemp);
                                        du.PercentUsed = iTemp;
                                        du.PoolStatus = String.Empty;
                                        Logger.LogMessage("   - Adding disk" + fileSystem, LogType.Debug);
                                        temp.Add(du);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.LogMessage("   - Error: " + ex.Message, LogType.Debug);
                        }
                    }
                }

                String zfsRaw = _client.GetCommandRawResponse("/sbin/zpool list -H");
                lines = zfsRaw.Split(new String[] { Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string line in lines)
                {
                    Match match = Regex.Match(line, @"(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\d+)%\s+(\S+)\s+(\S+)\s+(.+)");
                    if (match.Success)
                    {
                        String poolName = match.Groups[1].Value;
                        Logger.LogMessage(" - Pool: '" + poolName + "'", LogType.Debug);
                        XmlNode node = ParseXMLConfig("nas4free/zfs/pools/pool[name=\"" + poolName + "\"]");
                        if (node != null)
                        {
                            try
                            {
                                Logger.LogMessage("   - Found pool config", LogType.Debug);
                                String sSize = match.Groups[2].Value;
                                String sAlloc = match.Groups[3].Value;
                                String sFree = match.Groups[4].Value;
                                String sCap = match.Groups[5].Value;
                                String sDedup = match.Groups[6].Value;
                                String sHealth = match.Groups[7].Value;
                                String sAltRoot = match.Groups[8].Value;
                                String zfsRaw2 = _client.GetCommandRawResponse("/sbin/zfs list -H -o used,available " + poolName);
                                Match match2 = Regex.Match(zfsRaw2, @"(\S+)\s+(\S+)");
                                if (match2.Success)
                                {
                                    sAlloc = match2.Groups[1].Value;
                                    sFree = match2.Groups[2].Value;
                                }
                                DiskUsage du = new DiskUsage(poolName);
                                du.FileSystem = poolName;
                                du.TotalSpace = sSize;
                                du.UsedSpace = sAlloc;
                                du.FreeSpace = sFree;
                                int iTemp = 0;
                                int.TryParse(sCap, out iTemp);
                                du.PercentUsed = iTemp;
                                du.PoolStatus = sHealth;
                                Logger.LogMessage("   - Adding pool '" + poolName + "'", LogType.Debug);
                                temp.Add(du);
                            }
                            catch (Exception ex)
                            {
                                Logger.LogMessage("   - Error: " + ex.Message, LogType.Debug);
                            }
                        }
                    }
                    temp = temp.OrderBy(t => t.Name).ToList();
                }
                lock (_diskUsages)
                {
                    _diskUsages = temp;
                    Logger.LogMessage(" - Updated DiskUsage", LogType.Debug);
                }
            }
        }