mirror of
https://github.com/hcengineering/platform.git
synced 2026-08-29 03:09:40 +02:00
UBERF-8553: Stats as separate service (#7054)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
@@ -4,41 +4,31 @@
|
||||
|
||||
import { Analytics } from '@hcengineering/analytics'
|
||||
import { SplitLogger, configureAnalytics } from '@hcengineering/analytics-service'
|
||||
import { MeasureMetricsContext, metricsToString, newMetrics } from '@hcengineering/core'
|
||||
import { loadBrandingMap } from '@hcengineering/server-core'
|
||||
import { writeFile } from 'fs/promises'
|
||||
import { MeasureMetricsContext, newMetrics } from '@hcengineering/core'
|
||||
import { initStatisticsContext, loadBrandingMap } from '@hcengineering/server-core'
|
||||
import { join } from 'path'
|
||||
import config from './config'
|
||||
import { start } from './server'
|
||||
|
||||
// Load and inc startID, to have easy logs.
|
||||
|
||||
const metricsContext = new MeasureMetricsContext(
|
||||
'github',
|
||||
{},
|
||||
{},
|
||||
newMetrics(),
|
||||
new SplitLogger('github-service', {
|
||||
root: join(process.cwd(), 'logs'),
|
||||
enableConsole: (process.env.ENABLE_CONSOLE ?? 'true') === 'true'
|
||||
})
|
||||
)
|
||||
const metricsContext = initStatisticsContext('github', {
|
||||
factory: () =>
|
||||
new MeasureMetricsContext(
|
||||
'github',
|
||||
{},
|
||||
{},
|
||||
newMetrics(),
|
||||
new SplitLogger('github-service', {
|
||||
root: join(process.cwd(), 'logs'),
|
||||
enableConsole: (process.env.ENABLE_CONSOLE ?? 'true') === 'true'
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
configureAnalytics(config.SentryDSN, config)
|
||||
Analytics.setTag('application', 'github-service')
|
||||
|
||||
let oldMetricsValue = ''
|
||||
|
||||
const intTimer = setInterval(() => {
|
||||
const val = metricsToString(metricsContext.metrics, 'Github', 140)
|
||||
if (val !== oldMetricsValue) {
|
||||
oldMetricsValue = val
|
||||
void writeFile('metrics.txt', val).catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
}
|
||||
}, 30000)
|
||||
|
||||
let doOnClose: () => Promise<void> = async () => {}
|
||||
|
||||
void start(metricsContext, loadBrandingMap(config.BrandingPath)).then((r) => {
|
||||
@@ -46,7 +36,6 @@ void start(metricsContext, loadBrandingMap(config.BrandingPath)).then((r) => {
|
||||
})
|
||||
|
||||
const onClose = (): void => {
|
||||
clearInterval(intTimer)
|
||||
metricsContext.info('Closed')
|
||||
void doOnClose().then((r) => {
|
||||
process.exit(0)
|
||||
|
||||
Reference in New Issue
Block a user