Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
database-metrics-logger
Advanced tools
This project is no longer supported, please consider using node-service-metrics-logger instead.
The project node-service-metrics-logger does also support other services like RabbitMQ
.
You want to log service metrics from your application on Cloud Foundry? - Yes? - Here you are 🙌 !!
Service | Version |
---|---|
MongoDB | >=3.6.6 |
Redis | >=2.3.9 |
Install library by using npm
npm install database-metrics-logger
or by using yarn
yarn add database-metrics-logger
Using CommonJS
module loader:
const DatabaseMetricsLogger = require('database-metrics-logger');
Using ES6
module loader:
import { DatabaseMetricsLogger } from 'database-metrics-logger';
Create new instance of DatabaseMetricsLogger
and provide options:
const databaseCredentials = [
{
databaseType: 'mongodb',
host: 'your-mongodb-host',
username: 'user',
password: 'this-is-secret',
port: 27017
database: 'your-database-name',
},
{
databaseType: 'redis',
host: 'your-redis-host',
port: 6379,
password: 'this-is-secret',
}
];
const databaseMetricsLogger = new DatabaseMetricsLogger({databaseCredentials});
Subscribe metrics
to receive service metrics data:
databaseMetricsLogger.subscribe('metrics', data => {
// do some fancy stuff with your metrics
});
Subscribe logs
to receive general application logs:
databaseMetricsLogger.subscribe('logs', {message, level} => {
console[level](message));
});
Start database metrics logging:
databaseMetricsLogger.start();
Stop service metrics logging:
databaseMetricsLogger.stop();
Option | Description | Default Value |
---|---|---|
databaseType | Type of database. Currently only mongodb redis are available | |
name | Name of credential to identify your specific database in a mass of logs | your host |
host | Host of database | |
port (optional) | Port of database | |
uri (optional) | Instead of port and host, you can provide an URI | |
username (optional) | Username | |
password (optional) | Password | |
interval (optional) | Database metrics polling interval in ms | 10000 |
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 |
Id | Description |
---|---|
metrics | Service metrics |
logs | General application logs for levels debug , info , warn and error |
You can use a cloud connector to log metrics from your cloud instance databases.
Option | Description | Default Value |
---|---|---|
vcap (optional) | Provide local VCAP_SERVICES and/or VCAP_APPLICATION values | {} |
vcapFile (optional) | Provide local VCAP_SERVICES and/or VCAP_APPLICATION file | '' |
Method | Description |
---|---|
getCredentials() | Get Cloud Foundry service credentials |
// import using `CommonJS` module loader:
const { CloudFoundryConnector, DatabaseMetricsLogger } = require('cf-service-metrics-logger');
// or import using `ES6` module loader:
import { CloudFoundryConnector, DatabaseMetricsLogger } from 'cf-service-metrics-logger';
const options = {
vcapFile: 'your-vcap-file-path/vcap.json'
};
const cloudFoundryConnector = new CloudFoundryConnector(options);
const databaseCredentials = cloudFoundryConnector.getCredentials();
const databaseMetricsLogger = new DatabaseMetricsLogger({databaseCredentials});
databaseMetricsLogger.subscribe('metrics', data => {
// do some fancy stuff with your metrics
});
databaseMetricsLogger.start();
setTimeout(() => {
databaseMetricsLogger.stop();
}, 30000);
With transports you can log metrics to metrics services like Datadog. Datadog is currently the one and only implemented transport.
// import using `CommonJS` module loader:
const { DatabaseMetricsLogger, DatadogTransport } = require('database-metrics-logger');
// or import using `ES6` module loader:
import { DatabaseMetricsLogger, DatadogTransport } from 'database-metrics-logger';
const datadogTransport = new DatadogTransport({
apiKey: 'datadog-api-key',
appKey: 'datadog-app-key',
host: 'app.datadoghq.com',
tags: ['env:development']
});
const databaseCredentials = [
{
databaseType: 'mongodb',
host: 'your-mongodb-host',
username: 'user',
password: 'this-is-secret',
port: 27017,
database: 'your-database-name',
}
];
const databaseMetricsLogger = new DatabaseMetricsLogger({
databaseCredentials,
transports: [datadogTransport],
});
databaseMetricsLogger.start();
You need to set up your development environment before you can do anything.
Install Node.js and NPM
brew install node
choco install nodejs
Install yarn globally
yarn install yarn -g
Install all dependencies with yarn.
yarn install
yarn install
yarn run lint
. This runs tslint.yarn run test
.yarn run build
to generate commonJS and ES6 modules as well as declaration from the TypeScript source.dist
folder.Just set a breakpoint in source or unit test and hit F5 in your Visual Studio Code to execute and debug all unit tests.
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 |
rollup.config.js | Config for Rollup module bundler |
[0.8.4] - 2019-08-08
FAQs
log database metrics
The npm package database-metrics-logger receives a total of 3 weekly downloads. As such, database-metrics-logger popularity was classified as not popular.
We found that database-metrics-logger demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.