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

metrics-nodejs

v1.2.2

Published

Library wrapping Metric collection methods (to abstract out the actual transport solution)

Downloads

9

Readme

metrics-python

Morgan & Morgan wrapper for application metrics instrumentation.

Installation

pip install mm-metrics

Core API

Increment

Increment a counter for a metric.

increment(metric)

Gauge

Set the magnitude of a metric to a value

gauge(metric, value)

Histogram

Set a frequency metric to a value

histogram(metric, value)

Timer

Time the execution of a task, via either decorator or context manager

# as decorator
@timer(metric)

# as contextmanager
with timer(metric):

Environment Variables

| Name | Default | Description | | --- | --- | --- | | METRICS_DEFAULT_BACKEND | 'metrics.backends.DataDogMetricsBackend' | The dot-notation path to a metrics backend to default to | | DD_API_KEY | None | DataDog API Key | | DD_APP_KEY | None | DataDog App Key | | DD_SERVICE_NAME | None | The name of the current service. If set, every metric will be tagged by this value like 'service:' | | DD_SERVICE_PRIORITY | None | The priority of the current service, on a scale of 1-3 with 1 being highest priority. If set, every metric will be tagged by this value like 'priority:' | | DD_GLOBAL_TAGS | None | Any additional global tags to apply when metrics are sent. For instance, global tags like 'foobar:1,baz:2' would send tags ['foobar:1', 'baz:2'] with every metric |

Examples

  1. Time the execution of a task
from metrics.decorators import timer
import requests

@timer(metric='mm.connections.sf.sync.timer')
def sync_to_sf(data):
  resp = requests.post('https://sf-url.com', data=data)
  return resp.ok
  1. Increment an error counter when a function hits an error, increment a count counter when a function completes successfully
from metrics.decorators import increment


@increment(on_complete_metric='mm.connections.aws.secrets.count', on_error_metric='mm.connections.aws.secrets.errors.count')
def secrets():
  # get AWS secrets handle
  return boto3.client('secrets')
  1. Send some extra tags to attach to a metric (note: some backends might not support tagging and will simply disregard the parameter)
from metrics.decorators import increment


@increment(on_complete_metric='mm.requests.get.count', on_error_metric='mm.connections.get.errors.count', tags=['path:/'])
def get(self):
  return HttpResponse(status=200)

Motivation

Given that most client's have similar (and straightforward) requirements for metric tracking, we wrap these common methods (as well as helper tooling) in this abstract Python API. This gives us the flexibility to:

  • Maintain metric tracking functionality in a central location
  • Decouple metric tracking from core application functionality
  • Swap statsD providers opaquely (e.g DogStatsD -> Vanilla StatsD)

Additional Reading

  • For more detail on metrics collection at MM and metric naming guidelines, see the wiki page here