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

cf-service-metrics-logger

v0.2.1

Published

Log Cloud Foundry service metrics

Downloads

3

Readme

divider

❯ Why

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

divider

❯ Table of Contents

divider

❯ Supported Services

| Service | Version | | ----------- | ------- | | MongoDB | >=3.6.6 | | Redis | >=2.3.9 |

divider

❯ 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

Step 1: Import CfServiceMetricsLogger

Using CommonJS module loader:

const CfServiceMetricsLogger = require('cf-service-metrics-logger');

Using ES6 module loader:

import { CfServiceMetricsLogger } from 'cf-service-metrics-logger';

Step 2: Create new instance of CfServiceMetricsLogger

Create new instance of CfServiceMetricsLogger and provide options:

const options = {
  mongoDB: {
    serverStatusInterval: 10000,
    dbStatsInterval: 20000,
  },
  redis: {
    infoInterval: 100000
  }
};

const cfServiceMetricsLogger = new CfServiceMetricsLogger(options);

Step 3: Subscribe to receive service metrics and general logs

Subscribe metrics to receive service metrics data:

cfServiceMetricsLogger.subscribe('metrics', data => {
  // do some fancy stuff with your metrics
});

Subscribe logs to receive general application logs:

cfServiceMetricsLogger.subscribe('logs', {message, level} => {
  console[level](message));
});

Step 3: Start and stop service metrics logging

Start service metrics logging:

cfServiceMetricsLogger.start();

Stop service metrics logging:

cfServiceMetricsLogger.stop();

divider

❯ API

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 | '' |

Methods

| Method | Description | | -------------------------------- | ---------------------- | | start() | Start service metrics | | stop() | Stop service metrics | | subscribe(eventId, callback) | Subscribe an event | | unsubscribe(eventId, callback) | Unsubscribe an event | | unsubscribeAll() | Unsubscribe all events |

Subscription event id's

| Id | Description | | --------- | ---------------------------------------------------------------------- | | metrics | Service metrics | | logs | General application logs for levels debug, info, warn and error |

divider

❯ 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.

divider

❯ 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 |