
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
grafana-dash-gen
Advanced tools
A collection of utility classes to construct and publish grafana graphs. The library is built ground up to incorporate grafana terminologies.

You will be able to generate and publish a grafana graph using the following steps.
if you would like grafana to publish your dashboard you need this step. If you do not need grafana to publish your dashboard, you can skip this step.
const grafana = require('grafana-dash-gen');
const Row = grafana.Row;
const Dashboard = grafana.Dashboard;
const Panels = grafana.Panels;
const Target = grafana.Target;
const Templates = grafana.Templates;
const Alert = grafana.Alert;
const Condition = grafana.Condition;
grafana.configure({
url: 'https://your.grafana.com/elasticsearch/grafana-dash/dashboard/',
cookie: 'auth-openid=someidhere'
});
const dashboard = new Dashboard({
title: 'Api dashboard'
});
(or) Below is an example of a dashboard with a custom slug, templates dc and smoothing and annotations.
const dashboard = new Dashboard({
title: 'Api dashboard',
slug: 'api',
templating: [{
name: 'dc',
options: ['dc1', 'dc2']
}, {
name: 'smoothing',
options: ['30min', '10min', '5min', '2min', '1min']
}],
annotations: [{
name: 'Deploy',
target: 'stats.$dc.production.deploy'
}]
});
If you do not wish to have any templates and annotations
As said abolve, grafana dashboard contains a number of rows.
const row = new Row();
There are two ways to add the graph to a row. Pass it while a graph is created as below
const panel = new Panels.Graph({
title: 'api req/sec',
span: 5,
targets: [
new Target('api.statusCode.*').
transformNull(0).sum().hitcount('1seconds').scale(0.1).alias('rps')
],
row: row,
dashboard: dashboard
});
(or) add it in a separate step
const panel = new Panels.Graph({
title: 'api req/sec',
span: 5,
targets: [
new Target('api.statusCode.*').
transformNull(0).sum().hitcount('1seconds').scale(0.1).alias('rps')
]
});
row.addPanel(panel);
If you would like to create a full width single stat (as in the image) the code is below. Notice how we create a new row on the fly.
const requestVolume = new Panels.SingleStat({
title: 'Current Request Volume',
postfix: 'req/sec',
targets: [
new Target('stats.$dc.counts').
sum().scale(0.1)
],
row: new Row(),
dashboard: dashboard
});
Alerts are optional. An alert is set on a target, each target added to the panel receives a refId of 'A', 'B', ..., 'Z'.
const conditionOnRequestLowVolume = new Condition()
.onQuery('A')
.withEvaluator(1, 'lt')
.withReducer('max');
const alert = new Alert({ name: 'Low volume of requests' });
alert.addCondition(conditionOnRequestLowVolume);
// OR
const alert = new Alert({ name: 'Low volume of requests' })
.addCondition(conditionOnRequestLowVolume);
requestVolume.addAlert(alert);
It is also possible to add an alert by passing it to the Graph constructor
const graphWithAnAlert = new Graph({ alert: YOUR_ALERT_OBJECT });
grafana.publish(dashboard);
to generate the json and not publish use
console.log(JSON.stringify(dashboard.generate()));
A complete example of a dashboard is provided in example.js
npm install grafana-dash-gen
npm test
FAQs
A grafana dashboard generator
The npm package grafana-dash-gen receives a total of 401 weekly downloads. As such, grafana-dash-gen popularity was classified as not popular.
We found that grafana-dash-gen demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 11 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.

Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.

Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.