Ejemplo n.º 1
0
def _WriteFleetBreakdownStatsToDB(fleet_stats, report_type):
    """Saves a snapshot of client activity stats to the DB.

  Args:
    fleet_stats: Client activity stats returned by the DB.
    report_type: rdf_stats.ClientGraphSeries.ReportType for the client stats.
  """
    graph_series_by_label = collections.defaultdict(
        lambda: rdf_stats.ClientGraphSeries(report_type=report_type))
    for day_bucket in fleet_stats.GetDayBuckets():
        for client_label in fleet_stats.GetAllLabels():
            graph = rdf_stats.Graph(title="%d day actives for %s label" %
                                    (day_bucket, client_label))
            values = fleet_stats.GetValuesForDayAndLabel(
                day_bucket, client_label)
            for category_value, num_actives in sorted(values.items()):
                graph.Append(label=category_value, y_value=num_actives)
            graph_series_by_label[client_label].graphs.Append(graph)

    # Generate aggregate graphs for all clients in the snapshot (total for
    # every category_value regardless of label).
    for day_bucket in fleet_stats.GetDayBuckets():
        graph = rdf_stats.Graph(title="%d day actives for %s label" %
                                (day_bucket, _ALL_CLIENT_FLEET_STATS_LABEL))
        totals = fleet_stats.GetTotalsForDay(day_bucket)
        for category_value, num_actives in sorted(totals.items()):
            graph.Append(label=category_value, y_value=num_actives)
        graph_series_by_label[_ALL_CLIENT_FLEET_STATS_LABEL].graphs.Append(
            graph)

    for client_label, graph_series in graph_series_by_label.items():
        client_report_utils.WriteGraphSeries(graph_series, client_label)
Ejemplo n.º 2
0
def _WriteFleetAggregateStatsToDB(client_label, bucket_dict):
    graph = rdf_stats.Graph()
    for day_bucket, num_actives in sorted(bucket_dict.items()):
        graph.Append(x_value=rdfvalue.Duration.From(
            day_bucket, rdfvalue.DAYS).microseconds,
                     y_value=num_actives)
    graph_series = rdf_stats.ClientGraphSeries(
        report_type=rdf_stats.ClientGraphSeries.ReportType.N_DAY_ACTIVE)
    graph_series.graphs.Append(graph)
    client_report_utils.WriteGraphSeries(graph_series, client_label)
Ejemplo n.º 3
0
 def FinishProcessing(self):
   # Build and store the graph now. Day actives are cumulative.
   for label in self.values:
     cumulative_count = 0
     graph_series = rdf_stats.ClientGraphSeries(
         report_type=rdf_stats.ClientGraphSeries.ReportType.N_DAY_ACTIVE)
     graph_series.graphs.Append(rdf_stats.Graph())
     for x, y in zip(self._bins, self.values[label]):
       cumulative_count += y
       graph_series.graphs[0].Append(x_value=x, y_value=cumulative_count)
     client_report_utils.WriteGraphSeries(
         graph_series, label, token=self.token)
Ejemplo n.º 4
0
  def Save(self):
    """Generate a histogram object and store in the specified attribute."""
    graph_series_by_label = {}
    for active_time in self.active_days:
      for label in self.categories[active_time]:
        graphs_for_label = graph_series_by_label.setdefault(
            label, rdf_stats.ClientGraphSeries(report_type=self._report_type))
        graph = rdf_stats.Graph(title="%s day actives for %s label" %
                                (active_time, label))
        for k, v in sorted(iteritems(self.categories[active_time][label])):
          graph.Append(label=k, y_value=v)
        graphs_for_label.graphs.Append(graph)

    for label, graph_series in iteritems(graph_series_by_label):
      client_report_utils.WriteGraphSeries(graph_series, label)
Ejemplo n.º 5
0
  def Save(self, cron_flow):
    """Generate a histogram object and store in the specified attribute."""
    histograms = {}
    for active_time in self.active_days:
      for label in self.categories[active_time]:
        histograms.setdefault(label, self.attribute())
        graph = rdf_stats.Graph(title="%s day actives for %s label" %
                                (active_time, label))
        for k, v in sorted(iteritems(self.categories[active_time][label])):
          graph.Append(label=k, y_value=v)

        histograms[label].Append(graph)

    for label, histogram in iteritems(histograms):
      # Add an additional instance of this histogram (without removing previous
      # instances).
      # pylint: disable=protected-access
      cron_flow._StatsForLabel(label).AddAttribute(histogram)
Ejemplo n.º 6
0
def _CreateNDayActiveGraphSeries(num_graph_series):
  """Creates N_DAY_ACTIVE graphs for use in tests in this file.

  Args:
    num_graph_series: The number of graph series to create.

  Returns:
    A list of rdf_stats.ClientGraphSeries of type N_DAY_ACTIVE containing
    realistic test data.
  """
  graph_series_list = []
  for series_index in range(num_graph_series):
    graph_series = rdf_stats.ClientGraphSeries(
        report_type=rdf_stats.ClientGraphSeries.ReportType.N_DAY_ACTIVE)
    graph_series.graphs.Append(rdf_stats.Graph())
    for i, period in enumerate([1, 2, 3, 7, 14, 30, 60]):
      graph_series.graphs[0].Append(x_value=period, y_value=i * series_index)
      graph_series.graphs[0].Append(x_value=period, y_value=i * series_index)
    graph_series_list.append(graph_series)
  return graph_series_list
Ejemplo n.º 7
0
def _CreateGRRVersionGraphSeries(num_graph_series):
  """Creates GRR_VERSION graphs for use in tests in this file.

  Args:
    num_graph_series: The number of graph series to create.

  Returns:
    A list of rdf_stats.ClientGraphSeries of type GRR_VERSION containing
    realistic test data.
  """
  graph_series_list = []
  for series_index in range(num_graph_series):
    graph_series = rdf_stats.ClientGraphSeries(
        report_type=rdf_stats.ClientGraphSeries.ReportType.GRR_VERSION)
    for i, period in enumerate([1, 7, 14, 30]):
      graph = rdf_stats.Graph()
      graph.title = "%s day actives for %s label" % (period, _TEST_LABEL)
      graph.Append(label="GRR linux amd64 3000", y_value=i * series_index)
      graph.Append(label="GRR linux amd64 3001", y_value=i * series_index)
      graph_series.graphs.Append(graph)
    graph_series_list.append(graph_series)
  return graph_series_list