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

added cpu metrics, fails if no file found #4

Merged
merged 1 commit into from Oct 7, 2019

Conversation

@jdelbick
Copy link
Collaborator

commented Oct 7, 2019

Description

Added CPU metrics:

  • cpuacct.usage: total CPU time (in nanoseconds) obtained by this cgroup (CPU time obtained by all the tasks)
    in the system
  • cpuacct.stat: reports the user and system CPU time consumed by all tasks in this cgroup (including tasks lower in the hierarchy):
    • user: CPU time (in nanoseconds) spent by tasks of the cgroup in user mode
    • system: CPU time (in nanoseconds) spent by tasks of the cgroup in kernel mode
  • cpuacct.usage_percpu: CPU time (in nanoseconds) consumed on each CPU by all tasks in this cgroup (including tasks lower in the hierarchy).

Changed behavior when not running in a container:
Before it would return null if there was no container running (when reading the file path sys/fs/cgroup would return an error).
Now it will actually through an error and let the user know the issue.

Added a function getAllMetrics that returns an object of all the metrics.

How Has This Been Tested?

Added tests in test/index.test.js

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
@jdelbick jdelbick merged commit 5942ed2 into master Oct 7, 2019
1 check passed
1 check passed
Adobe CLA Signed? ✓ Adobe Employee
Details
@jdelbick jdelbick deleted the cpu-metrics branch Oct 7, 2019
console.log(`CPU usage per CPU task: ${cpuacct_usage_percpu}`);
// Or you can use the function `getAllMetrics` to get an object of all the metrics
const metrics = await cgroup.getAllMetrics();

This comment has been minimized.

Copy link
@alexkli

alexkli Oct 8, 2019

@jdelbick I would suggest to rename cgroup.getAllMetrics() to cgroup.metrics().

This would be more consistent with the other method names (stat(), usage() ...).

This comment has been minimized.

Copy link
@jdelbick

jdelbick Oct 10, 2019

Author Collaborator

Good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.