Cloud Foundry Service Metrics Logger

❯ Why
You want to log service metrics from your application on Cloud Foundry? - Yes? - Here you are 🙌 !!

❯ Table of Contents

❯ Supported Services
Service | Version |
---|
MongoDB | >=3.6.6 |
Redis | >=2.3.9 |

❯ Quick Start
Installation
Install library by using npm
npm install cf-service-metrics-logger
or by using yarn
yarn add cf-service-metrics-logger
How to use
Logger Interface
Create a new instance of CfServiceMetricsLogger and pass any kind of logger implementing following interface:
Method |
---|
`debug(message: {} |
`info(message: {} |
`warn(message: {} |
`error(message: {} |
CfServiceMetricsLogger Options
Option | Description | Default Value |
---|
mongoDb.serverStatusInterval (optional) | MongoDb database status polling interval in ms | 10000 |
mongoDb.dbStatsInterval (optional) | MongoDB storage statistics polling interval in ms | 10000 |
redis.infoInterval (optional) | Redis statistics polling interval | 10000 |
vcap (optional) | Provide local VCAP_SERVICES and/or VCAP_APPLICATION values | {} |
vcapFile (optional) | Provide local VCAP_SERVICES and/or VCAP_APPLICATION file | '' |
Example
const CfServiceMetricsLogger = require('cf-service-metrics-logger');
import { CfServiceMetricsLogger } from 'cf-service-metrics-logger';
class Logger {
debug(message) {
console.debug(message);
}
info(message) {
console.info(message);
}
warn(message) {
console.warn(message);
}
error(message) {
console.error(message);
}
}
const logger = new Logger();
const options = {
mongoDB: {
serverStatusInterval: 10000,
dbStatsInterval: 20000,
},
redis: {
infoInterval: 100000
}
};
const cfServiceMetricsLogger = new CfServiceMetricsLogger(logger, options);
cfServiceMetricsLogger.start();
cfServiceMetricsLogger.stop();

❯ Development
Getting Started
Step 1: Set up the Development Environment
You need to set up your development environment before you can do anything.
Install Node.js and NPM
Install yarn globally
yarn install yarn -g
Step 2: Set up Environment Variables
Copy the vcap.example.json
file and rename it to vcap.json
. This file provides VCAP_SERVICES
and/or VCAP_APPLICATION
for local development.
More information is provided here.
Step 3: Install dependencies
Install all dependencies with yarn.
yarn install
Scripts and Tasks
Install
- Install all dependencies with
yarn install
Linting
- Run code quality analysis using
yarn run lint
. This runs tslint.
Tests
- Run unit test using
yarn run test
.
Building the project
- Run
yarn run build
to generate commonJS and ES6 modules as well as declaration from the TypeScript source. - Builded sources are located in
dist
folder.
Debugger
VS Code
Just set a breakpoint in source or unit test and hit F5 in your Visual Studio Code to execute and debug all unit tests.

❯ Project Structure
Name | Description |
---|
.vscode/ | VSCode tasks, launch configuration and some other settings |
dist/ | Compiled and bundled source files will be placed here |
src/ | Source files |
src/types/ *.d.ts | Custom type definitions and files that aren't on DefinitelyTyped |
test/ | Tests |
test/unit/ *.test.ts | Unit tests |
vcap.example.json | Provides VCAP_SERVICES and/or VCAP_APPLICATION for local development |
vcap.test.json | Provides VCAP_SERVICES and/or VCAP_APPLICATION for unit tests |
rollup.config.js | Config for Rollup module bundler |