mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	feat: Count errors and gauge for heap memory (#10203)
This commit is contained in:
		
							parent
							
								
									4471b3ff00
								
							
						
					
					
						commit
						7c31ec71a1
					
				| @ -1,10 +1,25 @@ | ||||
| import type { IFlagResolver } from '../../../types/index.js'; | ||||
| 
 | ||||
| export const FEAUTRE_LINK_COUNT = 'feature_link_count'; | ||||
| export const CLIENT_ERROR_COUNT = 'client_error_count'; | ||||
| export const SERVER_ERROR_COUNT = 'server_error_count'; | ||||
| export const HEAP_MEMORY_TOTAL = 'heap_memory_total'; | ||||
| 
 | ||||
| export const defineImpactMetrics = (flagResolver: IFlagResolver) => { | ||||
|     flagResolver.impactMetrics?.defineCounter( | ||||
|         FEAUTRE_LINK_COUNT, | ||||
|         'Count of feature links', | ||||
|     ); | ||||
|     flagResolver.impactMetrics?.defineCounter( | ||||
|         CLIENT_ERROR_COUNT, | ||||
|         'Count of 4xx errors', | ||||
|     ); | ||||
|     flagResolver.impactMetrics?.defineCounter( | ||||
|         SERVER_ERROR_COUNT, | ||||
|         'Count of 5xx errors', | ||||
|     ); | ||||
|     flagResolver.impactMetrics?.defineGauge( | ||||
|         HEAP_MEMORY_TOTAL, | ||||
|         'Total heap memory used by the application process', | ||||
|     ); | ||||
| }; | ||||
|  | ||||
| @ -41,6 +41,7 @@ import { | ||||
| import type { SchedulerService } from './services/index.js'; | ||||
| import type { IClientMetricsEnv } from './features/metrics/client-metrics/client-metrics-store-v2-type.js'; | ||||
| import { DbMetricsMonitor } from './metrics-gauge.js'; | ||||
| import { HEAP_MEMORY_TOTAL } from './features/metrics/impact/define-impact-metrics.js'; | ||||
| 
 | ||||
| export function registerPrometheusPostgresMetrics( | ||||
|     db: Knex, | ||||
| @ -1137,6 +1138,10 @@ export function registerPrometheusMetrics( | ||||
|         collectAggDbMetrics: dbMetrics.refreshMetrics, | ||||
|         collectStaticCounters: async () => { | ||||
|             try { | ||||
|                 config.flagResolver.impactMetrics?.updateGauge( | ||||
|                     HEAP_MEMORY_TOTAL, | ||||
|                     process.memoryUsage().heapUsed, | ||||
|                 ); | ||||
|                 featureTogglesArchivedTotal.reset(); | ||||
|                 featureTogglesArchivedTotal.set( | ||||
|                     await instanceStatsService.getArchivedToggleCount(), | ||||
|  | ||||
| @ -1,14 +1,25 @@ | ||||
| import url from 'url'; | ||||
| import type { RequestHandler } from 'express'; | ||||
| import type { IUnleashConfig } from '../types/option.js'; | ||||
| import { | ||||
|     CLIENT_ERROR_COUNT, | ||||
|     SERVER_ERROR_COUNT, | ||||
| } from '../features/metrics/impact/define-impact-metrics.js'; | ||||
| 
 | ||||
| const requestLogger: (config: IUnleashConfig) => RequestHandler = (config) => { | ||||
|     const logger = config.getLogger('HTTP'); | ||||
|     const enable = config.server.enableRequestLogger; | ||||
|     const impactMetrics = config.flagResolver.impactMetrics; | ||||
|     return (req, res, next) => { | ||||
|         if (enable) { | ||||
|             res.on('finish', () => { | ||||
|                 const { pathname } = url.parse(req.originalUrl); | ||||
|                 if (res.statusCode >= 400 || res.statusCode < 500) { | ||||
|                     impactMetrics?.incrementCounter(CLIENT_ERROR_COUNT); | ||||
|                 } | ||||
|                 if (res.statusCode >= 500) { | ||||
|                     impactMetrics?.incrementCounter(SERVER_ERROR_COUNT); | ||||
|                 } | ||||
|                 logger.info(`${res.statusCode} ${req.method} ${pathname}`); | ||||
|             }); | ||||
|         } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user