title: Detecting SQL Server Utilization with a query
body: <p>My current project will send queries to an sql server constantly and It may use 100% of the memory or CPU. </p>
  
  <ul>
  <li><p>How can I check if the server is nearing full utilization in a stored procedure so that I can decide whether to execute the queries or not or save some settings in a table so that the following queries can know the workload is high and decide what to do</p></li>
  <li><p>If not, how can I prevent SQL server to reach full utilization?</p></li>
  </ul>
  
  <p>More information about the case: 
  Right now I know our current test server can process 40-50 queries per second (one specific stored procedure). And now we'll decide how many queries are sent to the server every second. If we set the amount even 1 higher than the expected, in the long run, the queries will eventually fill the virtual memory and out client will have to restart their sql server instance periodically.</p>
  
  <p>Expected Results (For bounty hunters): </p>
  
  <pre><code>@memory_usage float, @cpu_usage float; /* in percentage */
  </code></pre>
  
  <p>Any ideas are welcomed. Thanks.</p>