Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ export interface XtransitConfig {

// II. 比较重要的可选配置(不知道怎么配置的别传任何值,key 也别传,整个配置留空!!)
disks?: string[], // 数组,每一项为配置需要监控的 disk 目录全路径
ignoredFileSystems?: string[], // 数组,每一项为配置监控磁盘需要忽略的文件系统名
errors?: string[], // 数组,每一项为配置需要监控的 error 日志文件全路径
packages?: string[], // 数组,每一项为配置需要监控的 package.json 文件全路径,并且要保证存在平级的 lock 文件(package-lock.json 或者 yarn.lock)

// III. 不是很重要的可选的配置(不知道怎么配置的别传任何值,key 也别传,整个配置留空!!)
logDir?: string, // xprofiler 插件生成性能日志文件的目录,默认两者均为 os.tmpdir() 如:'/path/to/xprofiler_output'
docker?: boolean, // 默认 false,系统数据采集会依赖当前是否是 docker 环境而进行一些特殊处理,可以手动强制指定当前实例是否为 docker 环境
ipMode?: boolean, // 默认 false,此时仅使用 hostname 作为 agentId;设置为 true 后 agentId 组装形式为 ${ip}_${hostname}
ipMode?: boolean, // 默认 false,此时仅使用 hostname 作为 agentId;设置为 true 后 agentId 组装形式为 ${ip}_${hostname}
libMode?: boolean, // 默认 false,此时采集如果收到 shutdown 事件会退出当前进程;如果是以第三方库的形式引用接入应用内,请将此属性设置为 true
errexp?: RegExp, // 匹配错误日志起始的正则,默认为匹配到 YYYY-MM-DD HH:mm:ss 时间戳即认为是一条错误日志的起始 /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/i
logger?: any, // 可以传入应用日志句柄方便日志统一管理,注意需要实现 error, info, warn 和 debug 四个方法
Expand Down
1 change: 1 addition & 0 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class XtransitAgent extends EventEmitter {
this.libMode = utils.isBoolean(config.libMode) ? config.libMode : false;
this.cleanAfterUpload = utils.isBoolean(config.cleanAfterUpload) ? config.cleanAfterUpload : false;
this.disks = Array.from(new Set(config.disks || []));
this.ignoredFileSystems = Array.from(new Set(config.ignoredFileSystems || []));
this.errors = Array.from(new Set(config.errors || []));
this.packages = Array.from(new Set(config.packages || []));
this.coredirs = Array.from(new Set(config.coredirs || []));
Expand Down
7 changes: 4 additions & 3 deletions orders/system_log.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ async function getLoadAvg() {
return os.loadavg();
}

async function getDiskUsage(disks) {
async function getDiskUsage(disks, ignoredFileSystems) {
if (isWindows) {
return {};
}
Expand All @@ -502,7 +502,8 @@ async function getDiskUsage(disks) {
existsDisks.push(disk);
}
const params = existsDisks.length ? ` ${existsDisks.join(' ')}` : '';
const command = `df -P${params}`;
const xfs = ignoredFileSystems.length ? ` ${ignoredFileSystems.map(fs => `-x ${fs}`).join(' ')}` : '';
const command = `df -P${xfs}${params}`;

logger.debug(`[system_log] get disks info: ${command}`);
const { stdout } = await exec(command);
Expand Down Expand Up @@ -560,7 +561,7 @@ exports = module.exports = async function() {
tasks.push(getCpuUsage());
tasks.push(getFreeMemory());
tasks.push(getLoadAvg());
tasks.push(getDiskUsage(this.disks));
tasks.push(getDiskUsage(this.disks, this.ignoredFileSystems));
tasks.push(getNodeCount(this.titles));

const [
Expand Down
8 changes: 8 additions & 0 deletions test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ describe('get config', function() {
expect(agent.packages.length).to.be(0);
expect(Array.isArray(agent.titles)).to.be(true);
expect(agent.titles.length).to.be(0);
expect(Array.isArray(agent.ignoredFileSystems)).to.be(true);
expect(agent.ignoredFileSystems.length).to.be(0);
});

it('shoule merge user config', function() {
Expand All @@ -67,6 +69,7 @@ describe('get config', function() {
const errors = ['/error.log', '/error.log', '/error.log'];
const packages = ['/package.json', '/package.json', '/package.json'];
const titles = ['mock-node'];
const ignoredFileSystems = ['tmpfs', 'tmpfs', 'devtmpfs'];
const agent = new Agent({
server: 'ws://127.0.0.1',
appId: 1,
Expand All @@ -84,6 +87,7 @@ describe('get config', function() {
errors,
packages,
titles,
ignoredFileSystems,
});
expect(agent.logdir).to.be(logdir);
expect(agent.logLevel).to.be(logLevel);
Expand All @@ -102,6 +106,8 @@ describe('get config', function() {
expect(agent.packages.length).to.be(Array.from(new Set(packages)).length);
expect(Array.isArray(agent.titles)).to.be(true);
expect(agent.titles.length).to.be(Array.from(new Set(titles)).length);
expect(Array.isArray(agent.ignoredFileSystems)).to.be(true);
expect(agent.ignoredFileSystems.length).to.be(Array.from(new Set(ignoredFileSystems)).length);
});

it('should config logDir', function() {
Expand Down Expand Up @@ -129,6 +135,7 @@ describe('get config', function() {
const errors = ['/error.log', '/error.log', '/error.log'];
const packages = ['/package.json', '/package.json', '/package.json'];
const titles = ['mock-node'];
const ignoredFileSystems = ['tmpfs', 'tmpfs', 'devtmpfs'];
const agent = new Agent({
nodeExe: 'foo',
server: 'ws://127.0.0.1',
Expand All @@ -147,6 +154,7 @@ describe('get config', function() {
errors,
packages,
titles,
ignoredFileSystems,
});
let execOptions;
let exeFile;
Expand Down