grr/server/grr_response_server/hunt.py
def StopHuntIfAverageLimitsExceeded(hunt_obj):
  """Stops the hunt if average limites are exceeded."""

  # Do nothing if the hunt is already stopped.
  if hunt_obj.hunt_state == rdf_hunt_objects.Hunt.HuntState.STOPPED:
    return hunt_obj

  total_clients = (
      hunt_obj.num_successful_clients + hunt_obj.num_failed_clients +
      hunt_obj.num_crashed_clients)

  if total_clients < MIN_CLIENTS_FOR_AVERAGE_THRESHOLDS:
    return hunt_obj

  # Check average per-client results count limit.
  if hunt_obj.avg_results_per_client_limit:
    avg_results_per_client = (hunt_obj.num_results / total_clients)
    if avg_results_per_client > hunt_obj.avg_results_per_client_limit:
      # Stop the hunt since we get too many results per client.
      reason = ("Hunt %s reached the average results per client "
                "limit of %d and was stopped.") % (
                    hunt_obj.hunt_id, hunt_obj.avg_results_per_client_limit)
      return StopHunt(hunt_obj.hunt_id, reason=reason)

  # Check average per-client CPU seconds limit.
  if hunt_obj.avg_cpu_seconds_per_client_limit:
    avg_cpu_seconds_per_client = (
        (hunt_obj.client_resources_stats.user_cpu_stats.sum +
         hunt_obj.client_resources_stats.system_cpu_stats.sum) / total_clients)
    if avg_cpu_seconds_per_client > hunt_obj.avg_cpu_seconds_per_client_limit:
      # Stop the hunt since we use too many CPUs per client.
      reason = ("Hunt %s reached the average CPU seconds per client "
                "limit of %d and was stopped.") % (
                    hunt_obj.hunt_id, hunt_obj.avg_cpu_seconds_per_client_limit)
      return StopHunt(hunt_obj.hunt_id, reason=reason)

  # Check average per-client network bytes limit.
  if hunt_obj.avg_network_bytes_per_client_limit:
    avg_network_bytes_per_client = (
        hunt_obj.client_resources_stats.network_bytes_sent_stats.sum /
        total_clients)
    if (avg_network_bytes_per_client >
        hunt_obj.avg_network_bytes_per_client_limit):
      # Stop the hunt since we use too many network bytes sent
      # per client.
      reason = ("Hunt %s reached the average network bytes per client "
                "limit of %d and was stopped.") % (
                    hunt_obj.hunt_id,
                    hunt_obj.avg_network_bytes_per_client_limit)
      return StopHunt(hunt_obj.hunt_id, reason=reason)

  return hunt_obj
Stops the hunt if average limites are exceeded.
Stops the hunt if average limites are exceeded.
Stops the hunt if average limites are exceeded .
def StopHuntIfAverageLimitsExceeded(hunt_obj):
  if hunt_obj.hunt_state == rdf_hunt_objects.Hunt.HuntState.STOPPED:
    return hunt_obj
  total_clients = (
      hunt_obj.num_successful_clients + hunt_obj.num_failed_clients +
      hunt_obj.num_crashed_clients)
  if total_clients < MIN_CLIENTS_FOR_AVERAGE_THRESHOLDS:
    return hunt_obj
  if hunt_obj.avg_results_per_client_limit:
    avg_results_per_client = (hunt_obj.num_results / total_clients)
    if avg_results_per_client > hunt_obj.avg_results_per_client_limit:
      reason = ("Hunt %s reached the average results per client "
                "limit of %d and was stopped.") % (
                    hunt_obj.hunt_id, hunt_obj.avg_results_per_client_limit)
      return StopHunt(hunt_obj.hunt_id, reason=reason)
  if hunt_obj.avg_cpu_seconds_per_client_limit:
    avg_cpu_seconds_per_client = (
        (hunt_obj.client_resources_stats.user_cpu_stats.sum +
         hunt_obj.client_resources_stats.system_cpu_stats.sum) / total_clients)
    if avg_cpu_seconds_per_client > hunt_obj.avg_cpu_seconds_per_client_limit:
      reason = ("Hunt %s reached the average CPU seconds per client "
                "limit of %d and was stopped.") % (
                    hunt_obj.hunt_id, hunt_obj.avg_cpu_seconds_per_client_limit)
      return StopHunt(hunt_obj.hunt_id, reason=reason)
  if hunt_obj.avg_network_bytes_per_client_limit:
    avg_network_bytes_per_client = (
        hunt_obj.client_resources_stats.network_bytes_sent_stats.sum /
        total_clients)
    if (avg_network_bytes_per_client >
        hunt_obj.avg_network_bytes_per_client_limit):
      reason = ("Hunt %s reached the average network bytes per client "
                "limit of %d and was stopped.") % (
                    hunt_obj.hunt_id,
                    hunt_obj.avg_network_bytes_per_client_limit)
      return StopHunt(hunt_obj.hunt_id, reason=reason)
  return hunt_obj
def StopHuntIfAverageLimitsExceeded ( hunt_obj ) : if hunt_obj . hunt_state == rdf_hunt_objects . Hunt . HuntState . STOPPED : return hunt_obj total_clients = ( hunt_obj . num_successful_clients + hunt_obj . num_failed_clients + hunt_obj . num_crashed_clients ) if total_clients < MIN_CLIENTS_FOR_AVERAGE_THRESHOLDS : return hunt_obj if hunt_obj . avg_results_per_client_limit : avg_results_per_client = ( hunt_obj . num_results / total_clients ) if avg_results_per_client > hunt_obj . avg_results_per_client_limit : reason = ( "Hunt %s reached the average results per client " "limit of %d and was stopped." ) % ( hunt_obj . hunt_id , hunt_obj . avg_results_per_client_limit ) return StopHunt ( hunt_obj . hunt_id , reason = reason ) if hunt_obj . avg_cpu_seconds_per_client_limit : avg_cpu_seconds_per_client = ( ( hunt_obj . client_resources_stats . user_cpu_stats . sum + hunt_obj . client_resources_stats . system_cpu_stats . sum ) / total_clients ) if avg_cpu_seconds_per_client > hunt_obj . avg_cpu_seconds_per_client_limit : reason = ( "Hunt %s reached the average CPU seconds per client " "limit of %d and was stopped." ) % ( hunt_obj . hunt_id , hunt_obj . avg_cpu_seconds_per_client_limit ) return StopHunt ( hunt_obj . hunt_id , reason = reason ) if hunt_obj . avg_network_bytes_per_client_limit : avg_network_bytes_per_client = ( hunt_obj . client_resources_stats . network_bytes_sent_stats . sum / total_clients ) if ( avg_network_bytes_per_client > hunt_obj . avg_network_bytes_per_client_limit ) : reason = ( "Hunt %s reached the average network bytes per client " "limit of %d and was stopped." ) % ( hunt_obj . hunt_id , hunt_obj . avg_network_bytes_per_client_limit ) return StopHunt ( hunt_obj . hunt_id , reason = reason ) return hunt_obj
Stops the hunt if average limites are exceeded.
Stops the hunt if average limites are exceeded .
"""Stops the hunt if average limites are exceeded.""" # Do nothing if the hunt is already stopped. # Check average per-client results count limit. # Stop the hunt since we get too many results per client. # Check average per-client CPU seconds limit. # Stop the hunt since we use too many CPUs per client. # Check average per-client network bytes limit. # Stop the hunt since we use too many network bytes sent # per client.
hunt_obj