npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mem-stat

v1.0.5

Published

Memory statistics, not provided by `os` module.

Downloads

169

Readme

mem-stat

  ___ ___ _______ ___ ___ _______ _______ _______ _______
 |   Y   |   _   |   Y   |   _   |       |   _   |       |
 |.      |.  1___|.      |   1___|.|   | |.  1   |.|   | |
 |. \_/  |.  __)_|. \_/  |____   `-|.  |-|.  _   `-|.  |-'
 |:  |   |:  1   |:  |   |:  1   | |:  | |:  |   | |:  |
 |::.|:. |::.. . |::.|:. |::.. . | |::.| |::.|:. | |::.|
 `--- ---`-------`--- ---`-------' `---' `--- ---' `---'

Note: This repo can be found on npm here: mem-stat

Note: This repo can be found on github here: node-mem-stat

Caveat: Works by parsing /proc/meminfo, so will only work on nix OS.

Install

npm install mem-stat

Example

Require the module:

var memStat = require('mem-stat');

By default free() returns values in bytes:

var free = memStat.free();
console.log(free);

Return free memory in GiB, see docs below for allowed values of units:

var free = memStat.free('GiB');
console.log(free);

usedPercent() returns the percentage memory used eg. 13.359272:

var usedPercent = memStat.usedPercent();
console.log(usedPercent);

Get all the calculated statistics, requiring only one read and parse of /proc/meminfo:

var allStats = memStat.allStats();
console.log(allStats);
  {
    free: 1000,
    total: 8000,
    freePercent: 86.245977,
    usedPercent: 13.754023,
  }

Get all fields available from /proc/meminfo formatted as an object, see docs below for example of all the fields:

var raw = memStat.raw();
console.log(raw);
``

``
//or use the callback style
memStat.raw(function(err, raw) {
  if (err) {
    return console.log(err);
  }
  console.log(raw);
});

free(units)

Returns the amount of free memory in units available on the system.

Option | Type | Default | Explanation ------------- | -------------| ------------- | ------------ units | String | 'bytes' | The units of the returned value, can be one of bytes, KiB, MiB or GiB.

total(units)

Returns the amount of total memory in units available on the system. It's basically the same as os.totalmem(), but instead using /proc/meminfo.

Option | Type | Default | Explanation ------------- | -------------| ------------- | ------------ units | String | 'bytes' | The units of the returned value, can be one of bytes, KiB, MiB or GiB.

freePercent()

Returns the amount of free memory as a percentage eg 83.9430437.

usedPercent()

Returns the amount of used memory as a percentage eg 13.9430437.

allStats(units)

Returns an object of all the stats, therefore only requiring one reading and parsing of /proc/meminfo.

  {
    free: 1000,
    total: 8000,
    freePercent: 86.245977,
    usedPercent: 13.754023,
  }

Option | Type | Default | Explanation ------------- | -------------| ------------- | ------------ units | String | 'bytes' | The units of the returned value, can be one of bytes, KiB, MiB or GiB.

raw([cb])

Returns an object representing the data in /proc/meminfo.

Option | Type | Default | Explanation ------- | -------------| ------------------------------------------------ | ------------ cb | Function | If no callback is specified, uses sync file read | Gives the user the option of using a callback style interface.

  {
    memTotal: 8114892,
    memFree: 794140,
    memAvailable: 5879036,
    buffers: 385952,
    cached: 4597408,
    swapCached: 10992,
    active: 4288952,
    inactive: 2453264,
    activeAnon: 1197680,
    inactiveAnon: 592184,
    activeFile: 3091272,
    inactiveFile: 1861080,
    unevictable: 32,
    mlocked: 32,
    swapTotal: 1951740,
    swapFree: 1930036,
    dirty: 212,
    writeback: 0,
    anonPages: 1748032,
    mapped: 378400,
    shmem: 31012,
    slab: 418628,
    sReclaimable: 385960,
    sUnreclaim: 32668,
    kernelStack: 6800,
    pageTables: 32020,
    nFSUnstable: 0,
    bounce: 0,
    writebackTmp: 0,
    commitLimit: 6009184,
    committedAS: 6138892,
    vmallocTotal: 34359738367,
    vmallocUsed: 120844,
    vmallocChunk: 34359595004,
    hardwareCorrupted: 0,
    anonHugePages: 370688,
    hugePagesTotal: 0,
    hugePagesFree: 0,
    hugePagesRsvd: 0,
    hugePagesSurp: 0,
    hugepagesize: 2048,
    directMap4k: 237136,
    directMap2M: 5992448,
    directMap1G: 2097152
  }

Contributing

Just send a PR, or create an issue if you are not sure.

Areas ripe for contribution:

  • testing
  • cross compatability for windows and darwin/osx
  • performance
  • bugs

Other Stat Modules

Note: net-stat, disk-stat, mem-stat only work on nix platforms.

License

MIT