Skip to content

Commit

Permalink
Tested logman
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Jan 7, 2024
1 parent 07bb4c7 commit 37644e6
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/controllers/logman.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export default function () {
try {
let domain = await virtualminExec.getDomainInfo(req.query.domain.toString());
let type = req.query.type.toString()
let n = parseInt(req.query.n.toString()) || 100;
let n = parseInt((req.query.n || 100).toString()) || 100;
let output = await logmanExec.getLog(domain, type, n);
return res.json(output);
} catch (error) {
next(error);
} catch (err) {
next(JSON.stringify(err, Object.getOwnPropertyNames(err)));
}
});
return router;
Expand Down
19 changes: 12 additions & 7 deletions src/executor/logman.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
writeTo
} from '../util.js';
import { XMLParser } from "fast-xml-parser";
import { readFile } from "fs/promises";

class LogmanExecutor {
constructor() {
Expand Down Expand Up @@ -39,8 +40,10 @@ class LogmanExecutor {
"tail", "-n", n, domain['Error log']]);
case 'passenger':
const user = domain['Username'];
const pe = await spawnSudoUtil("SHELL_SUDO", [user,
"passenger-status", "--show=xml"]);
const pe = process.env.NODE_ENV === 'development' ?
{ stdout: await readFile('./test/passenger-status', {encoding: 'utf-8'}) } :
await spawnSudoUtil("SHELL_SUDO", [user,
"passenger-status", "--show=xml"]);
const peo = pe.stdout.trim();
if (!peo) {
return {
Expand All @@ -59,21 +62,23 @@ class LogmanExecutor {
}
}
let peomaa = Array.isArray(peoma) ? peoma : [peoma];
let peomaps = peomaa.map(x => x.group.processes).filter(x => x);
let peomaps = peomaa.map(x => x.group).filter(x => x.processes);
if (!peomaps.length) {
return {
code: 255,
stderr: 'No processes from passenger-status is running',
stderr: 'No processes reported from passenger-status is running',
stdout: ''
}
}
let procs = peomaps.reduce((a, b) => {
let x = (Array.isArray(b.process) ? b.process : [b.process]);
a[b.group.name] = x.map(y => y.pid).filter(y => typeof y === "number");
}, peomaps);
let x = (Array.isArray(b.processes.process) ? b.processes.process : [b.processes.process]);
a[b.name] = x.map(y => y.pid).filter(y => typeof y === "number");
return a;
}, {});
let head = `List of passenger processes running:\n`;
head += JSON.stringify(procs, null, 2);
head += `\n------------------------\n`;
console.log(head);
let pids = Object.values(procs).flatMap(x => x).join('\\|');
const pes = await spawnSudoUtil("SHELL_SUDO", ["root",
"bash", "-c", `grep -w "\\^App \\(${pids}\\)" "${this.PASSENGERLOG}" | tail -n ${n}`
Expand Down
92 changes: 92 additions & 0 deletions test/passenger-status
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<info version="3">
<passenger_version>6.0.19</passenger_version>
<group_count>5</group_count>
<process_count>5</process_count>
<max>20</max>
<capacity_used>5</capacity_used>
<get_wait_list_size>0</get_wait_list_size>
<supergroups>
<supergroup>
<name>/home/bridge/public_html/webssh2/app (production)</name>
<state>READY</state>
<get_wait_list_size>0</get_wait_list_size>
<capacity_used>1</capacity_used>
<group default="true">
<name>/home/bridge/public_html/webssh2/app (production)</name>
<component_name>/home/bridge/public_html/webssh2/app (production)</component_name>
<app_root>/home/bridge/public_html/webssh2/app</app_root>
<app_type/>
<environment>production</environment>
<uuid>U8CALDqmahQomxukXAXm</uuid>
<enabled_process_count>1</enabled_process_count>
<disabling_process_count>0</disabling_process_count>
<disabled_process_count>0</disabled_process_count>
<capacity_used>1</capacity_used>
<get_wait_list_size>0</get_wait_list_size>
<disable_wait_list_size>0</disable_wait_list_size>
<processes_being_spawned>0</processes_being_spawned>
<life_status>ALIVE</life_status>
<user>bridge</user>
<uid>1036</uid>
<group>bridge</group>
<gid>1036</gid>
<options>
<app_root>/home/bridge/public_html/webssh2/app</app_root>
<app_group_name>/home/bridge/public_html/webssh2/app (production)</app_group_name>
<start_command>env PORT=$PORT node app.js</start_command>
<startup_file>/home/bridge/public_html/webssh2/app</startup_file>
<log_level>3</log_level>
<start_timeout>90000</start_timeout>
<environment>production</environment>
<base_uri>/</base_uri>
<spawn_method>smart</spawn_method>
<bind_address>127.0.0.1</bind_address>
<default_user>nobody</default_user>
<default_group>nobody</default_group>
<restart_dir>tmp</restart_dir>
<integration_mode>nginx</integration_mode>
<ruby>/usr/bin/ruby</ruby>
<python>/usr/bin/python3</python>
<nodejs>/usr/bin/node</nodejs>
<debugger>false</debugger>
<api_key>LcZ3a5palXtc</api_key>
<min_processes>0</min_processes>
<max_processes>1</max_processes>
<max_preloader_idle_time>300</max_preloader_idle_time>
<max_out_of_band_work_instances>1</max_out_of_band_work_instances>
<sticky_sessions_cookie_attributes>SameSite=Lax; Secure;</sticky_sessions_cookie_attributes>
</options>
<processes>
<process>
<pid>2238686</pid>
<sticky_session_id>592161411</sticky_session_id>
<gupid>1b17ce1-YJRaByfnLl</gupid>
<concurrency>-1</concurrency>
<sessions>2</sessions>
<busyness>2</busyness>
<processed>29</processed>
<spawner_creation_time>1704543452738301</spawner_creation_time>
<spawn_start_time>1704543452745389</spawn_start_time>
<spawn_end_time>1704543454007375</spawn_end_time>
<last_used>1704543625386216</last_used>
<last_used_desc>10m 55s ago</last_used_desc>
<uptime>13m 46s</uptime>
<life_status>ALIVE</life_status>
<enabled>ENABLED</enabled>
<has_metrics>true</has_metrics>
<cpu>0</cpu>
<rss>24056</rss>
<pss>16813</pss>
<private_dirty>13056</private_dirty>
<swap>14568</swap>
<real_memory>27624</real_memory>
<vmsize>11280320</vmsize>
<process_group_id>2238536</process_group_id>
<command>node app.js</command>
</process>
</processes>
</group>
</supergroup>
</supergroups>
</info>

0 comments on commit 37644e6

Please sign in to comment.