mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-01 23:38:37 +00:00
Update statistic-metrics.js
This commit is contained in:
parent
bd79368b9d
commit
2b9311b82c
@ -12,11 +12,16 @@ class MetricCard extends Component {
|
|||||||
<div className="metric-card">
|
<div className="metric-card">
|
||||||
<div className="card mb-4">
|
<div className="card mb-4">
|
||||||
<div className="card-header">
|
<div className="card-header">
|
||||||
<h5 className="mb-0">
|
<div className="metric-title-row">
|
||||||
{metric.name}
|
<span className="metric-name">{metric.name}</span>
|
||||||
<small className="text-muted ml-2">{metric.type}</small>
|
<span className="metric-type">{metric.type}</span>
|
||||||
</h5>
|
{metric.help && (
|
||||||
{metric.help && <p className="text-muted mb-0">{metric.help}</p>}
|
<span className="metric-help">
|
||||||
|
<span className="help-label">help:</span>
|
||||||
|
{metric.help}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="card-body">
|
<div className="card-body">
|
||||||
<table className="table table-hover mb-0">
|
<table className="table table-hover mb-0">
|
||||||
@ -103,24 +108,61 @@ class StatisticMetrics extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加样式
|
|
||||||
const style = `
|
const style = `
|
||||||
<style>
|
<style>
|
||||||
.metrics-container {
|
|
||||||
padding: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.metric-card .card-header {
|
.metric-card .card-header {
|
||||||
background-color: #f8f9fa;
|
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 {
|
.metric-card .table {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.metric-card .table td,
|
|
||||||
.metric-card .table th {
|
.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 {
|
.loading-tip {
|
||||||
|
@ -482,7 +482,7 @@ class SystemMetricsView(APIView):
|
|||||||
throttle_classes = (UserRateThrottle,)
|
throttle_classes = (UserRateThrottle,)
|
||||||
permission_classes = (IsAdminUser,)
|
permission_classes = (IsAdminUser,)
|
||||||
|
|
||||||
def parse_prometheus_metrics(self, metrics_raw):
|
def _parse_prometheus_metrics(self, metrics_raw):
|
||||||
"""Parse prometheus metrics"""
|
"""Parse prometheus metrics"""
|
||||||
metrics_dict = {}
|
metrics_dict = {}
|
||||||
|
|
||||||
@ -539,12 +539,18 @@ class SystemMetricsView(APIView):
|
|||||||
return list(metrics_dict.values())
|
return list(metrics_dict.values())
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
res = get_seafevents_metrics()
|
if not request.user.admin_permissions.can_view_statistic():
|
||||||
metrics_raw = res.content.decode('utf-8')
|
return api_error(status.HTTP_403_FORBIDDEN, 'Permission denied.')
|
||||||
|
|
||||||
metrics_data = self.parse_prometheus_metrics(metrics_raw)
|
|
||||||
|
|
||||||
|
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({
|
return Response({
|
||||||
'metrics': metrics_data,
|
'metrics': metrics_data,
|
||||||
'timestamp': datetime.datetime.now().isoformat()
|
})
|
||||||
})
|
|
||||||
|
@ -1184,8 +1184,8 @@ def check_metric_auth(auth_header):
|
|||||||
def get_metrics(request):
|
def get_metrics(request):
|
||||||
if not ENABLE_METRIC:
|
if not ENABLE_METRIC:
|
||||||
return Http404
|
return Http404
|
||||||
# auth_header = request.META.get('HTTP_AUTHORIZATION')
|
auth_header = request.META.get('HTTP_AUTHORIZATION')
|
||||||
# if not auth_header or not check_metric_auth(auth_header):
|
if not auth_header or not check_metric_auth(auth_header):
|
||||||
# return HttpResponseForbidden('Invalid Authentication')
|
return HttpResponseForbidden('Invalid Authentication')
|
||||||
metrics = get_seafevents_metrics()
|
metrics = get_seafevents_metrics()
|
||||||
return HttpResponse(metrics, content_type='text/plain')
|
return HttpResponse(metrics, content_type='text/plain')
|
||||||
|
Loading…
Reference in New Issue
Block a user