forked from livingdocsIO/loki-log-export
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (29 loc) · 1.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const extractors = JSON.parse(process.env.EXTRACTORS || '[]')
const exporter = require('./exporter')({
awsBucket: process.env.AWS_BUCKET,
awsRegion: process.env.AWS_REGION,
awsAccessKeyId: process.env.AWS_ACCESS_KEY_ID,
awsSecretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
lokiHost: process.env.LOKI_HOST || 'http://localhost:3100'
})
for (const extractor of extractors) {
exporter.log.warn(`Processor started for ${extractor.prefix}: ${extractor.query}`)
if (process.argv.includes('--once')) {
exporter.start(extractor)
} else {
exporter.startCron(extractor)
}
}
const prexit = require('prexit')
prexit.signals.push('uncaughtException', 'unhandledRejection')
prexit.logExceptions = false
prexit(async (signal, error) => {
const uptime = Math.round(process.uptime() * 100) / 100
if ([0, 'SIGTERM', 'SIGINT'].includes(signal)) {
if (signal === 0) exporter.log.warn(`Shutting down after running for ${uptime}s`)
else exporter.log.warn(`Signal ${signal} received. Shutting down after running for ${uptime}s`)
} else {
const err = signal instanceof Error ? signal : error
exporter.log.fatal({err}, `Processing error. Shutting down after running for ${uptime}s`)
}
})