Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

agentx

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

agentx - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

59

lib/orders/node_log.js
'use strict';
var path = require('path');
var spawn = require('child_process').spawn;
var exec = require('child_process').exec;
var through = require('through2');
var sf = require('slice-file');
var fs = require('fs');
var MAX_LINES = 10; // 最多10行数据
var buffered = [];
exports.logdir = ''; // 日志路径
var tail;
var xs;
var createFileIfNotExists = function(path) {
// TODO: blocking i/o
var fd = fs.openSync(path, 'a');
fs.close(fd);
};
var date = function(now) {

@@ -25,3 +33,3 @@ if (!now) {

time: time,
ms: ms
ms: ms
};

@@ -45,4 +53,3 @@ };

current: path.join(exports.logdir, 'node-' + now.date + '.log'),
next: path.join(exports.logdir, 'node-' + next.date + '.log'),
ms_to_refresh: diff
timeToRefresh: diff
};

@@ -52,7 +59,11 @@ }

function startTailf(path) {
var tail = spawn('tail', ['-f', path]);
tail.stdout.on("data", function (data) {
buffered.push(data);
});
return tail;
var xs = sf(path);
xs.follow(-1).pipe(through(function(line, _, next){
buffered.push(line);
if (buffered.length > MAX_LINES) {
buffered.shift(); // 删掉前面的
}
next();
}));
return xs;
}

@@ -63,7 +74,3 @@

function getNodeLog() {
var msg = Buffer.concat(buffered).toString();
// empty buffered array
buffered = [];
function getNodeLog(msg) {
var matched;

@@ -90,15 +97,11 @@ var result = {ok: true, data: []};

var tail;
var init = function () {
var info = getLogFileInfo();
tail = startTailf(info.current);
exec('touch ' + info.next, function (error, stdout, stderr) {
if (error) {
console.log('exec error: ' + error);
}
});
createFileIfNotExists(info.current);
xs = startTailf(info.current);
setTimeout(function() {
tail.kill();
xs.close();
init();
}, info.ms_to_refresh);
}, info.timeToRefresh);
};

@@ -112,6 +115,10 @@

exports.run = function (callback) {
var msg = Buffer.concat(buffered).toString();
// empty buffered array
buffered = [];
callback(null, {
type: 'node_log',
metrics: getNodeLog()
metrics: getNodeLog(msg)
});
};
{
"name": "agentx",
"version": "1.0.1",
"version": "1.0.2",
"description": "agentx is powered by alinode",

@@ -15,3 +15,5 @@ "scripts": {

"ws": "^0.7.2",
"debug": "*"
"debug": "*",
"slice-file": "*",
"through2": "^0.6.5"
},

@@ -18,0 +20,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc