-
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.
- Loading branch information
1 parent
b119e7c
commit 2bf196f
Showing
3 changed files
with
68 additions
and
10 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
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,31 @@ | ||
import { Counter, register } from "prom-client"; | ||
import type { Telegraf } from "telegraf"; | ||
import type { MessageSubType } from "telegraf/typings/telegram-types"; | ||
import type { Ctx } from "./types"; | ||
|
||
const promMessageCounter = new Counter({ | ||
name: "tg_messages_total", | ||
help: "Message counter", | ||
labelNames: ["media_type"], | ||
}); | ||
|
||
const promUpdateTypes: MessageSubType[] = [ | ||
"text", | ||
"photo", | ||
"sticker", | ||
"photo", | ||
"video", | ||
]; | ||
|
||
export function registerPromHandlers(bot: Telegraf<Ctx>) { | ||
for (const msgSubType of promUpdateTypes) { | ||
bot.on(msgSubType, (_ctx, next) => { | ||
promMessageCounter.inc({ media_type: msgSubType }); | ||
return next(); | ||
}); | ||
} | ||
} | ||
|
||
export function getRawMetrics() { | ||
return register.metrics(); | ||
} |