blob: bb1c2443889cf0722d57ebecdacc5cfe9647c582 [file] [log] [blame]
TRM-coding85e5c322025-06-18 19:49:21 +08001import React, { useState, useEffect } from 'react';
2import {
3 ResponsiveContainer, LineChart, Line,
4 XAxis, YAxis, Tooltip, CartesianGrid, Legend
5} from 'recharts';
6import { fetchSysCost } from '../api/posts_trm';
7
8function PerformanceLogs({ userId }) {
9 const [data, setData] = useState([]);
10
11 useEffect(() => {
12 fetchSysCost(userId)
13 .then(list => setData(list))
14 .catch(err => console.error('fetchSysCost error:', err));
15 }, [userId]);
16
17 return (
18 <section className="dashboard-performance">
19 <ResponsiveContainer width="100%" height={400}>
20 <LineChart
21 data={data}
22 margin={{ top: 20, right: 30, left: 20, bottom: 5 }}
23 >
24 <CartesianGrid strokeDasharray="3 3" />
25 <XAxis dataKey="record_time" />
26 <YAxis
27 domain={[0, 'auto']}
28 label={{ value: '时间 (s)', angle: -90, position: 'insideLeft' }}
29 tickFormatter={val => (val / 1000).toFixed(2)}
30 />
31 <Tooltip formatter={val => (typeof val === 'number' ? (val/1000).toFixed(2) + 's' : val)} />
32 <Legend />
33 <Line type="monotone" dataKey="elapsed_time" stroke="#8884d8" name="响应时间" />
34 <Line type="monotone" dataKey="cpu_user" stroke="#82ca9d" name="CPU 用户时间" />
35 <Line type="monotone" dataKey="cpu_system" stroke="#ffc658" name="CPU 系统时间" />
36 <Line type="monotone" dataKey="memory_rss" stroke="#ff7300" name="内存 RSS" />
37 {/* 如需更多指标,可再添其他 <Line /> */}
38 </LineChart>
39 </ResponsiveContainer>
40 </section>
41 );
42}
43
44export default PerformanceLogs;