Click here to Skip to main content
15,878,231 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When 3 clients are connected wtih server. I want to monitor file, after threshold has been setup.

ForExample:
 Threshold is 50% has been set.
Iam monitoring folder name as C:\Newfolder. 
Total Size of NewFolder is 500MB.
When Newfolder reaches 250MB, I want to send notification to IT Team.

How it can be achieved. This is new to me.

I have done this sample in windows service. but we cannot install windows service in N number of client system.


What I have tried:

public void FolderMonitorTimer()
       {
           timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
           timer.Interval = 5000;
           timer.Enabled = true;
       }

<pre>// Get current system File monitor

static long DirectorySize12(DirectoryInfo dInfo, bool includeSubDir)
      {
          // Enumerate all the files
          long totalSize = dInfo.EnumerateFiles()
                       .Sum(file => file.Length);

          // If Subdirectories are to be included
          if (includeSubDir)
          {
              // Enumerate all sub-directories
              totalSize += dInfo.EnumerateDirectories()
                       .Sum(dir => DirectorySize12(dir, true));
          }
          return totalSize;
      }


private void OnElapsedTime(object source, ElapsedEventArgs e)
     {
         DirectoryInfo dInfo = new DirectoryInfo(FolderPath);

         long sizeOfDir = DirectorySize12(dInfo, true);


         usedSizeMB = ((double)sizeOfDir) / (1024 * 1024);
         availSizeMB = strDiskDefaultSize - usedSizeMB;
         availPercent = availSizeMB / strDiskDefaultSize * 100;
         UsedPercent = usedSizeMB / strDiskDefaultSize * 100;
         timer.Interval = 1000;
         WarningThreshold= 50;

         if ((Convert.ToInt32(UsedPercent) > Convert.ToInt32(WarningThreshold)))
         {
             //Send notification to IT Team

         }
Posted
Updated 6-Feb-17 5:11am
Comments
Tomas Takac 6-Feb-17 6:56am    
Why do you need to monitor something on client's computer from a web app? Sounds fishy.
vinodh muthusamy 6-Feb-17 7:29am    
From IT-Team They will set threshold value to monitor some specified path.

So that if any client system reaches that particular threshold value. We will send notification to IT team, To clean up or delete some unwanted datas.

These process will run background process.
[no name] 6-Feb-17 7:10am    
"we cannot install windows service ", why not? Just about the only way you can do this. If you need to do this legitimately, that is.
vinodh muthusamy 6-Feb-17 7:26am    
can you brief your suggestion
[no name] 6-Feb-17 9:43am    
No, I cannot "brief" anything. Use a service and you already know that. You are not going to monitor anything from the web.

1 solution

As NotPoliticallyCorrect[^] mentioned, "You are not going to monitor anything from the web."
There is only one way to achieve that: install Windows service on client computers.
On the other hand, there's tons of scripts available on net, which can be run to scan client computers (IT team perspective) to find out how much space C:\NewFolder occupied.
 
Share this answer
 
Comments
vinodh muthusamy 7-Feb-17 0:22am    
yes that was my question. Is there any alternate way to do. kindly provide me some solution and links for scripts

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900