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

ambrite-mdd

v0.0.24

Published

ambrite mdd

Downloads

3

Readme

ambrite-mdd library

Use this library in your server side (node) TypeScript (or javascript) code.

Uses Stackdriver to LOG and MONTIOR.

Logging

Log-line based reporting, featuring:

  • text payloads
  • json payloads
  • severities
  • logBook name

Monitoring

Write logs to custom metrics. NOTE: don't use too many different log names.

  • custom names
  • custom labels
  • time-series based

Installation

npm install -s ambrite-mdd

Note: includes TypeScript types.

Usage

Logging

Installation

Import the library, Logger part: import { Logger } from "ambrite-mdd"

Add new logBook (or reference an old one)

Setup a new log: const log = new Logger(projectId, logName) where projectId is the name of the GCP project and logName is the name of the log to write to.

Write a log

And finally to write a log: log.debug("some string")

or generic: log.level(payload)

LogLevel

where the level is one of:

  • log.log(...) uses DEFAULT
  • log.debug(...) uses DEBUG
  • log.notice(...) uses NOTICE
  • log.warn(...) uses WARNING
  • log.error(...) uses ERROR
  • log.critical(...) uses CRITICAL
  • log.alert(...) uses ALERT
  • log.emergency(...) uses EMERGENCY

All these log levels are supported by stackdriver.

Payload

Currently, the payload you submit to the function is directly used in the stackdriver methods.

Specifically, you can use:

Text payloads; log.debug("Hello")

JSON payloads: log.debug({foo: {bar: 5}})

Retrieving logs

  • Go to the GCP console.
  • Go to the Logging subsection
  • Switch to advanced filter
  • start typing: logName (should auto-complete)
  • then type = and a drop down with all logBooks should appear, so you can just choose the log you need

Example: logName="projects/testProject/logs/testLog"

or generically: logName="projects/{projectID}/logs/{logName}"

Monitoring

Installation

Import the library, Monitoring part: import { Monitoring } from "ambrite-mdd"

Create a new metric (or reference an old one)

const monitoring = new Monitoring(projectId);
const metric = Monitoring.createMetric("testService/metric1", {
  label1: "tag1",
});

This creates a new metric on our project. Note that we could add more/other metrics with different tags.

Do NOT create too many metrics, but try to use labels to make differences.

This is all you need to configure a metric.

Writing to a metric

Now, in the code, you add a new point to the metric by:

monitoring.addPoint(123, metric);

This adds the point 123 to the metric. Note that this API allows us to simply define various metrics and ad-hoc choose the metric to write to.

Retrieving Metrics

  • Go to your GCP Project
  • Navigate to Monitoring
  • Go to the metrics explorer
  • Under the global resource, you should find your metric

Note: Might take a minute or two to feed through all the systems.