Skip to content

Commit

Permalink
Populate/show the db and redis access data in traffic report
Browse files Browse the repository at this point in the history
  • Loading branch information
rockychen-dpaw committed Oct 31, 2024
1 parent b484d50 commit e76cc7e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
51 changes: 46 additions & 5 deletions authome/admin/monitoradmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ def _domains(self,obj):
fields = ("_cluster","_start_time","_end_time","_serverlist","requests","_min_time","_max_time","_avg_time","_status","_domains","_batchid")

class TrafficDataAdmin(TrafficDataPropertyMixin,admin.DatetimeMixin,djangoadmin.ModelAdmin):
readonly_fields = ("_cluster","_start_time","_end_time","_serverlist","requests","_min_time","_max_time","_avg_time","get_remote_sessions","delete_remote_sessions","_status","_domains","_batchid")
fields = readonly_fields
ordering = ("-start_time","clusterid")
list_filter = ['clusterid']
inlines = [SSOMethodTrafficDataInline]
Expand Down Expand Up @@ -217,17 +215,60 @@ def _domains(self,obj):
return mark_safe("<pre>{}</pre>".format("\r\n".join(" {} : {}".format(o[0],json.dumps(o[1],sort_keys=True,indent=4) if isinstance(o[1],dict) else o[1]) for o in datas)))
_domains.short_description = "Groups"

if settings.REDIS_TRAFFIC_MONITOR_LEVEL > 0 and settings.DB_TRAFFIC_MONITOR_LEVEL > 0:
report_list_display_4_cluster = ("_report_type","_start_time","_cluster","requests","_min_time","_max_time","_avg_time","redis_requests","_redis_avg_time","db_requests","_db_avg_time","get_remote_sessions","delete_remote_sessions","_subreports")
report_list_display = ("_report_type","_start_time","_cluster","requests","_min_time","_max_time","_avg_time","redis_requests","_redis_avg_time","db_requests","_db_avg_time","_subreports")

report_fields_4_cluster = ("_cluster","_report_type","_start_time","_end_time","requests","_min_time","_max_time","_avg_time","redis_requests","_redis_avg_time","db_requests","_db_avg_time","get_remote_sessions","delete_remote_sessions","_status","_domains")
report_fields = ("_cluster","_report_type","_start_time","_end_time","requests","_min_time","_max_time","_avg_time","redis_requests","_redis_avg_time","db_requests","_db_avg_time","_status","_domains")
elif settings.REDIS_TRAFFIC_MONITOR_LEVEL > 0:
report_list_display_4_cluster = ("_report_type","_start_time","_cluster","requests","_min_time","_max_time","_avg_time","redis_requests","_redis_avg_time","get_remote_sessions","delete_remote_sessions","_subreports")
report_list_display = ("_report_type","_start_time","_cluster","requests","_min_time","_max_time","_avg_time","redis_requests","_redis_avg_time","_subreports")

report_fields_4_cluster = ("_cluster","_report_type","_start_time","_end_time","requests","_min_time","_max_time","_avg_time","redis_requests","_redis_avg_time","get_remote_sessions","delete_remote_sessions","_status","_domains")
report_fields = ("_cluster","_report_type","_start_time","_end_time","requests","_min_time","_max_time","_avg_time","redis_requests","_redis_avg_time","_status","_domains")
elif settings.DB_TRAFFIC_MONITOR_LEVEL > 0:
report_list_display_4_cluster = ("_report_type","_start_time","_cluster","requests","_min_time","_max_time","_avg_time","db_requests","_db_avg_time","get_remote_sessions","delete_remote_sessions","_subreports")
report_list_display = ("_report_type","_start_time","_cluster","requests","_min_time","_max_time","_avg_time","db_requests","_db_avg_time","_subreports")

report_fields_4_cluster = ("_cluster","_report_type","_start_time","_end_time","requests","_min_time","_max_time","_avg_time","db_requests","_db_avg_time","get_remote_sessions","delete_remote_sessions","_status","_domains")
report_fields = ("_cluster","_report_type","_start_time","_end_time","requests","_min_time","_max_time","_avg_time","db_requests","_db_avg_time","_status","_domains")
else:
report_list_display_4_cluster = ("_report_type","_start_time","_cluster","requests","_min_time","_max_time","_avg_time","get_remote_sessions","delete_remote_sessions","_subreports")
report_list_display = ("_report_type","_start_time","_cluster","requests","_min_time","_max_time","_avg_time","_subreports")

report_fields_4_cluster = ("_cluster","_report_type","_start_time","_end_time","requests","_min_time","_max_time","_avg_time","get_remote_sessions","delete_remote_sessions","_status","_domains")
report_fields = ("_cluster","_report_type","_start_time","_end_time","requests","_min_time","_max_time","_avg_time","_status","_domains")

class TrafficReportAdmin(TrafficDataPropertyMixin,admin.DatetimeMixin,djangoadmin.ModelAdmin):
list_display = ("_report_type","_start_time","_cluster","requests","_min_time","_max_time","_avg_time","get_remote_sessions","delete_remote_sessions","_subreports")
readonly_fields = ("_cluster","_report_type","_start_time","_end_time","requests","_min_time","_max_time","_avg_time","get_remote_sessions","delete_remote_sessions","_status","_domains")
fields = readonly_fields
ordering = ("report_type","-start_time",'clusterid')
list_filter = ['clusterid',"report_type"]
inlines = [SSOMethodTrafficReportInline]

traffic_data_list_url_name = 'admin:{}_{}_changelist'.format(models.TrafficData._meta.app_label,models.TrafficData._meta.model_name)
traffic_report_list_url_name = 'admin:{}_{}_changelist'.format(models.TrafficReport._meta.app_label,models.TrafficReport._meta.model_name)

@property
def list_display(self):
if settings.AUTH2_CLUSTER_ENABLED and cache.auth2_clusters:
return report_list_display_4_cluster
else:
return report_list_display

@property
def readonly_fields(self):
if settings.AUTH2_CLUSTER_ENABLED and cache.auth2_clusters:
return report_fields_4_cluster
else:
return report_fields

@property
def fields(self):
if settings.AUTH2_CLUSTER_ENABLED and cache.auth2_clusters:
return report_fields_4_cluster
else:
return report_fields

def _subreports(self,obj):
if not obj:
return ""
Expand Down
13 changes: 12 additions & 1 deletion authome/trafficdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _populate_reports():

if data.batchid == BATCHID_END:
continue
if not data.requests and not data.get_remote_sessions and not data.delete_remote_sessions:
if not data.requests and not data.get_remote_sessions and not data.delete_remote_sessions and not data.db_requests and not data.redis_requests:
#no requests
continue

Expand Down Expand Up @@ -228,7 +228,18 @@ def _populate_reports():
_add_avg(method_traffic_report.domains)
else:
method_traffic_report.domains = method_data.domains


method_traffic_report.changed = True

if method_data.sso_method == "Redis":
traffic_reports[method_report_key[0]].redis_requests = method_traffic_report.requests
traffic_reports[method_report_key[0]].redis_avg_time = method_traffic_report.avg_time
traffic_reports[method_report_key[0]].changed = True
elif method_data.sso_method == "DB":
traffic_reports[method_report_key[0]].db_requests = method_traffic_report.requests
traffic_reports[method_report_key[0]].db_avg_time = method_traffic_report.avg_time
traffic_reports[method_report_key[0]].changed = True

if not traffic_reports :
logger.info("No new traffic data and all traffic reports are latest.")

0 comments on commit e76cc7e

Please sign in to comment.