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

@gapit/grafana-metric

v1.2.0

Published

Retrieves metric value

Downloads

10

Readme

HTMLGraphics metric

Retrieves metric value from Grafana's data interface.

Usage

The main difference between MetricValue and MetricData is that MetricValue is a single value while MetricData is an object

type MetricValue = unknown;

interface TimeData {
  first?: unknown;
  last?: unknown;
}

interface MetricData {
  calcs: { [key: string]: unknown };
  time: TimeData;
  hasData: boolean;
}

getMetricValueFromExpression

Evaluates a metric expression

import { getMetricValueFromExpression } from "@gapit/grafana-metric";

// random-metric = 100

getMetricValueFromExpression("'random-metric' * 2"); // Returns 200
getMetricValueFromExpression("Math.sqrt('random-metric')"); // Returns 10

getShowcaseMetricValue

Generate a random number

import { getShowcaseMetricValue } from "@gapit/grafana-metric";

getShowcaseMetricValue(); // Returns a value between 0 and 1000 with 2 decimals
getShowcaseMetricValue({ range: { min: x, max: y }, decimals: z }); // Return a random value between x and y with z decimals.

getMetricValueFromName

Gets a metric value by name/alias

import { getMetricValueFromName } from "@gapit/grafana-metric";

// metric-name = 100

getMetricValueFromName("metric-name"); // Returns 100
getMetricValueFromName("non-existing-metric"); // Returns null
getMetricValueFromName("non-existing-metric", { noDataValue: "No data" }); // Returns "No data"

getMetricValue

Function provides calculations for grafana queries.

import { getMetricValue } from "@gapit/grafana-metric";

// metric-name = 100

// From name
getMetricValue("metric-name"); // Returns 100

// No data
getMetricValue("non-existing-metric"); // Returns null
getMetricValue("non-existing-metric", { noDataValue: "No data" }); // Returns "No data"

// Evaluation string
getMetricValue("'metric-name' * 2"); // Returns 200
getMetricValue("Math.sqrt('metric-name')"); // Returns 10

// Showcase
getMetricValue("metric-name", { showcase: true }); // Returns a random value between 0 and 1000.
getMetricValue("metric-name", { showcase: true, range: { min: 0, max: 10 } }); // Returns random value between 1-10.
getMetricValue("metric-name", {
  showcase: true,
  range: { min: 0, max: 10 },
  decimals: 4,
}); // Returns random value between 1-10 with 4 decimals.

getMetricDataFromExpression

Evaluates a metric expression

getShowcaseMetricData

Generates a random metric data object

getMetricDataFromName

Gets metric data by name/alias

getMetricData

Gets metric data