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

promes

v0.1.3

Published

PromES: Prometheus Exporter for Serverless applications, exposing cost and performance related metrics of your running functions

Downloads

20

Readme

NodeJS Prometheus Exporter for Serverless

This package is part of Serverless Metrics Dashboard (Github). You need a server component to push your metrics to. A guide and an example can be found on the linked Github page.

promES

Prometheus Exporter for Serverless

No-dependency package to push metrics to prometheus-aggregator by Peter Bourgon. The library is currently only implemented for Microsoft Azure Functions. To use other providers, you only need to add a new metadataManager implementation. See Metadata Manager for details.

Requirements

  • Address to the Prometheus Aggregator as environment variable "PROMETHEUS_AGGREGATOR_ADDRESS" in url format tcp://address:port. TCP can optionally be replaced with upd, if enabled in the Prometheus Aggregator. Environment variables for Azure Functions can be set in the Function App (Platform Features -> Application Settings) or via Azure CLI (e.g. az functionapp config appsettings set ... --settings PROMETHEUS_AGGREGATOR_ADDRESS=<address>). You can also pass the address to the constructor of FunctionMetrics
  • Install promES via npm and make sure that the node_modules folder gets deployed to the cloud (might depend on deployment method and provider)

Use The Library

An easy example can be found in the Azure example Hello World function.

The current implementation supports the following metrics (all metrics are sent immediately):

  • logFunctionStart(): Adds +1 to the function_invocations_total metric. In addition you can enable RAM-tracking by setting parameter 1 to true and by setting parameter 2 to a track interval in milliseconds. The library will save the RAM usage at the given interval. The RAM usage is multiplied with the execution time to estimate the used GB-seconds. RAM tracking is terminated after logFunctionEnd() was called
  • logFunctionEnd() sends +1 to the function_finished_total metric and the execution time in milliseconds to function_execution_time_total. It also sends the estimated GB-seconds if RAM tracking was enabled in logFunctionStart()
  • logCustomMetric() allows you to send a custom metric to the Prometheus Aggregator. The first two parameters, metric name and metric value, are required

Metadata Manager

You can use the azureMetadataManager as an example. Required methods are:

  • getDefaultLabels() returning a JSON object with labels for Prometheus in key-value format. Prometheus Aggregator sums the values of a metric if the label values of a metric are identical. The default labels are used for basic logFunctionStart/End metrics and can be optionally used for custom metrics. The labels should enable a clear distinction between the different functions. Because Azure groups functions in Function Apps a function_app label is required. This might not be necessary for your provider.
  • getInvocationId() should exist in case you want to send metrics which should not be aggregated. The invocation ID should be a unique identifier for the current execution of the Function. This method is required for PromCES.
  • getAggregatorUrlEnv() to read the address to Prometheus Aggregator from an environment variable. (getGatewayUrlEnv is only necessary for promCES)
  • a log() function which ideally allows any amount of parameters just like console.log()

Feel free to create a Pull Request with your implementation!