Example #1
0
        private async Task ProcessNode(ProxmoxVEAPI.Client.Contracts.Response.Node[] proxmoxNodes, Application.Entities.DatacenterNode[] databaseNodes, ProxmoxVEAPI.Client.Contracts.Response.ClusterStatus node)
        {
            var selectedNode = databaseNodes.FirstOrDefault(n => n.Name == node.Name && n.Ip == node.Ip);
            var proxmoxNode  = proxmoxNodes.FirstOrDefault(n => n.NodeName == node.Name);
            var nodeDetails  = await nodeClient.GetNodeStatusAsync(node.Name);

            if (selectedNode != null)
            {
                selectedNode.Name    = node.Name;
                selectedNode.Uptime  = nodeDetails.Uptime;
                selectedNode.RamUsed = nodeDetails.Memory.Used;

                if ((await datacenterRepository.UpdateAsync(selectedNode)) > 0)
                {
                    logger.LogInformation("Existing node update in database.");
                }
            }
            else
            {
                selectedNode = new Application.Entities.DatacenterNode()
                {
                    Ip              = node.Ip,
                    Name            = node.Name,
                    Online          = node.Online == 1,
                    Uptime          = proxmoxNode.Uptime,
                    Core            = nodeDetails.CpuInfo.Cores,
                    Thread          = nodeDetails.CpuInfo.Cpus,
                    Flag            = nodeDetails.CpuInfo.Flags,
                    Mhz             = double.Parse(nodeDetails.CpuInfo.Mhz) / 1000,
                    Model           = nodeDetails.CpuInfo.Model,
                    RamFree         = nodeDetails.Memory.Free,
                    RamTotal        = nodeDetails.Memory.Total,
                    RamUsed         = nodeDetails.Memory.Used,
                    Socket          = nodeDetails.CpuInfo.Sockets,
                    SwapFree        = nodeDetails.Swap.Free,
                    SwapTotal       = nodeDetails.Swap.Total,
                    SwapUsed        = nodeDetails.Swap.Used,
                    KernelVersion   = nodeDetails.KernelVersion,
                    PveVersion      = nodeDetails.PveVersion,
                    UserHz          = nodeDetails.CpuInfo.UserHz,
                    Hvm             = nodeDetails.CpuInfo.Hvm == "1",
                    RootFsAvailable = nodeDetails.RootFs.Available,
                    RootFsFree      = nodeDetails.RootFs.Free,
                    RootFsTotal     = nodeDetails.RootFs.Total,
                    RootFsUsed      = nodeDetails.RootFs.Used
                };

                if ((await datacenterRepository.InsertAsync(selectedNode)) > 0)
                {
                    logger.LogInformation("New node insert in database.");
                }
            }
        }