forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8d2b65
commit d602014
Showing
5 changed files
with
937 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { StatsD } from "node-statsd"; | ||
import { config } from "dotenv"; | ||
|
||
config(); // load env vars | ||
|
||
const environment = process.env.NODE_ENV; | ||
const graphite = process.env.GRAPHITE_HOST; | ||
|
||
if (graphite === null) throw new Error("Graphite host is not configured"); | ||
|
||
const options = { | ||
host: graphite, | ||
port: 8125, | ||
prefix: `${environment}.sprig.` | ||
}; | ||
|
||
const metrics = new StatsD(options); | ||
|
||
export default metrics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/// <reference path="../.astro/types.d.ts" /> | ||
/// <reference types="astro/client" /> | ||
|
||
interface ImportMetaEnv { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import metrics from "../metrics"; | ||
|
||
export async function onRequest({ request }: any, next: () => any) { | ||
const url = request.url; | ||
|
||
if (!url.includes("api")) return next(); | ||
|
||
const metricName = url.split("/").slice(3).join("_"); | ||
const response = await next(); | ||
|
||
const metricKey = `${response.status}.${metricName}`; | ||
console.log(metricKey); | ||
metrics.increment(metricKey, 1); | ||
} |
Oops, something went wrong.