New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

metricsfn

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metricsfn

Get metric data on your scripts

latest
Source
npmnpm
Version
1.0.41
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Metricsfn

Introduction

metricsfn is a lightweight JavaScript library designed to facilitate the collection of metrics and performance data in an application.

Installation

Install the library via npm:

npm install metricsfn

Usage


// Create an instance of Metrics
const metrics = new Metrics();

// Initialize Metrics
metrics.Init();

// Add an ID
metrics.ID(123);

// Add data
metrics.UserID('user123')
    .TimeSamp()
    .ParseErrors();

// Retrieve data
const data = metrics.env();
console.log(data);

Example

const axios = require('axios')
const Metrics = require('metricsfn')
const metrics = new Metrics();

async function makeRequest(url, method = 'GET', data = null) {
  metrics.Init();
  const id = 123
  metrics.ID(id);
  metrics.ID(id).TimeSamp()

  const datas = {};
  const metricsDatas = {};

  try {
    metrics.TimerStart(id);
    const response = await axios({
      method,
      url,
      data,
    });

    metrics.ID(id).FetchTimeExec(metrics.TimerStop(id)).Success()
    datas = response.data
    metricsDatas = metrics.ID(id).env()

    return {datas, metricsDatas};

  } catch (error) {
    metrics.ID(id).FetchTimeExec(metrics.TimerStop(id)).FetchError().Aborted()
    metricsDatas = metrics.ID(id).env()

    return {datas, metricsDatas};

  }

}

const apiUrl = 'https://jsonplaceholder.typicode.com/posts/1';
makeRequest(apiUrl, 'GET');

Available Methods

Init()

Initializes the Metrics library.

ID(id: string)

Adds a new ID to the data table.

  • id: Unique identifier.

UserID(data: string)

Adds the user ID to the data.

  • data: User ID.

TimeSamp()

Adds a timestamp to the data.

ParseErrors()

Increments the parse errors count in the data.

SyntaxErrors()

Increments the syntax errors count in the data.

FilterTimeExec(timesamp: string)

Adds filter execution time to the data.

  • timesamp: Timestamp of filter execution time.

GenerateTimeExec(timesamp: string)

Adds generation execution time to the data.

  • timesamp: Timestamp of generation execution time.

FetchTimeExec(timesamp: string)

Adds fetch execution time to the data.

  • timesamp: Timestamp of fetch execution time.

Aborted()

Indicates in the data that the operation was aborted.

Exited()

Indicates in the data that the operation was exited.

Success()

Indicates in the data that the operation was successful.

TimerStart(key: string)

Starts a timer with the specified key.

  • key: Timer key.

TimerStop(key: string)

Stops the timer and returns the elapsed time.

  • key: Timer key.

TimerClear(key: string)

Stops and clears the timer associated with the specified key.

  • key: Timer key.

env()

Gets the complete data array.

Keywords

metrics

FAQs

Package last updated on 09 Nov 2023

Did you know?

Socket

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.

Install

Related posts