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

node-red-contrib-prometheus-exporter-enhanced

v1.0.0

Published

A NodeRED node which allows exporting Prometheus metrics from within flows. Enhanced with additional metrics and noop.

Downloads

2

Readme

node-red-contrib-prometheus-exporter-enhanced

A NodeRED node which allows exporting Prometheus metrics from within flows.

Using this node for NodeRED, you can define your own Prometheus metrics which will become available over an HTTP endpoint. The endpoint can be polled from a Prometheus agent or Telegraf.

Supported metric types:

  • Counter
  • Gauge
  • Histogram
  • Summary

Labels are supported for all metric types.

How to install

The preferred way of installing the node is to use the Palette Manager in NodeRED. Just seek for node-red-contrib-prometheus-exporter-enhanced and follow the instructions.

Alternatively, you can also manually install the node permanently into your embedded NodeRED application with npm:

npm install node-red-contrib-prometheus-exporter-enhanced

How to use

Configure a metric

From the Palette Manager, pull the node "prometheus out" in the network section into your flow.

In the editor of the metric node, create a new metric by clicking the pencil button next to the "Metric" drop down box. The config node editor will fire up.

In the config node editor, define the metric as you like. Name, help, and metric type are mandatory. Label names are optional. To learn more about Prometheus metrics, please refer to the Prometheus documentation.

Using the metric in a flow

After you have defined the metric, you can now feed the metric with values to actually populate the metrics output.

The node expects a message.payload as input with the following structure:

{
    "reset": false,
    "op": "inc",
    "val": 5,
    "labels": {
        "tag_1": "computer_123"
    }
}

Set reset if you want to reset the metric before the operation is executed. Defaults to false.

Choose the op property from one of the following values:

  • For metrics of type Counter:
    • inc - Increases the counter by val (without specifying val, defaults to 1)
  • For metrics of type Gauge:
    • set - Sets the gauge to val (which is mandatory for this operation)
    • inc - Increases the gauge by val (without specifying val, defaults to 1)
    • dec - Decreases the gauge by val (without specifying val, defaults to 1)
  • For metrics of type Histogram and Summary:
    • observe - Observe val (which is mandatory for this operation)
  • Additionally, all metrics support the nop 'no-operation' mode, which does nothing. Useful for resets

As described above, the val property is mandatory or optional depending on the selected op and the metric type.

Labels are always optional. Make sure, you only use label keys, which you have defined in the configuration of the node as "Labels".

Check the metrics output

Deploy the flow, open up the browser and access the /metrics endpoint of your NodeRED server.

The output should look like this:

# HELP example_counter This is an example Counter
# TYPE example_counter counter
example_counter 10

# HELP example_gauge This is an example Gauge
# TYPE example_gauge gauge
example_gauge{tag_1="computer_123"} 5
example_gauge 5

# HELP example_histogram This is an example Histogram
# TYPE example_histogram histogram
example_histogram_bucket{le="0.005"} 0
example_histogram_bucket{le="0.01"} 0
example_histogram_bucket{le="0.025"} 0
example_histogram_bucket{le="0.05"} 0
example_histogram_bucket{le="0.1"} 0
example_histogram_bucket{le="0.25"} 0
example_histogram_bucket{le="0.5"} 0
example_histogram_bucket{le="1"} 1
example_histogram_bucket{le="2.5"} 1
example_histogram_bucket{le="5"} 1
example_histogram_bucket{le="10"} 1
example_histogram_bucket{le="+Inf"} 1
example_histogram_sum 1
example_histogram_count 1

# HELP example_summary This is an example Summary
# TYPE example_summary summary
example_summary{quantile="0.01"} 0.1
example_summary{quantile="0.05"} 0.1
example_summary{quantile="0.5"} 0.1
example_summary{quantile="0.9"} 0.1
example_summary{quantile="0.95"} 0.1
example_summary{quantile="0.99"} 0.1
example_summary{quantile="0.999"} 0.1
example_summary_sum 0.1
example_summary_count 1

Changing the path

You can manually change the path under which the metrics are exposed. Just set the environment variable PROMETHEUS_METRICS_PATH to a path of your choice.

Expose default metrics

You can easily collect and expose a useful set of pre-defined metrics about the node.js process hosting the NodeRED environment. These metrics are disabled by default, but you can activate them by setting the environment variable PROMETHEUS_COLLECT_DEFAULT_METRICS to true.

License

This library is licensed under Apache 2.0.

Credits

NodeRED is an awsome and carefully-written low-code environment for node.js. This library has been written and tested against NodeRED v1.2.

Under the hood, this library is built on top of the prom-client, a mature Prometheus client for node.js.

This project is sponsored by docoyo.