InspectStatsTab.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React from 'react';
  2. import { PanelData, QueryResultMetaStat, TimeZone } from '@grafana/data';
  3. import { selectors } from '@grafana/e2e-selectors';
  4. import { InspectStatsTable } from './InspectStatsTable';
  5. interface InspectStatsTabProps {
  6. data: PanelData;
  7. timeZone: TimeZone;
  8. }
  9. export const InspectStatsTab: React.FC<InspectStatsTabProps> = ({ data, timeZone }) => {
  10. if (!data.request) {
  11. return null;
  12. }
  13. let stats: QueryResultMetaStat[] = [];
  14. const requestTime = data.request.endTime ? data.request.endTime - data.request.startTime : -1;
  15. const processingTime = data.timings?.dataProcessingTime || -1;
  16. let dataRows = 0;
  17. for (const frame of data.series) {
  18. dataRows += frame.length;
  19. }
  20. if (requestTime > 0) {
  21. stats.push({ displayName: 'Total request time', value: requestTime, unit: 'ms' });
  22. }
  23. if (processingTime > 0) {
  24. stats.push({ displayName: 'Data processing time', value: processingTime, unit: 'ms' });
  25. }
  26. stats.push({ displayName: 'Number of queries', value: data.request.targets.length });
  27. stats.push({ displayName: 'Total number rows', value: dataRows });
  28. let dataStats: QueryResultMetaStat[] = [];
  29. for (const series of data.series) {
  30. if (series.meta && series.meta.stats) {
  31. dataStats = dataStats.concat(series.meta.stats);
  32. }
  33. }
  34. return (
  35. <div aria-label={selectors.components.PanelInspector.Stats.content}>
  36. <InspectStatsTable timeZone={timeZone} name={'Stats'} stats={stats} />
  37. <InspectStatsTable timeZone={timeZone} name={'Data source stats'} stats={dataStats} />
  38. </div>
  39. );
  40. };