Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [10.x, 12.x, 14.x, latest]
node-version: [14.x, 'lts/*', latest]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm install
- run: npm test
- run: npm run report-coverage

Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ dist/

# Important Documentation
!.github/**

# IntelliJ IDEA
.idea
*.iml
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,21 @@ const metrics = new NewRelic({

Sent for all metrics.

| Attribute | Format | Description |
|-------------------|------------------|---------------------------------|
| `eventType` | string | Event type, required, [standard New Relic Insights type](https://docs.newrelic.com/docs/insights/insights-data-sources/custom-data/insights-custom-data-requirements-limits). |
| Attribute | Format | Description |
|-------------------|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `eventType` | string | Event type, required, [standard New Relic Insights type](https://docs.newrelic.com/docs/insights/insights-data-sources/custom-data/insights-custom-data-requirements-limits). |
| `timestamp` | utc millis (?) | The UTC timestamp to associate with the event. [Standard New Relic Insights type](https://docs.newrelic.com/docs/insights/insights-data-sources/custom-data/insights-custom-data-requirements-limits). |
| `namespace` | string | OpenWhisk namespace of the action that sent the event. |
| `package` | string | OpenWhisk package name of the action that sent the event. |
| `actionName` | string | OpenWhisk action name (without package) of the action that sent the event. |
| `activationId` | string | OpenWhisk activation id of the action that sent the event. |
| `cloud` | string | Cloud in which the activation ran, e.g. `aws` or `azure` (`__OW_CLOUD`). |
| `region` | string | Region in which the activation ran, e.g. `us-east-1` (`__OW_REGION`). |
| `transactionId` | string | OpenWhisk transaction id (`__OW_TRANSACTION_ID`). |
| `activationHost` | string | Hostname where the activation ran (`HOSTNAME` env var). |
| `activationContainerName` | string | Container name where the activation ran (`MESOS_CONTAINER_NAME` env var). |
| `nodeVersion` | string | Nodejs version on which the action ran, e.g. `13.12.0`. |
| `containerMemorySize` | number | Container memory size found in `/sys/fs/cgroup/memory/memory.limit_in_bytes`|
| `namespace` | string | OpenWhisk namespace of the action that sent the event. |
| `package` | string | OpenWhisk package name of the action that sent the event. |
| `actionName` | string | OpenWhisk action name (without package) of the action that sent the event. |
| `activationId` | string | OpenWhisk activation id of the action that sent the event. |
| `cloud` | string | Cloud in which the activation ran, e.g. `aws` or `azure` (`__OW_CLOUD`). |
| `region` | string | Region in which the activation ran, e.g. `us-east-1` (`__OW_REGION`). |
| `transactionId` | string | OpenWhisk transaction id (`__OW_TRANSACTION_ID`). |
| `activationHost` | string | Hostname where the activation ran (`HOSTNAME` env var). |
| `activationContainerName` | string | Container name where the activation ran (`MESOS_CONTAINER_NAME` env var). |
| `nodeVersion` | string | Nodejs version on which the action ran, e.g. `13.12.0`. |
| `containerMemorySize` | number | Container memory size found in `/sys/fs/cgroup/memory/memory.limit_in_bytes` in CGROUPV1 or `/sys/fs/cgroup/memory.max` in CGROUPV2 |

### Http

Expand Down
10 changes: 9 additions & 1 deletion lib/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const ERROR_METRIC_NAMES = [

const LIB_RELEASE_PATH = '/etc/os-release';
const LIB_RELEASE_PATH_SECONDARY = '/usr/lib/os-release';
const CONTAINER_MEMORY_SIZE_CGROUPV1 = '/sys/fs/cgroup/memory/memory.limit_in_bytes';
const CONTAINER_MEMORY_SIZE_CGROUPV2 = '/sys/fs/cgroup/memory.max';

/**
* Retrieve timestamp in milliseconds since Unix epoch for
Expand Down Expand Up @@ -98,7 +100,13 @@ function openwhisk(metrics) {

try {
// container memory size
metrics.containerMemorySize = parseInt(fs.readFileSync('/sys/fs/cgroup/memory/memory.limit_in_bytes'), 10) || undefined;
if (fs.existsSync(CONTAINER_MEMORY_SIZE_CGROUPV2)) {
// cgroup v2
metrics.containerMemorySize = parseInt(fs.readFileSync(CONTAINER_MEMORY_SIZE_CGROUPV2), 10) || undefined;
} else {
// cgroup v1
metrics.containerMemorySize = parseInt(fs.readFileSync(CONTAINER_MEMORY_SIZE_CGROUPV1), 10) || undefined;
}
// eslint-disable-next-line no-unused-vars
} catch (e) {
// ignore error if not in the context of a docker container
Expand Down
Loading