-
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
Adnan Rahic
committed
Jan 13, 2021
1 parent
388c807
commit 591e9ee
Showing
4 changed files
with
85 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const pidUsageTree = require('pidusage-tree') | ||
const util = require('util') | ||
const pidUsageTreePromise = util.promisify(pidUsageTree) | ||
const pm2Enabled = process.env.NODE_APP_INSTANCE !== undefined | ||
const isChildProcess = process.send !== undefined | ||
const isMasterProcess = process.send === undefined | ||
|
||
const setProcessTags = async ({ pidToCheck, type }) => { | ||
const results = await pidUsageTreePromise(pidToCheck) | ||
const processes = Object.keys(results) | ||
.map(key => results[key]) | ||
.filter(proc => proc) | ||
|
||
const resProc = processes.filter(proc => proc.pid === pidToCheck).pop() | ||
|
||
const processTags = { | ||
process: { | ||
type, | ||
name: 'node', | ||
pid: resProc.pid, | ||
ppip: resProc.ppid | ||
} | ||
} | ||
|
||
process.env.processTags = JSON.stringify(processTags) | ||
} | ||
|
||
const setDefaultProcessTags = async () => | ||
isMasterProcess | ||
? await setProcessTags({ pidToCheck: process.pid, type: 'master' }) | ||
: await setProcessTags({ pidToCheck: process.pid, type: 'child' }) | ||
|
||
const setPm2ProcessTags = async () => | ||
isChildProcess | ||
? await setProcessTags({ pidToCheck: process.ppid, type: 'pm2' }) | ||
: null | ||
|
||
;(async () => { | ||
try { | ||
if (pm2Enabled) { | ||
await setPm2ProcessTags() | ||
} else { | ||
await setDefaultProcessTags() | ||
} | ||
} catch (error) { | ||
console.log(error) | ||
} | ||
})() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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