Merge branch 'master' of gitlab.com:MrFry/mrfrys-node-server

This commit is contained in:
mrfry 2021-10-06 19:14:13 +02:00
commit c13035a8df
6 changed files with 175 additions and 154 deletions

View file

@ -4,5 +4,6 @@ dist
stats stats
data data
publicDirs publicDirs
nextStatic
devel devel
.git .git

View file

@ -1,7 +1,9 @@
#!/bin/bash #!/bin/bash
hr() { hr() {
if [ -t 0 ]; then
printf '\033[0;32m%*s\033[0m\n' "$(tput cols)" '' | tr ' ' '=' printf '\033[0;32m%*s\033[0m\n' "$(tput cols)" '' | tr ' ' '='
fi
} }
log() { log() {
@ -80,16 +82,14 @@ touch publicDirs/qminingPublic/version
touch publicDirs/qminingPublic/motd touch publicDirs/qminingPublic/motd
if [ -z "$(ls -A ./data/dbs)" ]; then if [ -z "$(ls -A ./data/dbs)" ]; then
log "Making DB-s"
pushd src/standaloneUtils pushd src/standaloneUtils
NS_LOGLEVEL=2 node dbSetup.js NS_LOGLEVEL=2 node dbSetup.js
mv *.db ../../data/dbs mv *.db ../../data/dbs
popd popd
fi fi
log "Disabling next telemetry"
npx --yes next telemetry disable npx --yes next telemetry disable
hr log "Done!"
echo "Done!"
echo "npm start {loglevel}"
echo "To start server"
hr

View file

@ -21,14 +21,18 @@ elif [ "$1" == "stop" ]; then
docker stop $(getContainerId) docker stop $(getContainerId)
elif [ "$1" == "start" ]; then elif [ "$1" == "start" ]; then
# --entrypoint bash \ # --entrypoint bash \
docker start -i $(getContainerId) scripts/setup.sh
docker start $(getContainerId)
elif [ "$1" == "run" ]; then elif [ "$1" == "run" ]; then
# --entrypoint bash \ # --entrypoint bash \
docker run -it \ scripts/setup.sh
-p 8080:80 \
--mount src="$(pwd)/stats",target=/server/stats,type=bind \ docker run \
--mount src="$(pwd)/data",target=/server/data,type=bind \ --network host \
--mount src="$(pwd)/publicDirs",target=/server/publicDirs,type=bind \ --mount src="$(pwd)/stats",target="/server/stats",type=bind \
--mount src="$(pwd)/data",target="/server/data",type=bind \
--mount src="$(pwd)/publicDirs",target="/server/publicDirs",type=bind \
--mount src="/etc/letsencrypt",target="/etc/letsencrypt",type=bind \
qminer/mrfrys-node-server qminer/mrfrys-node-server
elif [ "$1" == "bash" ]; then elif [ "$1" == "bash" ]; then
docker exec -it $(getContainerId) /bin/bash docker exec -it $(getContainerId) /bin/bash

View file

@ -74,7 +74,8 @@ const filterFromDailyStats = [
'.xml', '.xml',
'.aspx', '.aspx',
'/questionDbs/', '/questionDbs/',
'/chatFiles/' '/chatFiles/',
'rss'
] ]
// ----------------------------------------------------------------- // -----------------------------------------------------------------
@ -291,9 +292,9 @@ function pCols(cols, rowTitles, colorNames, firstRowColor) {
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
printHeader('Daily stats') printHeader('Daily stats')
try {
const dailyStats = readJSON(`${dir}stats/vstats`) const dailyStats = readJSON(`${dir}stats/vstats`)
function preProcessDailyStats(obj) { function preProcessDailyStats(obj) {
const formatted = Object.keys(obj).reduce((acc, key) => { const formatted = Object.keys(obj).reduce((acc, key) => {
const includes = filterFromDailyStats.some((keyword) => { const includes = filterFromDailyStats.some((keyword) => {
return key.toLowerCase().includes(keyword.toLowerCase()) return key.toLowerCase().includes(keyword.toLowerCase())
@ -335,12 +336,12 @@ function preProcessDailyStats(obj) {
return 0 return 0
} }
}) })
} }
function getDailyStat(day) { function getDailyStat(day) {
return preProcessDailyStats(dailyStats[getDayIndex(day)]) return preProcessDailyStats(dailyStats[getDayIndex(day)])
} }
pCols( pCols(
[ [
...[...Array(colsToPrint).keys()].map((x) => { ...[...Array(colsToPrint).keys()].map((x) => {
return getDailyStat(-x) return getDailyStat(-x)
@ -348,12 +349,16 @@ pCols(
], ],
null, null,
true true
) )
} catch (e) {
console.error(e)
}
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
printHeader('User id test solving') printHeader('User id test solving')
const userIdTestSolving = readJSON(`${dir}stats/idvstats`) try {
function preProcessUIdTestSolving(obj, minLength) { const userIdTestSolving = readJSON(`${dir}stats/idvstats`)
function preProcessUIdTestSolving(obj, minLength) {
if (!obj) { if (!obj) {
return '0' return '0'
} }
@ -366,15 +371,15 @@ function preProcessUIdTestSolving(obj, minLength) {
} else { } else {
return Object.keys(obj).length.toString() return Object.keys(obj).length.toString()
} }
} }
function getUserIdTestSolving(day) { function getUserIdTestSolving(day) {
return [ return [
getDayName(day), getDayName(day),
preProcessUIdTestSolving(userIdTestSolving[getDayIndex(day)]), preProcessUIdTestSolving(userIdTestSolving[getDayIndex(day)]),
] ]
} }
pCols( pCols(
[ [
...[...Array(colsToPrint).keys()].map((x) => { ...[...Array(colsToPrint).keys()].map((x) => {
return getUserIdTestSolving(-x) return getUserIdTestSolving(-x)
@ -383,20 +388,24 @@ pCols(
null, null,
false, false,
'green' 'green'
) )
} catch(e) {
console.error(e)
}
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
printHeader('User id requests') printHeader('User id requests')
const clientIdTestSolving = readJSON(`${dir}stats/uvstats`) try {
function getUserIdRequests(day) { const clientIdTestSolving = readJSON(`${dir}stats/uvstats`)
function getUserIdRequests(day) {
return [ return [
getDayName(day), getDayName(day),
preProcessUIdTestSolving(clientIdTestSolving[getDayIndex(day)]), preProcessUIdTestSolving(clientIdTestSolving[getDayIndex(day)]),
preProcessUIdTestSolving(clientIdTestSolving[getDayIndex(day)], 5), preProcessUIdTestSolving(clientIdTestSolving[getDayIndex(day)], 5),
] ]
} }
pCols( pCols(
[ [
...[...Array(colsToPrint).keys()].map((x) => { ...[...Array(colsToPrint).keys()].map((x) => {
return getUserIdRequests(-x) return getUserIdRequests(-x)
@ -405,20 +414,20 @@ pCols(
['', 'All', 'More than 5'], ['', 'All', 'More than 5'],
false, false,
'green' 'green'
) )
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
printHeader('Daily data count') printHeader('Daily data count')
const dailyDataCount = readFile(`${dir}stats/dailyDataCount`) const dailyDataCount = readFile(`${dir}stats/dailyDataCount`)
function getDailyDataCount(count) { function getDailyDataCount(count) {
return [...Array(count).keys()].map((x) => { return [...Array(count).keys()].map((x) => {
return JSON.parse(head(tail(dailyDataCount, x + 1), 1)) return JSON.parse(head(tail(dailyDataCount, x + 1), 1))
}) })
} }
printLastDataCount(getDailyDataCount(colsToPrint)) printLastDataCount(getDailyDataCount(colsToPrint))
function printLastDataCount(data) { function printLastDataCount(data) {
const res = [...Array(colsToPrint).keys()].map((x) => { const res = [...Array(colsToPrint).keys()].map((x) => {
return [getDayName(-x)] return [getDayName(-x)]
}) })
@ -429,10 +438,14 @@ function printLastDataCount(data) {
}) })
pCols(res, ['', 'Users', 'Subjects', 'Questions'], false, 'green') pCols(res, ['', 'Users', 'Subjects', 'Questions'], false, 'green')
}
} catch(e) {
console.error(e)
} }
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
printHeader('Daily script install / update check count') printHeader('Daily script install / update check count')
function getDailyScriptStat(day) { try {
function getDailyScriptStat(day) {
const log = const log =
!day || day === 0 !day || day === 0
? readFile(`${dir}stats/vlogs/log`) ? readFile(`${dir}stats/vlogs/log`)
@ -446,10 +459,13 @@ function getDailyScriptStat(day) {
countLinesMatching(log, '?install').toString(), countLinesMatching(log, '?install').toString(),
countLinesMatching(log, '?up').toString(), countLinesMatching(log, '?up').toString(),
] ]
} }
const installs = [...Array(colsToPrint).keys()].map((x) => { const installs = [...Array(colsToPrint).keys()].map((x) => {
return getDailyScriptStat(-x) return getDailyScriptStat(-x)
}) })
pCols(installs, ['', 'Installs', 'Updates'], false, 'green') pCols(installs, ['', 'Installs', 'Updates'], false, 'green')
} catch(e) {
console.error(e)
}

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
scripts/make.sh scripts/make.sh
npm run start npm run start > /dev/null

View file

@ -24,8 +24,8 @@ console.log('Current working directory: ' + process.cwd())
const startHTTPS = true const startHTTPS = true
const isRoot = process.getuid && process.getuid() === 0 const isRoot = process.getuid && process.getuid() === 0
const port = isRoot ? 80 : 8080 const port = 8080
const httpsport = isRoot ? 443 : 5001 const httpsport = 5001
// import os from 'os' // import os from 'os'
// os.setPriority(10) // os.setPriority(10)