本文整理汇总了Python中lib.cuckoo.core.database.Database.count_tasks方法的典型用法代码示例。如果您正苦于以下问题:Python Database.count_tasks方法的具体用法?Python Database.count_tasks怎么用?Python Database.count_tasks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.cuckoo.core.database.Database
的用法示例。
在下文中一共展示了Database.count_tasks方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import count_tasks [as 别名]
def index(request):
db = Database()
report = dict(
total_samples=db.count_samples(),
total_tasks=db.count_tasks(),
states_count={},
estimate_hour=None,
estimate_day=None
)
states = (
TASK_PENDING,
TASK_RUNNING,
TASK_COMPLETED,
TASK_RECOVERED,
TASK_REPORTED,
TASK_FAILED_ANALYSIS,
TASK_FAILED_PROCESSING,
TASK_FAILED_REPORTING
)
for state in states:
report["states_count"][state] = db.count_tasks(state)
offset = None
# For the following stats we're only interested in completed tasks.
tasks = db.list_tasks(offset=offset, status=TASK_COMPLETED)
tasks += db.list_tasks(offset=offset, status=TASK_REPORTED)
if tasks:
tasksubset = [x for x in tasks if timestamp(x.started_on) >= timestamp(datetime.datetime.today() - timedelta(days=30))]
# Get the time when the first task started.
started = min(timestamp(task.started_on) for task in tasksubset)
# Get the time when the last task completed.
completed = max(timestamp(task.completed_on) for task in tasksubset)
# Get the amount of tasks that actually completed.
finished = len(tasksubset)
# It has happened that for unknown reasons completed and started were
# equal in which case an exception is thrown, avoid this.
if int(completed - started):
hourly = 60 * 60 * finished / (completed - started)
else:
hourly = 0
report["estimate_hour"] = int(hourly)
report["estimate_day"] = int(24 * hourly)
return render_to_response("dashboard/index.html",
{"report" : report},
context_instance=RequestContext(request))
示例2: index
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import count_tasks [as 别名]
def index(request):
db = Database()
dbmx = DatabaseMX()
report = dict(
total_mails=dbmx.count_mails(),
total_malwares=dbmx.count_malwares(),
total_attachments=dbmx.count_attachments(),
total_urls=dbmx.count_urls(),
mails_have_malwares=dbmx.get_mails_have_malwares(),
total_samples=db.count_samples(),
total_tasks=db.count_tasks(),
states_count={},
estimate_hour=None,
estimate_day=None
)
states = (
TASK_PENDING,
TASK_RUNNING,
TASK_COMPLETED,
TASK_RECOVERED,
TASK_REPORTED,
TASK_FAILED_ANALYSIS,
TASK_FAILED_PROCESSING,
TASK_FAILED_REPORTING
)
for state in states:
report["states_count"][state] = db.count_tasks(state)
offset = None
# For the following stats we're only interested in completed tasks.
tasks = db.list_tasks(offset=offset, status=TASK_COMPLETED)
tasks += db.list_tasks(offset=offset, status=TASK_REPORTED)
if tasks:
# Get the time when the first task started.
started = min(timestamp(task.started_on) for task in tasks)
# Get the time when the last task completed.
completed = max(timestamp(task.completed_on) for task in tasks)
# Get the amount of tasks that actually completed.
finished = len(tasks)
hourly = 60 * 60 * finished / (completed - started)
report["estimate_hour"] = int(hourly)
report["estimate_day"] = int(24 * hourly)
return render_to_response("cuckoomx/index.html",
{"report" : report},
context_instance=RequestContext(request))
示例3: task_done
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import count_tasks [as 别名]
def task_done(tid_list):
"""Calculates number of completed URLs for a task
then compare with size of tid_list."""
db = Database()
tasks_count = db.count_tasks(status=TASK_COMPLETED, tid_list=tid_list)
tasks_count += db.count_tasks(status=TASK_REPORTED, tid_list=tid_list)
if tasks_count < len(tid_list):
return False
elif tasks_count == len(tid_list):
return True
示例4: main
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import count_tasks [as 别名]
def main():
db = Database()
print("%d samples in db" % db.count_samples())
print("%d tasks in db" % db.count_tasks())
states = (
TASK_PENDING,
TASK_RUNNING,
TASK_COMPLETED,
TASK_RECOVERED,
TASK_REPORTED,
TASK_FAILED_ANALYSIS,
TASK_FAILED_PROCESSING,
TASK_FAILED_REPORTING,
)
for state in states:
print("%s %d tasks" % (state, db.count_tasks(state)))
# Later on we might be interested in only calculating stats for all
# tasks starting at a certain offset, because the Cuckoo daemon may
# have been restarted at some point in time.
offset = None
# For the following stats we're only interested in completed tasks.
tasks = db.list_tasks(offset=offset, status=TASK_COMPLETED)
tasks += db.list_tasks(offset=offset, status=TASK_REPORTED)
if tasks:
# Get the time when the first task started.
started = min(timestamp(task.started_on) for task in tasks)
# Get the time when the last task completed.
stamps = []
for task in tasks:
try:
stamps.append(timestamp(task.completed_on))
except AttributeError:
pass
completed = max(stamps)
# Get the amount of tasks that actually completed.
finished = len(tasks)
hourly = 60 * 60 * finished / (completed - started)
print("roughly %d tasks an hour" % int(hourly))
print("roughly %d tasks a day" % int(24 * hourly))
示例5: index
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import count_tasks [as 别名]
def index(request):
db = Database()
report = dict(
total_samples=db.count_samples(),
total_tasks=db.count_tasks(),
states_count={},
estimate_hour=None,
estimate_day=None
)
states = (
TASK_PENDING,
TASK_RUNNING,
TASK_COMPLETED,
TASK_RECOVERED,
TASK_REPORTED,
TASK_FAILED_ANALYSIS,
TASK_FAILED_PROCESSING,
TASK_FAILED_REPORTING
)
for state in states:
report["states_count"][state] = db.count_tasks(state)
offset = None
# For the following stats we're only interested in completed tasks.
tasks = db.count_tasks(status=TASK_COMPLETED)
tasks += db.count_tasks(status=TASK_REPORTED)
if tasks:
# Get the time when the first task started and last one ended.
started, completed = db.minmax_tasks()
# It has happened that for unknown reasons completed and started were
# equal in which case an exception is thrown, avoid this.
if completed and started and int(completed - started):
hourly = 60 * 60 * tasks / (completed - started)
else:
hourly = 0
report["estimate_hour"] = int(hourly)
report["estimate_day"] = int(24 * hourly)
return render(request, "dashboard/index.html", {
"report": report,
})
示例6: delete_all
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import count_tasks [as 别名]
def delete_all():
"""Delete ALL tasks in Cuckoo's local processing queue."""
db = Database()
list = db.list_tasks()
if not list:
print(bold(red("Error")) + ": no tasks to be deleted")
else:
for url in list:
db.delete_task(db.count_tasks())
示例7: HealthStatistics
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import count_tasks [as 别名]
class HealthStatistics():
def __init__(self, simple=False):
self.simple = simple
self.style = {"fill": True,
"interpolate": "cubic",
"style": pygal.style.LightStyle}
self.db = Database()
self.datadir = os.path.join(CUCKOO_ROOT, "web", "static", "generated")
def all(self):
""" Generating all charts
"""
self.processing_stages_pie()
self.processing_time_bar()
self.task_status_pie()
self.task_success_by_machine_bar()
def processing_time_bar(self):
""" Processing time histogram for the tasks
"""
name = "processing_time.svg"
filename = os.path.join(self.datadir, name)
bar_chart = pygal.Bar(fill=self.style["fill"],
style=self.style["style"],
show_minor_y_labels=False,
x_title="Time in minutes",
y_title="Number of samples")
bar_chart.title = 'Processing time, histogram'
stages = ["full", "analysis", "processing", "signatures", "reporting"]
totalmax = 0
for stage in stages:
td = self.db.task_duration(stage=stage)
items = []
if td:
maxm = max(td) / 30
if maxm > totalmax:
totalmax = maxm
minm = min(td) / 30
for i in range(maxm, -1, -1):
total = 0
for res in td:
if res / 30 == i:
total = total + 1
items.append(total)
items.reverse()
if len(td):
bar_chart.add(stage, items)
bar_chart.x_labels = map(str, [x * 0.5 for x in range(0, totalmax + 1)])
bar_chart.render_to_file(filename)
if self.simple:
return name
else:
return filename
def processing_stages_pie(self):
""" Showing a pie chart for the stages and time they consume
"""
name = "stage_pie.svg"
filename = os.path.join(self.datadir, name)
stage_list = ["analysis", "processing", "signatures", "reporting"]
status_pie = pygal.Pie(fill=self.style["fill"],
interpolate=self.style["interpolate"],
style=self.style["style"])
status_pie.title = 'Stage percentage'
for i in stage_list:
td = self.db.task_duration(stage=i)
if len(td):
status_pie.add(i, sum(td))
status_pie.render_to_file(filename)
if self.simple:
return name
else:
return filename
def task_status_pie(self):
""" Showing a pie chart for the task status
"""
name = "status_pie.svg"
filename = os.path.join(self.datadir, name)
status_list = [TASK_COMPLETED, TASK_REPORTED, TASK_PENDING, TASK_RUNNING, TASK_RECOVERED,
TASK_FAILED_ANALYSIS, TASK_FAILED_PROCESSING]
status_pie = pygal.Pie(fill=self.style["fill"],
interpolate=self.style["interpolate"],
style=self.style["style"])
status_pie.title = 'Total task status'
for stat in status_list:
status_pie.add(stat, self.db.count_tasks(stat))
status_pie.render_to_file(filename)
if self.simple:
return name
else:
return filename
def task_analysis_pie(self):
""" Showing a pie chart for the task analysis. Viewing problems and issues like Anti-VM, crashes, ...
"""
name = "analysis_issues_pie.svg"
filename = os.path.join(self.datadir, name)
#.........这里部分代码省略.........