1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-05-11 01:17:02 +00:00

Update statistic-metrics.js

This commit is contained in:
孙永强 2025-04-02 10:17:13 +08:00
parent bd79368b9d
commit 2b9311b82c
3 changed files with 71 additions and 23 deletions
frontend/src/pages/sys-admin/statistic
seahub
api2/endpoints/admin
views

View File

@ -12,11 +12,16 @@ class MetricCard extends Component {
<div className="metric-card">
<div className="card mb-4">
<div className="card-header">
<h5 className="mb-0">
{metric.name}
<small className="text-muted ml-2">{metric.type}</small>
</h5>
{metric.help && <p className="text-muted mb-0">{metric.help}</p>}
<div className="metric-title-row">
<span className="metric-name">{metric.name}</span>
<span className="metric-type">{metric.type}</span>
{metric.help && (
<span className="metric-help">
<span className="help-label">help:</span>
{metric.help}
</span>
)}
</div>
</div>
<div className="card-body">
<table className="table table-hover mb-0">
@ -103,24 +108,61 @@ class StatisticMetrics extends Component {
}
}
// 添加样式
const style = `
<style>
.metrics-container {
padding: 1rem;
}
.metric-card .card-header {
background-color: #f8f9fa;
padding: 15px 20px;
}
.metric-card .metric-title-row {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
}
.metric-card .metric-name {
font-size: 16px;
font-weight: 600;
color: #333;
}
.metric-card .metric-type {
display: inline-block;
padding: 2px 8px;
font-size: 13px;
font-weight: normal;
color: #fff;
background-color: #17a2b8;
border-radius: 3px;
}
.metric-card .metric-help {
color: #666;
font-size: 14px;
}
.metric-card .help-label {
color: #888;
margin-right: 6px;
}
.metric-card .table {
margin-bottom: 0;
}
.metric-card .table td,
.metric-card .table th {
padding: 0.5rem;
background-color: #f8f9fa;
border-top: none;
}
.metric-card .table td {
vertical-align: middle;
}
.metrics-container {
padding: 1rem;
}
.loading-tip {

View File

@ -482,7 +482,7 @@ class SystemMetricsView(APIView):
throttle_classes = (UserRateThrottle,)
permission_classes = (IsAdminUser,)
def parse_prometheus_metrics(self, metrics_raw):
def _parse_prometheus_metrics(self, metrics_raw):
"""Parse prometheus metrics"""
metrics_dict = {}
@ -539,12 +539,18 @@ class SystemMetricsView(APIView):
return list(metrics_dict.values())
def get(self, request):
res = get_seafevents_metrics()
metrics_raw = res.content.decode('utf-8')
metrics_data = self.parse_prometheus_metrics(metrics_raw)
if not request.user.admin_permissions.can_view_statistic():
return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied.')
try:
res = get_seafevents_metrics()
metrics_raw = res.content.decode('utf-8')
metrics_data = self._parse_prometheus_metrics(metrics_raw)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
return Response({
'metrics': metrics_data,
'timestamp': datetime.datetime.now().isoformat()
})
'metrics': metrics_data,
})

View File

@ -1184,8 +1184,8 @@ def check_metric_auth(auth_header):
def get_metrics(request):
if not ENABLE_METRIC:
return Http404
# auth_header = request.META.get('HTTP_AUTHORIZATION')
# if not auth_header or not check_metric_auth(auth_header):
# return HttpResponseForbidden('Invalid Authentication')
auth_header = request.META.get('HTTP_AUTHORIZATION')
if not auth_header or not check_metric_auth(auth_header):
return HttpResponseForbidden('Invalid Authentication')
metrics = get_seafevents_metrics()
return HttpResponse(metrics, content_type='text/plain')