fix(dnscaching): display stats for DNS caching (#1858)

* fix(dnscaching): display stats for DNS caching

* fix: add missing translation
This commit is contained in:
Gauthier
2025-08-20 11:32:59 +02:00
committed by GitHub
parent d3fd5028dc
commit 368ecf8771
7 changed files with 20 additions and 50 deletions

View File

@@ -1,3 +1,4 @@
import type { DnsEntries, DnsStats } from 'dns-caching';
import type { PaginatedResponse } from './common';
export type LogMessage = {
@@ -61,38 +62,12 @@ export interface CacheItem {
};
}
export interface DNSAddresses {
ipv4: number;
ipv6: number;
}
export interface DNSRecord {
addresses: DNSAddresses;
activeAddress: string;
family: number;
age: number;
ttl: number;
networkErrors: number;
hits: number;
misses: number;
}
export interface DNSStats {
size: number;
maxSize: number;
hits: number;
misses: number;
failures: number;
ipv4Fallbacks: number;
hitRate: number;
}
export interface CacheResponse {
apiCaches: CacheItem[];
imageCache: Record<'tmdb' | 'avatar', { size: number; imageCount: number }>;
dnsCache: {
entries: Record<string, DNSRecord>;
stats: DNSStats;
stats: DnsStats | undefined;
entries: DnsEntries | undefined;
};
}

View File

@@ -28,8 +28,9 @@ import discoverSettingRoutes from '@server/routes/settings/discover';
import { ApiError } from '@server/types/error';
import { appDataPath } from '@server/utils/appDataVolume';
import { getAppVersion } from '@server/utils/appVersion';
import dnsCache from '@server/utils/dnsCache';
import { dnsCache } from '@server/utils/dnsCache';
import { getHostname } from '@server/utils/getHostname';
import type { DnsEntries, DnsStats } from 'dns-caching';
import { Router } from 'express';
import rateLimit from 'express-rate-limit';
import fs from 'fs';
@@ -756,8 +757,8 @@ settingsRoutes.get('/cache', async (_req, res) => {
const tmdbImageCache = await ImageProxy.getImageStats('tmdb');
const avatarImageCache = await ImageProxy.getImageStats('avatar');
const stats = dnsCache?.getStats();
const entries = dnsCache?.getCacheEntries();
const stats: DnsStats | undefined = dnsCache?.getStats();
const entries: DnsEntries | undefined = dnsCache?.getCacheEntries();
return res.status(200).json({
apiCaches,

View File

@@ -1,7 +1,7 @@
import logger from '@server/logger';
import { DnsCacheManager } from 'dns-caching';
let dnsCache: DnsCacheManager | undefined;
export let dnsCache: DnsCacheManager | undefined;
export function initializeDnsCache({
forceMinTtl,
@@ -24,5 +24,3 @@ export function initializeDnsCache({
});
dnsCache.initialize();
}
export default dnsCache;