Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to monitor processes not started by cardamon #61

Open
seal opened this issue Jul 5, 2024 · 0 comments
Open

Add ability to monitor processes not started by cardamon #61

seal opened this issue Jul 5, 2024 · 0 comments
Assignees
Labels
backburner Something we want to do, not yet roadmapped

Comments

@seal
Copy link
Collaborator

seal commented Jul 5, 2024

Example used:

  • Next.js application that calculates Prime numbers ( client side, CPU heavy )
    image
  • Node.js "puppeteer" application that navigates to the UI, and generates 10000 prime numbers
const puppeteer = require('puppeteer');
(async () => {
    try {
        const browser = await puppeteer.launch({
            headless: true, // Keep as true
        });
        const page = await browser.newPage();
        await page.goto('http://127.0.0.1:3001');
        await page.type('#limit', '1000000');
        // generate prime numbers button
        await page.click('.bg-blue-500.text-white.p-2.rounded');
// etc
    } catch (error) {
        console.error('An error occurred:', error);
    }
})();

The idea of this example is to generate a "CPU Leak" / memory leak on the client side

The problem with this is:

  • cardamon can only record PID's of processes it spawns
  • Puppeteer spawns chromium ( browser) not as a child process but as a detached process

This means after recording the CPU usage of our node.js program, we get a CPU usage of 0

Proposed changed:

  • Add the ability to send Process ID's to cardamon after it's started

One implementation of doing this would be as follows:

  • Create a http-server via cardamon
  • Await a post request with process ID's to start the scenario

Example node.js code:

const puppeteer = require('puppeteer');
const request = require('request');
(async () => {
    try {
        console.log('Starting puppeteer');
        const browser = await puppeteer.launch({
            headless: true, // Keep as true
        });
        request.post(
            'http://127.0.0.1:XX/api/pid',
            { json: { name: 'browser_click', pid: browser.process().pid } },
            function(error, response, body) {
                if (!error && response.statusCode == 200) {
                    console.log(body);
                }
            }
        );

        const page = await browser.newPage();

        await page.goto('http://127.0.0.1:3001');

        await page.type('#limit', '1000000');

        // generate prime numbers button
        await page.click('.bg-blue-500.text-white.p-2.rounded');


        // This will timeout at 30s 
        await page.waitForNavigation({ waitUntil: 'networkidle0' });

        console.log('Actions completed successfully');

        await browser.close();
    } catch (error) {
        console.error('An error occurred:', error);
    }
})();

Example cardamon.toml config:

[[processes]]
name = "pupp"
up = "node puppeteer.js"
[processes.redirect]
to = "parent"
[processes.process]
type = "baremetal"
[process.pid]
hang = true
name = "browser_click"

The idea here is to hang the starting of logging / metrics until the "pupp" process has sent a PID

@seal seal changed the title Add ability to add processes not started by cardamon Add ability to monitor processes not started by cardamon Jul 5, 2024
@anewmandev anewmandev added the backburner Something we want to do, not yet roadmapped label Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backburner Something we want to do, not yet roadmapped
Projects
None yet
Development

No branches or pull requests

3 participants