perf: dashboard

pull/14789/head
feng 2025-01-09 16:11:37 +08:00 committed by feng626
parent 96dc7db027
commit a911b50df0
2 changed files with 47 additions and 20 deletions

View File

@ -4,7 +4,10 @@ from django.db.models import Count, F, Q
from django.http.response import JsonResponse
from rest_framework.views import APIView
from accounts.models import Account, RiskChoice
from accounts.models import (
Account, RiskChoice, GatherAccountsAutomation,
PushAccountAutomation, BackupAccountAutomation, AccountRisk, IntegrationApplication
)
from assets.const import AllTypes
from common.utils.timezone import local_monday
@ -85,9 +88,34 @@ class PamDashboardApi(APIView):
data['total_long_time_change_password_accounts'] = Account.get_risks(
risk_type=RiskChoice.long_time_password).count()
if _all or query_params.get('total_count_type_to_accounts_amount'):
if _all or query_params.get('total_count_type_to_accounts'):
data.update({
'total_count_type_to_accounts_amount': self.get_type_to_accounts(),
'total_count_type_to_accounts': self.get_type_to_accounts(),
})
if _all or query_params.get('total_count_gathered_account_automation'):
data.update({
'total_count_gathered_account_automation': GatherAccountsAutomation.objects.count()
})
if _all or query_params.get('total_count_push_account_automation'):
data.update({
'total_count_push_account_automation': PushAccountAutomation.objects.count()
})
if _all or query_params.get('total_count_backup_account_automation'):
data.update({
'total_count_backup_account_automation': BackupAccountAutomation.objects.count()
})
if _all or query_params.get('total_count_risk_account'):
data.update({
'total_count_risk_account': AccountRisk.objects.count()
})
if _all or query_params.get('total_count_integration_application'):
data.update({
'total_count_integration_application': IntegrationApplication.objects.count()
})
return JsonResponse(data, status=200)

View File

@ -117,28 +117,26 @@ class ChangeSecretDashboardApi(APIView):
query_params = self.request.query_params
data = {}
if query_params.get('total_count_change_secrets'):
_all = query_params.get('all')
if _all or query_params.get('total_count_change_secrets'):
data['total_count_change_secrets'] = self.get_filtered_counts(
self.change_secrets_queryset, 'date_updated'
)
if query_params.get('total_count_periodic_change_secrets'):
if _all or query_params.get('total_count_periodic_change_secrets'):
data['total_count_periodic_change_secrets'] = self.get_filtered_counts(
self.change_secrets_queryset.filter(is_periodic=True), 'date_updated'
)
if query_params.get('total_count_change_secret_assets'):
if _all or query_params.get('total_count_change_secret_assets'):
data['total_count_change_secret_assets'] = self.get_change_secret_asset_queryset().count()
if query_params.get('total_count_change_secret_status'):
if _all or query_params.get('total_count_change_secret_status'):
records = self.get_queryset_date_filter(self.change_secret_records_queryset, 'date_finished')
data.update(self.get_status_counts(records))
if query_params.get('total_count_change_secret_status'):
records = self.get_queryset_date_filter(self.change_secret_records_queryset, 'date_finished')
data.update(self.get_status_counts(records))
if query_params.get('daily_success_and_failure_metrics'):
if _all or query_params.get('daily_success_and_failure_metrics'):
success, failed = self.get_daily_success_and_failure_metrics()
data.update({
'dates_metrics_date': [date.strftime('%m-%d') for date in self.date_range_list] or ['0'],
@ -146,10 +144,11 @@ class ChangeSecretDashboardApi(APIView):
'dates_metrics_total_count_failed': failed,
})
if query_params.get('total_count_ongoing_change_secret'):
if _all or query_params.get('total_count_ongoing_change_secret'):
execution_ids = []
inspect = app.control.inspect()
active_tasks = inspect.active()
if active_tasks:
for tasks in active_tasks.values():
for task in tasks:
_id = task.get('id')