File tree 5 files changed +937
-368
lines changed 5 files changed +937
-368
lines changed Original file line number Diff line number Diff line change
1
+ import { StatsD } from "node-statsd" ;
2
+ import { config } from "dotenv" ;
3
+
4
+ config ( ) ; // load env vars
5
+
6
+ const environment = process . env . NODE_ENV ;
7
+ const graphite = process . env . GRAPHITE_HOST ;
8
+
9
+ if ( graphite === null ) throw new Error ( "Graphite host is not configured" ) ;
10
+
11
+ const options = {
12
+ host : graphite ,
13
+ port : 8125 ,
14
+ prefix : `${ environment } .sprig.`
15
+ } ;
16
+
17
+ const metrics = new StatsD ( options ) ;
18
+
19
+ export default metrics ;
Original file line number Diff line number Diff line change 23
23
"@lezer/common" : " ^1.0.2" ,
24
24
"@preact/signals" : " ^1.1.3" ,
25
25
"@sendgrid/mail" : " ^7.7.0" ,
26
- "astro" : " ^2.0.4" ,
26
+ "astro" : " 2.7.0" ,
27
+ "dotenv" : " ^16.3.1" ,
27
28
"esprima" : " ^4.0.1" ,
28
- "firebase-admin" : " ^11.5.0 " ,
29
+ "firebase-admin" : " ^11.10.1 " ,
29
30
"ms" : " ^2.1.3" ,
30
31
"nanoid" : " ^4.0.1" ,
32
+ "node-statsd" : " ^0.1.1" ,
31
33
"preact" : " ^10.6.5" ,
32
34
"react-icons" : " ^4.7.1" ,
33
35
"rehype-external-links" : " ^2.0.1" ,
Original file line number Diff line number Diff line change
1
+ /// <reference path="../.astro/types.d.ts" />
1
2
/// <reference types="astro/client" />
2
3
3
4
interface ImportMetaEnv {
Original file line number Diff line number Diff line change
1
+ import metrics from "../metrics" ;
2
+
3
+ export async function onRequest ( { request } : any , next : ( ) => any ) {
4
+ const url = request . url ;
5
+
6
+ if ( ! url . includes ( "api" ) ) return next ( ) ;
7
+
8
+ const metricName = url . split ( "/" ) . slice ( 3 ) . join ( "_" ) ;
9
+ const response = await next ( ) ;
10
+
11
+ const metricKey = `${ response . status } .${ metricName } ` ;
12
+ console . log ( metricKey ) ;
13
+ metrics . increment ( metricKey , 1 ) ;
14
+ }
You can’t perform that action at this time.
0 commit comments