datadog_dashboards
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -74,7 +74,5 @@ 'use strict'; | ||
}, | ||
s3_buckets: { | ||
uploads: { | ||
title: 's3', | ||
name: 's3-name' | ||
} | ||
s3: { | ||
title: 's3', | ||
name: 's3-name' | ||
}, | ||
@@ -81,0 +79,0 @@ caches: { |
@@ -6,8 +6,9 @@ const Templates = require("../../lib/templates"); | ||
* Creates a cpu usage timeseries by pool | ||
* @param {object} asgs | ||
* @param {object} vars | ||
* @param {object} state | ||
*/ | ||
asg_cpu(asgs, state) { | ||
asg_cpu(vars, state) { | ||
return Templates.jsonFromTemplate("templates/asg_cpu.hbs", { | ||
asgs: asgs, | ||
asgs: vars.asgs, | ||
region: vars.region, | ||
width: 44, | ||
@@ -22,8 +23,9 @@ height: 16, | ||
* Creates an instance count timeseries | ||
* @param {object} asgs | ||
* @param {object} vars | ||
* @param {object} state | ||
*/ | ||
asg_instancesInService(asgs, state) { | ||
asg_instancesInService(vars, state) { | ||
return Templates.jsonFromTemplate("templates/asg_instancesInService.hbs", { | ||
asgs: asgs, | ||
asgs: vars.asgs, | ||
region: vars.region, | ||
width: 44, | ||
@@ -38,6 +40,6 @@ height: 16, | ||
* Creates network in/out timeseries graphs | ||
* @param {object} asgs | ||
* @param {object} vars | ||
* @param {object} state | ||
*/ | ||
asg_network(asgs, state) { | ||
asg_network(vars, state) { | ||
var widgets = []; | ||
@@ -47,3 +49,4 @@ | ||
type: 'In', | ||
asgs: asgs, | ||
asgs: vars.asgs, | ||
region: vars.region, | ||
width: 43, | ||
@@ -56,3 +59,4 @@ height: 16, | ||
type: 'Out', | ||
asgs: asgs, | ||
asgs: vars.asgs, | ||
region: vars.region, | ||
width: 43, | ||
@@ -59,0 +63,0 @@ height: 16, |
432
index.js
#!/usr/bin/env node | ||
// Command-line tool to generate datadog dashboards from a config file | ||
require("dotenv").config(); | ||
Dashboards = require("./dashboards"); | ||
const { version } = require('./package.json'); | ||
ScreenboardService = require("./services/screenboard"); | ||
CloudwatchAlbGraphFactory = require("./factories/cloudwatch/alb"); | ||
CloudwatchAsgGraphFactory = require("./factories/cloudwatch/asg"); | ||
CloudwatchDynamoPanelFactory = require("./factories/cloudwatch/dynamodb"); | ||
CloudwatchElasticacheGraphFactory = require("./factories/cloudwatch/elasticache"); | ||
CloudwatchKinesisGraphFactory = require("./factories/cloudwatch/kinesis"); | ||
CloudwatchLambdaGraphFactory = require("./factories/cloudwatch/lambda"); | ||
CloudwatchRdsGraphFactory = require("./factories/cloudwatch/rds"); | ||
CloudwatchSqsGraphFactory = require("./factories/cloudwatch/sqs"); | ||
CloudwatchS3GraphFactory = require("./factories/cloudwatch/s3"); | ||
InstStatsdRequestsGraphFactory = require("./factories/statsd/inst-statsd-requests"); | ||
DelayedJobsGraphFactory = require("./factories/statsd/delayed-jobs"); | ||
CustomGraphFactory = require("./factories/custom"); | ||
const chalk = require("chalk"); | ||
@@ -15,2 +26,3 @@ const CLI = require("clui"); | ||
const prompt = require("prompt-sync")(); | ||
const Spinner = CLI.Spinner; | ||
const path = require("path"); | ||
@@ -63,8 +75,416 @@ const ROOT_PATH = process.cwd(); | ||
const dashboards = new Dashboards(dashboardsConfig.dashboardsByEnvironment) | ||
function getDashboardJsonString(dashboardConfig, prettyPrint = false) { | ||
const generated = generateEnvironmentDashboard(dashboardConfig); | ||
return JSON.stringify(generated, null, prettyPrint ? 2 : null); | ||
} | ||
/** | ||
* Creates the dashboards based on the config. | ||
* Determines whether to do a create or an updated based on the title of the dashboard. | ||
* @param {*} dashboardsConfig | ||
*/ | ||
function createDashboards(dashboardsConfig) { | ||
const spinnerStatus = new Spinner( | ||
"Retrieving existing dashboards, please wait..." | ||
); | ||
spinnerStatus.start(); | ||
const screenboardSvc = new ScreenboardService( | ||
DATADOG_API_API_KEY, | ||
DATADOG_API_APP_KEY | ||
); | ||
screenboardSvc.getAllScreenboards().then(res => { | ||
spinnerStatus.stop(); | ||
return Promise.all( | ||
dashboardsConfig.dashboardsByEnvironment.map(dashboardConfig => { | ||
const existingBoardId = screenboardSvc.getScreenboardIdByTitle( | ||
dashboardConfig.title | ||
); | ||
const jsonString = getDashboardJsonString(dashboardConfig); | ||
if (existingBoardId) { | ||
console.log(`Updating ${dashboardConfig.title}`); | ||
return screenboardSvc.updateScreenboard( | ||
existingBoardId, | ||
dashboardConfig.title, | ||
jsonString | ||
); | ||
} else { | ||
console.log(`Creating ${dashboardConfig.title}`); | ||
return screenboardSvc.createScreenboard( | ||
dashboardConfig.title, | ||
jsonString | ||
); | ||
} | ||
}) | ||
) | ||
.then(() => { | ||
console.log(); | ||
console.log(chalk.green.bold("Done!")); | ||
}) | ||
.catch(err => { | ||
console.log(chalk.red.bold("Failed!")); | ||
console.log(err); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Previews the dashboard JSON and outputs it to stdout | ||
* @param {*} dashboardsConfig | ||
*/ | ||
function previewDashboards(dashboardsConfig) { | ||
dashboardsConfig.dashboardsByEnvironment.map(dashboardConfig => { | ||
console.log(chalk.green.bold(`Dashboard - ${dashboardConfig.title}`)); | ||
const jsonString = getDashboardJsonString(dashboardConfig, true); | ||
console.log(jsonString) | ||
}) | ||
} | ||
if (program.preview) { | ||
dashboards.preview() | ||
previewDashboards(dashboardsConfig); | ||
} else { | ||
dashboards.create(DATADOG_API_API_KEY, DATADOG_API_APP_KEY) | ||
createDashboards(dashboardsConfig); | ||
} | ||
function titleWidget(title, state) { | ||
var widget = { | ||
type: 'free_text', | ||
font_size: '24', | ||
title: true, | ||
text: title, | ||
height: 3, | ||
width: 117, | ||
x: 0, | ||
y: state.position | ||
} | ||
state.position += 4; | ||
return widget; | ||
} | ||
function generateCustomWidgets(customWidgets, widgets = [], state) { | ||
if (!customWidgets) return; | ||
const factory = new CustomGraphFactory(); | ||
Object.keys(customWidgets).forEach(function(key) { | ||
widgets.push(factory.render(customWidgets[key], state)); | ||
}) | ||
} | ||
/** | ||
* Generates widgets for all load balancers. | ||
* | ||
* @param {object} load_balancers | ||
* @param {array} widgets | ||
* @param {object} state | ||
*/ | ||
function generateAlbGraphs(load_balancers, widgets = [], state) { | ||
if (!load_balancers) return; | ||
const factoryAlb = new CloudwatchAlbGraphFactory(); | ||
for (var lb of load_balancers) { | ||
const lbName = lb.targetgroup_name ? `Load Balancer: Target Group ${lb.targetgroup_name}` : 'Load Balancer' | ||
widgets.push(titleWidget(lbName, state)); | ||
widgets.push(...factoryAlb.alb_totalRequests(lb, state)); | ||
widgets.push(factoryAlb.alb_hits(lb, state)); | ||
widgets.push(factoryAlb.alb_latency(lb, state)); | ||
widgets.push(factoryAlb.alb_health(lb, state)); | ||
state.position += 30; | ||
} | ||
} | ||
/** | ||
* Generates widgets for instances in all auto scaling groups. | ||
* | ||
* @param {object} vars | ||
* @param {array} widgets | ||
* @param {object} state | ||
*/ | ||
function generateAsgGraphs(vars, widgets = [], state) { | ||
if (!vars.asgs) return; | ||
const factoryAsg = new CloudwatchAsgGraphFactory(); | ||
widgets.push(titleWidget('Auto Scaling Groups', state)); | ||
widgets.push(factoryAsg.asg_cpu(vars, state)); | ||
widgets.push(factoryAsg.asg_instancesInService(vars, state)); | ||
widgets.push(...factoryAsg.asg_network(vars, state)); | ||
widgets.push(...factoryAsg.asg_hosts(vars, state)); | ||
state.position += 38; | ||
} | ||
function generateInstStatsdRequestsGraphs(requests, project, environment, region, widgets = [], state) { | ||
if (!requests) return; | ||
const factoryRequests = new InstStatsdRequestsGraphFactory(requests, project, environment, region); | ||
widgets.push(titleWidget('Requests', state)); | ||
widgets.push(factoryRequests.totalTimeGraph(state)); | ||
widgets.push(factoryRequests.countGraph(state)); | ||
state.position += 30; | ||
widgets.push(...factoryRequests.toplists(state)); | ||
state.position += 16; | ||
} | ||
function generateDelayedJobsGraphs(delayed_jobs, project, environment, region, widgets = [], state) { | ||
if (!delayed_jobs) return; | ||
const factoryJobs = new DelayedJobsGraphFactory(delayed_jobs, project, environment, region); | ||
widgets.push(titleWidget('Jobs', state)); | ||
widgets.push(...factoryJobs.executedFailedCounts(state, 0)); | ||
widgets.push(...factoryJobs.executedFailedTimeseries(state, 21)); | ||
widgets.push(...factoryJobs.runtimeAndOldestJob(state, 66)); | ||
state.position += 48; | ||
} | ||
function generateLambdasGraphs(lambdas, region, widgets = [], state) { | ||
if (!lambdas) return; | ||
const factory = new CloudwatchLambdaGraphFactory(region); | ||
Object.keys(lambdas).forEach(key => { | ||
widgets.push(titleWidget(`Lambda: ${lambdas[key].title}`, state)); | ||
widgets.push(factory.render('invocations', lambdas[key], state)); | ||
widgets.push(factory.render('duration', lambdas[key], state)); | ||
state.position += 22; | ||
}); | ||
} | ||
function generateKinesisStreamsGraphs(streams, widgets = [], state) { | ||
if (!streams) return; | ||
const factory = new CloudwatchKinesisGraphFactory(); | ||
Object.keys(streams).forEach(key => { | ||
widgets.push(titleWidget(`Kinesis: ${streams[key].title}`, state)); | ||
widgets.push(factory.render('iteratorAge', streams[key], state)); | ||
widgets.push(factory.render('records', streams[key], state)); | ||
widgets.push(factory.render('throughput', streams[key], state)); | ||
state.position += 21; | ||
}); | ||
return widgets; | ||
} | ||
function generateDynamoTablesGraphs(tables, region, widgets = [], state) { | ||
if (!tables || !region) return; | ||
const factory = new CloudwatchDynamoPanelFactory(region); | ||
Object.keys(tables).forEach(function(key) { | ||
widgets.push(titleWidget(`DynamoDB: ${tables[key].title}`, state)); | ||
widgets.push(...factory.units(tables[key], state)); | ||
widgets.push(factory.throttled(tables[key], state)); | ||
state.position += 16; | ||
}); | ||
} | ||
function generateCachesGraphs(caches, widgets = [], state) { | ||
if (!caches) return; | ||
const factory = new CloudwatchElasticacheGraphFactory(); | ||
Object.keys(caches).forEach(function(key) { | ||
widgets.push(titleWidget(`ElastiCache: ${caches[key].title}`, state)); | ||
widgets.push(factory.render('cpu', caches[key], state)); | ||
widgets.push(factory.render('items', caches[key], state)); | ||
widgets.push(factory.render('memory', caches[key], state)); | ||
state.position += 16; | ||
widgets.push(factory.render('hits', caches[key], state)); | ||
widgets.push(factory.render('evictions', caches[key], state)); | ||
if (caches[key].type === 'redis') { | ||
widgets.push(factory.render('redis_commands', caches[key], state)); | ||
} | ||
state.position += 16; | ||
}); | ||
} | ||
function generateSqsGraphs(queues, region, widgets = [], state) { | ||
if (!queues || !region) return; | ||
const factory = new CloudwatchSqsGraphFactory(region); | ||
Object.keys(queues).forEach(function(key) { | ||
widgets.push(titleWidget(`SQS: ${queues[key].title}`, state)); | ||
widgets.push(factory.render('visibilityCount', queues[key], state)); | ||
widgets.push(factory.render('deletedCount', queues[key], state)); | ||
widgets.push(factory.render('visibility', queues[key], state)); | ||
widgets.push(factory.render('deleted', queues[key], state)); | ||
state.position += 20; | ||
}); | ||
} | ||
function generateRdsGraphs(rdsIds, widgets = [], state) { | ||
if (!rdsIds) return; | ||
const rds = new CloudwatchRdsGraphFactory(); | ||
rdsIds.forEach(function(rdsInstance) { | ||
let rdsId; | ||
let rdsName = null; | ||
if (typeof rdsInstance === 'string' || rdsInstance instanceof String) { | ||
rdsId = rdsInstance; | ||
} else { | ||
rdsId = rdsInstance.id; | ||
rdsName = rdsInstance.name; | ||
} | ||
widgets.push(titleWidget(`RDS: ${rdsName ? `${rdsName} (${rdsId})` : rdsId}`, state)); | ||
widgets.push(rds.render('rds_cpu', rdsId, state)); | ||
widgets.push(rds.render('rds_connections', rdsId, state)); | ||
widgets.push(rds.render('rds_iops', rdsId, state)); | ||
state.position += 16; | ||
widgets.push(rds.render('rds_memory', rdsId, state)); | ||
widgets.push(rds.render('rds_throughput', rdsId, state)); | ||
widgets.push(rds.render('rds_burstBalance', rdsId, state)); | ||
state.position += 16; | ||
widgets.push(rds.render('rds_storage', rdsId, state)); | ||
widgets.push(rds.render('rds_tx_log_gen', rdsId, state)); | ||
widgets.push(rds.render('rds_slot_lag', rdsId, state)); | ||
state.position += 16; | ||
}) | ||
} | ||
function generateS3BucketGraphs(buckets, widgets = [], state) { | ||
if (!buckets) return; | ||
const factory = new CloudwatchS3GraphFactory(); | ||
Object.keys(buckets).forEach(function(key) { | ||
widgets.push(titleWidget(`S3: ${buckets[key].title}`, state)); | ||
widgets.push(factory.render('totalCount', buckets[key], state)); | ||
widgets.push(factory.render('totalSize', buckets[key], state)); | ||
widgets.push(factory.render('count', buckets[key], state)); | ||
widgets.push(factory.render('size', buckets[key], state)); | ||
state.position += 20; | ||
}); | ||
} | ||
function generateEnvironmentDashboard(vars) { | ||
var dashboard = { | ||
board_title: vars.title, | ||
description: vars.description || "A great dashboard!", | ||
template_variables: vars.template_variables, | ||
widgets: [] | ||
}; | ||
var state = { | ||
position: 0 | ||
}; | ||
// Custom widgets | ||
if (vars.custom) { | ||
if (!vars.custom_height) { | ||
console.log(chalk.red('You must define the height you want reserved for custom graphs in "custom_height" setting.')); | ||
process.exit(1); | ||
} | ||
dashboard.widgets.push(titleWidget(vars.custom_title || 'Custom Graphs', state)); | ||
generateCustomWidgets(vars.custom, dashboard.widgets, state); | ||
state.position += vars.custom_height; | ||
} | ||
// ALB | ||
if (vars.alb) { | ||
generateAlbGraphs(vars.alb, dashboard.widgets, state); | ||
} | ||
// ASGS | ||
if (vars.asgs) { | ||
generateAsgGraphs(vars, dashboard.widgets, state); | ||
} | ||
// Requests | ||
if (vars.inst_statsd_requests) { | ||
// Use the specific project for statsd or use the default one | ||
var projectStatsd = vars.inst_statsd_requests.project || vars.project | ||
generateInstStatsdRequestsGraphs(vars.inst_statsd_requests, projectStatsd, vars.environment, | ||
vars.region, dashboard.widgets, state); | ||
} | ||
// Jobs | ||
if (vars.delayed_jobs) { | ||
// Use the specific project for statsd or use the default one | ||
var projectStatsd = vars.delayed_jobs.project || vars.project | ||
generateDelayedJobsGraphs(vars.delayed_jobs, projectStatsd, vars.environment, | ||
vars.region, dashboard.widgets, state); | ||
} | ||
// RDS | ||
// Support multiple RDS instances in an backwards compatible fashion | ||
if (vars.rds_id) { | ||
generateRdsGraphs([vars.rds_id], dashboard.widgets, state); | ||
} | ||
if (vars.rds_ids) { | ||
generateRdsGraphs(vars.rds_ids, dashboard.widgets, state); | ||
} | ||
// Caches | ||
if (vars.caches) { | ||
generateCachesGraphs(vars.caches, dashboard.widgets, state); | ||
} | ||
// Lambdas | ||
if (vars.lambdas) { | ||
generateLambdasGraphs(vars.lambdas, vars.region, dashboard.widgets, state); | ||
} | ||
// Kinesis | ||
if (vars.kinesis_streams) { | ||
generateKinesisStreamsGraphs(vars.kinesis_streams, dashboard.widgets, state); | ||
} | ||
// Dynamo tables | ||
if (vars.dynamo_tables) { | ||
generateDynamoTablesGraphs(vars.dynamo_tables, vars.region, dashboard.widgets, state); | ||
} | ||
// SQS Queues | ||
if (vars.sqs_queues) { | ||
generateSqsGraphs(vars.sqs_queues, vars.region, dashboard.widgets, state); | ||
} | ||
// S3 | ||
if (vars.s3_buckets) { | ||
generateS3BucketGraphs(vars.s3_buckets, dashboard.widgets, state); | ||
} | ||
return dashboard; | ||
} |
{ | ||
"name": "datadog_dashboards", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "A quick way to generate helpful, pre-canned datadog dashboards for Cloudwatch.", | ||
"engines": { | ||
"node": "^10", | ||
"npm": "^6" | ||
}, | ||
"main": "index.js", | ||
"dependencies": { | ||
"aws-sdk": "^2.543.0", | ||
"btoa": "^1.1.2", | ||
"callsites": "^3.0.0", | ||
"chalk": "^2.4.2", | ||
"callsites": "^3.1.0", | ||
"chalk": "^4.1.0", | ||
"clui": "^0.3.6", | ||
"commander": "^2.19.0", | ||
"dotenv": "^6.2.0", | ||
"figlet": "^1.2.1", | ||
"handlebars": "^4.4.3", | ||
"merge-deep": "^3.0.2", | ||
"node-fetch": "^2.3.0", | ||
"prompt-sync": "^4.1.5", | ||
"title-case": "^2.1.1" | ||
"commander": "^5.1.0", | ||
"dotenv": "^8.2.0", | ||
"figlet": "^1.4.0", | ||
"handlebars": "^4.7.6", | ||
"node-fetch": "^2.6.0", | ||
"prompt-sync": "^4.2.0" | ||
}, | ||
@@ -21,0 +22,0 @@ "bin": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
125208
10
73
6
1286
+ Addedansi-styles@4.3.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcommander@5.1.0(transitive)
+ Addeddotenv@8.6.0(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedsupports-color@7.2.0(transitive)
- Removedaws-sdk@^2.543.0
- Removedmerge-deep@^3.0.2
- Removedtitle-case@^2.1.1
- Removedansi-styles@3.2.1(transitive)
- Removedarr-union@3.1.0(transitive)
- Removedavailable-typed-arrays@1.0.7(transitive)
- Removedaws-sdk@2.1692.0(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbuffer@4.9.2(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedchalk@2.4.2(transitive)
- Removedclone-deep@0.2.4(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcommander@2.20.3(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddotenv@6.2.0(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedevents@1.1.1(transitive)
- Removedfor-each@0.3.3(transitive)
- Removedfor-in@0.1.81.0.2(transitive)
- Removedfor-own@0.1.5(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedieee754@1.1.13(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-arguments@1.1.1(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-callable@1.2.7(transitive)
- Removedis-extendable@0.1.1(transitive)
- Removedis-generator-function@1.0.10(transitive)
- Removedis-plain-object@2.0.4(transitive)
- Removedis-typed-array@1.1.13(transitive)
- Removedisarray@1.0.0(transitive)
- Removedisobject@3.0.1(transitive)
- Removedjmespath@0.16.0(transitive)
- Removedkind-of@2.0.13.2.2(transitive)
- Removedlazy-cache@0.2.71.0.4(transitive)
- Removedlower-case@1.1.4(transitive)
- Removedmerge-deep@3.0.3(transitive)
- Removedmixin-object@2.0.1(transitive)
- Removedno-case@2.3.2(transitive)
- Removedpossible-typed-array-names@1.0.0(transitive)
- Removedpunycode@1.3.2(transitive)
- Removedquerystring@0.2.0(transitive)
- Removedsax@1.2.1(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedshallow-clone@0.1.2(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedtitle-case@2.1.1(transitive)
- Removedupper-case@1.1.3(transitive)
- Removedurl@0.10.3(transitive)
- Removedutil@0.12.5(transitive)
- Removeduuid@8.0.0(transitive)
- Removedwhich-typed-array@1.1.15(transitive)
- Removedxml2js@0.6.2(transitive)
- Removedxmlbuilder@11.0.1(transitive)
Updatedcallsites@^3.1.0
Updatedchalk@^4.1.0
Updatedcommander@^5.1.0
Updateddotenv@^8.2.0
Updatedfiglet@^1.4.0
Updatedhandlebars@^4.7.6
Updatednode-fetch@^2.6.0
Updatedprompt-sync@^4.2.0