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 🙏

© 2026 – Pkg Stats / Ryan Hefner

grafana-dsl

v1.0.15

Published

A DSL for programmatically generating Grafana dashboard JSON.

Readme

Grafana-DSL

A DSL for programmatically generating Grafana dashboards. Currently, this module does not interface with Grafana's API. Instead, write the configurations to disk and configure Grafana to load the dashboards.

[dashboards.json]
enabled = true
path = /var/lib/dashboards

Installation

npm install -s grafana-dsl

Usage

import dashboard from 'grafana-dsl';

const backendDashboard = dashboard()
  .title('Backend Dashboard')
  .row(row => row()
    .graohPanel(panel => panel()
      .title('CPU')
      .span(12)
      .target(target => target()
        .expr('node_cpu')
        .datasource('Prometheus'))
      .alert(alert=> alert()
        .name('High CPU')
        .notifications([1])
        .condition(condition => condition()
          .when('max')
          .of(1)
          .isAbove(50)))));

// output
require('fs').writeFileSync(__dirname + '/backendDashboard.json', JSON.stringify(backendDashboard.serialize()));

In addition to the above syntax, you can also create objects like rows, panels, alerts, and more directly. This pattern enables reusable configuration components.

import dashboard, { graohPanel } from 'grafana-dsl';

const cpuGraph = graphPanel()
  .title('CPU')
  .span(12)
  .target(target => target()
    .expr('')
    .datasource('Prometheus'))
  .alert(alert => alert()
    .name('High CPU')
    .notifications([1])
    .condition(condition => condition()
      .when('avg')
      .of(1)
      .isAbove(50)));

const backendDashboard = dashboard()
  .row(row => row()
    .graphPanel(cpuGraph));

// output
require('fs').writeFileSync(__dirname + '/backendDashboard.json', JSON.stringify(backendDashboard.serialize()));

DSL

All top level DSL methods accept a config object. Use this parameter to directly pass raw Grafana configuration to accomodate cases where the DSL doesn't provide a required method.

Dashboard

|method|description|default| |---|---|---| |title|Set dashboard title|''| |tags|Set dashboard tags|[]| |refresh|Set refresh rate|1m| |time(from,to='now')|Set time range|from=now-1h to=now |template|Add template variable. Accepts either a callback function receiving template DSL function, or a pre-configured template object|| |row|Add row. Accepts either a callback function receiving row DSL function, or a pre-built row object||

Template

|method|description|default| |---|---|---| |name|Set template variable name|''| |type|Set template variable type (e.g: query,custom)|''| |multi(val=true)|Toggle multi-select|false| |includeAll(val=true)|Include all option|false| |query|Template variable query. For type=custom, a comma delimited list of options|| |datasource|For type=query, set the datasource|| |regex|For type=query, apply a regex against each return value|| |refreshOnLoad|Sets refresh=1 to enable variable refresh on dashboard load|| |refreshOnTimeChange|Sets refresh=2 to enable variable refresh on time change||

Row

|method|description|default| |---|---|---| |title|Set row title|''| |singleStatPanel|Accepts either a callback function receiving singleStatPanel DSL function, or a pre-configured singleStatPanel object|| |graphPanel|Accepts either a callback function receiving graphPanel DSL function, or a pre-configured graphPanel object||

graphPanel

|method|description|default| |---|---|---| |title|Set panel title|''| |span|Set panel span (Out of 12 columns)|12| |datasource|Set panel datasource|''| |lines|Toggle lines draw mode|true| |points|Toggle lines draw mode|false| |bars|Toggle lines draw mode|false| |format|Shortcut for setting yaxes.format|``| |fill|Set fill transparency 0-10|1| |yaxes|Configure yaxes for graph. Accepts either a callback function receiving yaxes DSL function, or a pre-configured yaxes object|| |target|Add target to panel. Accepts either a callback function receiving target DSL function, or a pre-configured target object|| |alert|Configure alerting for panel. Accepts either a callback function receiving an alert DSL function, or a pre-configured alert object||

singleStatPanel

|method|description|default| |---|---|---| |title|Set panel title|''| |span|Set panel span (Out of 12 columns)|12| |format|Set data format (e.g short, percent)|'short'| |datasource|Set panel datasource|''| |target|Add target to panel. Accepts either a callback function receiving target DSL function, or a pre-configured target object|| |sparkline|Enable sparklines. Accepts either a callback function receiving a sparkline DSL function, or a pre-configured sparkline object|| |alert|Configure alerting for panel. Accepts either a callback function receiving an alert DSL function, or a pre-configured alert object|| |valueName|Set value name property for panel|'avg'|

Target

Configure a panel target.

|method|description|default| |---|---|---| |expr|The query to execute|''| |legendFormat|Configure target's legend format||

sparkline

Configure singlestat panel sparkline.

|method|description|default| |---|---|---| |show(val=true)|Show sparkline|false| |full(val=true)|Set sparkline to full background mode|false| |fillColor({rgba(,,,)})|Set sparkline fill color|'rgba(31, 118, 189, 0.18)'| |lineColor({rgb(,,,)})|Set sparkline line color|'rgb(31, 120, 193)'|

yaxes

Configure panel yaxes for graphPanel |method|description|default| |---|---|---| |format|Set data format|'short'| |show|Show y axes|true| |max|Set max value|| |`min`|Set min value||

Alert

Configure a panel alert. Currently only for graphPanel

|method|description|default| |---|---|---| |name|Set alert name|''| |frequency|Set alert check frequency|''| |notifications([{0-9},])|Set alert notifications. Pass in the notification ID. You can find this from the notification edit page (e.g /alerting/notification/1/edit -> .notifications([1]))|[]| |condition|Configure an alert condition. Accepts either a callback function receiving a condition DSL function, or a pre-configured condition object||

Condition

Configure an alert condition.

|method|description|default| |---|---|---| |when|e.g: avg,min,max,sum,median,count,last|'avg'| |of(index,start='5m',end='now')|Set the alert query target and window. The first param is the id of a configured panel target. If your panel has a single target, you would pass 1|index=null start='5m' end='now'| |isAbove(val)|Set condition evaluator to gt|| |isBelow(val)|Set alert condition evaluator to lt|| |isOutsideRange(from, to)|Set alert condition evaluator to outside_range|| |isWithintRange(from, to)|Set alert condition evaluator to within_range|| |hasNoValue|Set alert condition evaluator to no_value||

Contributors