def Save(self, fd): """Generate a histogram object and store in the specified attribute.""" histogram = self.attribute() for active_time in self.active_days: graph = stats.Graph(title="%s day actives" % active_time) for k, v in sorted(self.categories[active_time].items()): graph.Append(label=k, y_value=v) histogram.Append(graph) # Add an additional instance of this histogram (without removing previous # instances). fd.AddAttribute(histogram)
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].keys(): histograms.setdefault(label, self.attribute()) graph = rdfstats.Graph( title="%s day actives for %s label" % (active_time, label)) for k, v in sorted(self.categories[active_time][label].items()): graph.Append(label=k, y_value=v) histograms[label].Append(graph) for label, histogram in histograms.items(): # Add an additional instance of this histogram (without removing previous # instances). cron_flow._StatsForLabel(label).AddAttribute(histogram)
def Layout(self, request, response): """Filter the last week of user actions.""" try: offset = rdfvalue.Duration("7d") now = rdfvalue.RDFDatetime().Now() counts = {} for event in GetAuditLogEntries(offset, now, request.token): counts.setdefault(event.user, 0) counts[event.user] += 1 self.graph = rdf_stats.Graph(title="User activity breakdown.") self.data = [] for user, count in counts.items(): if user not in aff4_users.GRRUser.SYSTEM_USERS: self.graph.Append(label=user, y_value=count) self.data.append(dict(label=user, data=count)) except IOError: pass return super(MostActiveUsers, self).Layout(request, response)
def PopulateData(): """Populates data into the stats object.""" token = access_control.ACLToken(username="******", reason="fixture") with aff4.FACTORY.Create("aff4:/stats/ClientFleetStats/All", "ClientFleetStats", token=token) as fd: now = 1321057655 for i in range(10, 15): histogram = fd.Schema.OS_HISTOGRAM(age=int( (now + i * 60 * 60 * 24) * 1e6)) for number in [1, 7, 14, 30]: graph = rdf_stats.Graph(title="%s day actives" % number) graph.Append(label="Windows", y_value=i + number) graph.Append(label="Linux", y_value=i * 2 + number) histogram.Append(graph) fd.AddAttribute(histogram)