diff --git a/packages/api/src/handlers/redisStats.ts b/packages/api/src/handlers/redisStats.ts index 107d89cb..ec1eb2f1 100644 --- a/packages/api/src/handlers/redisStats.ts +++ b/packages/api/src/handlers/redisStats.ts @@ -2,24 +2,6 @@ import { parse as parseRedisInfo } from 'redis-info'; import { BullBoardRequest, ControllerHandlerReturnType, RedisStats } from '../../typings/app'; import { BaseAdapter } from '../queueAdapters/base'; -function formatUptime(uptime: number) { - const date = new Date(uptime * 1000); - const days = date.getUTCDate() - 1, - hours = date.getUTCHours(), - minutes = date.getUTCMinutes(), - seconds = date.getUTCSeconds(); - - // Initialize an array for the uptime. - const segments = []; - - // Format the uptime string. - if (days > 0) segments.push(days + ' day' + (days == 1 ? '' : 's')); - if (hours > 0) segments.push(hours + ' hour' + (hours == 1 ? '' : 's')); - if (minutes > 0) segments.push(minutes + ' minute' + (minutes == 1 ? '' : 's')); - if (seconds > 0 && days === 0) segments.push(seconds + ' second' + (seconds == 1 ? '' : 's')); - return segments.join(', '); -} - async function getStats(queue: BaseAdapter): Promise { const redisInfoRaw = await queue.getRedisInfo(); const redisInfo = parseRedisInfo(redisInfoRaw); @@ -29,7 +11,7 @@ async function getStats(queue: BaseAdapter): Promise { mode: redisInfo.redis_mode, port: +redisInfo.tcp_port, os: redisInfo.os, - uptime: formatUptime(+redisInfo.uptime_in_seconds), + uptime: +redisInfo.uptime_in_seconds, memory: { total: +redisInfo.total_system_memory || +redisInfo.maxmemory, used: +redisInfo.used_memory, diff --git a/packages/api/typings/app.ts b/packages/api/typings/app.ts index f64a3326..febd3736 100644 --- a/packages/api/typings/app.ts +++ b/packages/api/typings/app.ts @@ -81,7 +81,7 @@ export interface RedisStats { mode: RedisInfo['redis_mode']; port: number; os: string; - uptime: string; + uptime: number; memory: { total: number; used: number; @@ -241,4 +241,4 @@ export type DateFormats = { * @see https://date-fns.org/v3.6.0/docs/format */ full?: string; -} +}; diff --git a/packages/ui/src/components/RedisStatsModal/RedisStatsModal.tsx b/packages/ui/src/components/RedisStatsModal/RedisStatsModal.tsx index 0c41bcd1..62254557 100644 --- a/packages/ui/src/components/RedisStatsModal/RedisStatsModal.tsx +++ b/packages/ui/src/components/RedisStatsModal/RedisStatsModal.tsx @@ -1,9 +1,11 @@ import { RedisStats } from '@bull-board/api/typings/app'; +import { formatDistance } from 'date-fns'; import formatBytes from 'pretty-bytes'; import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useApi } from '../../hooks/useApi'; import { useInterval } from '../../hooks/useInterval'; +import { dateFnsLocale } from '../../services/i18n'; import { Modal } from '../Modal/Modal'; import s from './RedisStatsModal.module.css'; @@ -62,7 +64,13 @@ export const RedisStatsModal = ({ open, onClose }: RedisStatsModalProps) => { { title: t('REDIS.VERSION'), value: stats.version }, { title: t('REDIS.MODE'), value: stats.mode }, { title: t('REDIS.OS'), value: stats.os }, - { title: t('REDIS.UP_TIME'), value: stats.uptime }, + { + title: t('REDIS.UP_TIME'), + value: formatDistance(0, stats.uptime * 1000, { + includeSeconds: true, + locale: dateFnsLocale, + }), + }, ]; return (