@@ -64,6 +64,68 @@ Total number of HTTP requests, labeled by:
6464- ` route ` - Request route/path
6565- ` status_code ` - HTTP status code
6666
67+ ### GraphQL Metrics
68+
69+ #### hawk_gql_operation_duration_seconds (Histogram)
70+
71+ Histogram of total GraphQL operation duration by operation name and type.
72+
73+ Labels:
74+ - ` operation_name ` - Name of the GraphQL operation
75+ - ` operation_type ` - Type of operation (query, mutation, subscription)
76+
77+ Buckets: 0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10 seconds
78+
79+ ** Purpose** : Identify slow API operations (P95/P99 latency).
80+
81+ #### hawk_gql_operation_errors_total (Counter)
82+
83+ Counter of failed GraphQL operations grouped by operation name and error class.
84+
85+ Labels:
86+ - ` operation_name ` - Name of the GraphQL operation
87+ - ` error_type ` - Type/class of the error
88+
89+ ** Purpose** : Detect increased error rates and failing operations.
90+
91+ #### hawk_gql_resolver_duration_seconds (Histogram)
92+
93+ Histogram of resolver execution time per type, field, and operation.
94+
95+ Labels:
96+ - ` type_name ` - GraphQL type name
97+ - ` field_name ` - Field name being resolved
98+ - ` operation_name ` - Name of the GraphQL operation
99+
100+ Buckets: 0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5 seconds
101+
102+ ** Purpose** : Find slow or CPU-intensive resolvers that degrade overall performance.
103+
104+ ### MongoDB Metrics
105+
106+ #### hawk_mongo_command_duration_seconds (Histogram)
107+
108+ Histogram of MongoDB command duration by command, collection, and database.
109+
110+ Labels:
111+ - ` command ` - MongoDB command name (find, insert, update, etc.)
112+ - ` collection ` - Collection name
113+ - ` db ` - Database name
114+
115+ Buckets: 0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 5, 10 seconds
116+
117+ ** Purpose** : Detect slow queries and high-latency collections.
118+
119+ #### hawk_mongo_command_errors_total (Counter)
120+
121+ Counter of failed MongoDB commands grouped by command and error code.
122+
123+ Labels:
124+ - ` command ` - MongoDB command name
125+ - ` error_code ` - MongoDB error code
126+
127+ ** Purpose** : Track transient or persistent database errors.
128+
67129## Testing
68130
69131### Manual Testing
@@ -98,11 +160,24 @@ The metrics implementation uses the `prom-client` library and consists of:
98160 - Initializes a Prometheus registry
99161 - Configures default Node.js metrics collection
100162 - Defines custom HTTP metrics (duration histogram and request counter)
163+ - Registers GraphQL and MongoDB metrics
101164 - Provides middleware for tracking HTTP requests
102165 - Creates a separate Express app for serving metrics
103166
104- 2 . ** Integration** (` src/index.ts ` ):
167+ 2 . ** GraphQL Metrics** (` src/metrics/graphql.ts ` ):
168+ - Implements Apollo Server plugin for tracking GraphQL operations
169+ - Tracks operation duration, errors, and resolver execution time
170+ - Automatically captures operation name, type, and field information
171+
172+ 3 . ** MongoDB Metrics** (` src/metrics/mongodb.ts ` ):
173+ - Implements MongoDB command monitoring
174+ - Tracks command duration and errors
175+ - Uses MongoDB's command monitoring events
176+
177+ 4 . ** Integration** (` src/index.ts ` , ` src/mongo.ts ` ):
178+ - Adds GraphQL metrics plugin to Apollo Server
105179 - Adds metrics middleware to the main Express app
180+ - Enables MongoDB command monitoring on database clients
106181 - Starts metrics server on a separate port
107182 - Keeps metrics server isolated from main API traffic
108183
0 commit comments