Permalink
Browse files

Change TCP listening state to a more generic representation

  • Loading branch information...
1 parent 8292c30 commit 5e6670552e6e400292b573e21ffb80553300c2d1 @mzsanford mzsanford committed Jul 23, 2012
Showing with 26 additions and 31 deletions.
  1. +20 −29 README.md
  2. +6 −2 lib/lsof.js
View
@@ -77,36 +77,27 @@ call it from your `status` commands to see how many open file descriptors your p
lsof.rawTcpPort(11211, function(data) {
console.log(data);
/*
- * [ { listening: true,
+ * [ { state: 'listen',
* command: 'memcached',
- * pid: '186',
- * user: 'matt',
- * fd: '28u',
- * type: 'IPv6',
- * device: '0xffffff80121fe600',
- * 'size/off': '0t0',
- * node: 'TCP',
- * name: 'localhost:11211' },
- * { listening: true,
- * command: 'memcached',
- * pid: '186',
- * user: 'matt',
- * fd: '29u',
- * type: 'IPv4',
- * device: '0xffffff80122004e0',
- * 'size/off': '0t0',
- * node: 'TCP',
- * name: 'localhost:11211' },
- * { listening: true,
- * command: 'memcached',
- * pid: '186',
- * user: 'matt',
- * fd: '30u',
- * type: 'IPv6',
- * device: '0xffffff80121fe240',
- * 'size/off': '0t0',
- * node: 'TCP',
- * name: 'localhost:11211' } ]
+ * pid: '183',
+ * user: 'matt',
+ * fd: '28u',
+ * type: 'IPv6',
+ * device: '0xffffff80121a3600',
+ * 'size/off': '0t0',
+ * node: 'TCP',
+ * name: 'localhost:11211' },
+ * { state: 'listen',
+ * command: 'memcached',
+ * pid: '183',
+ * user: 'matt',
+ * fd: '29u',
+ * type: 'IPv4',
+ * device: '0xffffff8013f90500',
+ * 'size/off': '0t0',
+ * node: 'TCP',
+ * name: 'localhost:11211' } ]
+ *
*/
}
View
@@ -47,8 +47,12 @@ var rawTcpPort = exports.rawTcpPort = function(port, fn) {
d.forEach(function(v) {
v = v.split(/\s+/);
var k = {};
- if (v[headers.length] == '(LISTEN)') {
- k['listening'] = true;
+ var finalField = v[headers.length];
+ if (finalField) {
+ // There is one more field than there are headers. Interpret that state info.
+ // These are things like '(LISTEN)' or '(ESTABLISHED)'. Save it into the state
+ // field minus the parenthesis and lowercased
+ k['state'] = finalField.substring(1, finalField.length-1).toLowerCase();
v.pop();
}
v.forEach(function(s, i) {

0 comments on commit 5e66705

Please sign in to comment.