-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User session bug fixes plus initial prometeus instrumentation.
- Loading branch information
1 parent
9fd2849
commit 64231d9
Showing
7 changed files
with
706 additions
and
318 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 |
---|---|---|
@@ -1,6 +1,14 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
} | ||
async rewrites() { | ||
return [ | ||
{ | ||
source: "/metrics", | ||
destination: "/api/prometheus", | ||
}, | ||
]; | ||
}, | ||
}; | ||
|
||
module.exports = nextConfig | ||
module.exports = nextConfig; |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { NextApiResponse } from "next"; | ||
import { | ||
Counter, | ||
CounterConfiguration, | ||
collectDefaultMetrics, | ||
register, | ||
} from "prom-client"; | ||
|
||
const getOrCreateCounter = <T extends string>( | ||
i: CounterConfiguration<T> | ||
): Counter<T> => { | ||
const existingMetric = register.getSingleMetric("seconds_spoken_total"); | ||
|
||
if (existingMetric) { | ||
return existingMetric as Counter<T>; | ||
} | ||
|
||
return new Counter(i); | ||
}; | ||
|
||
// Create a custom counter metric for counting HTTP requests | ||
export const minutesSpoken = getOrCreateCounter({ | ||
name: "seconds_spoken_total", | ||
help: "Total number of seconds that a user has spoken.", | ||
labelNames: ["user_id"], | ||
}); | ||
if (!(global as any).defaultMetricsInitialized) { | ||
collectDefaultMetrics(); | ||
(global as any).defaultMetricsInitialized = true; | ||
} | ||
|
||
// Export a middleware function to expose a /metrics endpoint | ||
export default async function (_: unknown, res: NextApiResponse) { | ||
res.setHeader("Content-Type", register.contentType); | ||
res.end(await register.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
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