Skip to content

Commit

Permalink
feat: accept logging path name as a identifier
Browse files Browse the repository at this point in the history
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
  • Loading branch information
RafaelGSS committed Mar 15, 2023
1 parent fe2234f commit 923ab19
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions index.js
Expand Up @@ -35,14 +35,16 @@ class ClinicDoctor extends events.EventEmitter {
sampleInterval = 10,
detectPort = false,
debug = false,
dest = null
dest = null,
name
} = settings

this.collectDelay = collectDelay
this.sampleInterval = sampleInterval
this.detectPort = detectPort
this.debug = debug
this.path = dest
this.name = name

// cannot calculate ELU on these node versions
this.collectLoopUtilization = semver.gt(process.version, 'v14.10.0')
Expand Down Expand Up @@ -85,6 +87,10 @@ class ClinicDoctor extends events.EventEmitter {
customEnv.NODE_CLINIC_DOCTOR_DATA_PATH = this.path
}

if (this.name) {
customEnv.NODE_CLINIC_DOCTOR_NAME = this.name
}

const proc = spawn(args[0], args.slice(1), {
stdio,
env: Object.assign({}, process.env, customEnv)
Expand All @@ -99,7 +105,7 @@ class ClinicDoctor extends events.EventEmitter {
}

// get logging directory structure
const options = { identifier: proc.pid, path: this.path }
const options = { identifier: this.name || proc.pid, path: this.path }
const paths = getLoggingPaths(options)
// relay SIGINT to process
process.once('SIGINT', /* istanbul ignore next: SIGINT is only emitted at Ctrl+C on windows */ () => {
Expand Down
5 changes: 4 additions & 1 deletion injects/sampler.js
Expand Up @@ -8,7 +8,10 @@ const getLoggingPaths = require('@clinic/clinic-common').getLoggingPaths('doctor
const ProcessStatEncoder = require('../format/process-stat-encoder.js')

// create encoding files and directory
const paths = getLoggingPaths({ path: process.env.NODE_CLINIC_DOCTOR_DATA_PATH, identifier: process.pid })
const paths = getLoggingPaths({
path: process.env.NODE_CLINIC_DOCTOR_DATA_PATH,
identifier: process.env.NODE_CLINIC_DOCTOR_NAME || process.pid
})

makeDir.sync(paths['/'])

Expand Down

0 comments on commit 923ab19

Please sign in to comment.