forked from uber/grafana-dash-gen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
146 lines (132 loc) · 3.66 KB
/
Copy pathexample.js
File metadata and controls
146 lines (132 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
'use strict';
var grafana = require('./index');
var Row = grafana.Row;
var Dashboard = grafana.Dashboard;
var Panels = grafana.Panels;
var Target = grafana.Target;
// For grafana v1, the URL should look something like:
//
// https://your.grafana.com/elasticsearch/grafana-dash/dashboard/
//
// Bascially, grafana v1 used elastic search as its backend, but grafana v2
// has its own backend. Because of this, the URL for grafana v2 should look
// something like this:
//
// https://your.grafanahost.com/grafana2/api/dashboards/db/
grafana.configure({
url: 'https://your.grafanahost.com/grafana2/api/dashboards/db/',
cookie: 'auth-openid=REPLACETOKENIFAPPLICABLE'
});
// Dashboard Constants
var TITLE = 'TEST API dashboard';
var TAGS = ['myapp', 'platform'];
var TEMPLATING = [{
name: 'dc',
options: ['dc1', 'dc2']
}, {
name: 'smoothing',
options: ['30min', '10min', '5min', '2min', '1min']
}];
var ANNOTATIONS = [{
name: 'Deploy',
target: 'stats.$dc.production.deploy'
}];
var REFRESH = '1m';
// Target prefixes
var SERVER_PREFIX = 'servers.app*-$dc.myapp.';
var COUNT_PREFIX = 'stats.$dc.counts.myapp.';
function generateDashboard() {
// Rows
var volumeRow = new Row({
title: 'Request Volume'
});
var systemRow = new Row({
title: 'System / OS'
});
// Panels: request volume
var rpsGraphPanel = new Panels.Graph({
title: 'req/sec',
span: 8,
targets: [
new Target(COUNT_PREFIX + 'statusCode.*').
transformNull(0).
sum().
hitcount('1seconds').
scale(0.1).
alias('rps')
]
});
var rpsStatPanel = new Panels.SingleStat({
title: 'Current Request Volume',
postfix: 'req/sec',
span: 4,
targets: [
new Target(COUNT_PREFIX + 'statusCode.*').
sum().
scale(0.1)
]
});
// Panels: system health
var cpuGraph = new Panels.Graph({
title: 'CPU',
span: 4,
targets: [
new Target(SERVER_PREFIX + 'cpu.user').
nonNegativeDerivative().
scale(1 / 60).
scale(100).
averageSeries().
alias('avg'),
new Target(SERVER_PREFIX + 'cpu.user').
nonNegativeDerivative().
scale(1 / 60).
scale(100).
percentileOfSeries(95, false).
alias('p95')
]
});
var rssGraph = new Panels.Graph({
title: 'Memory',
span: 4,
targets: [
new Target(SERVER_PREFIX + 'memory.rss').
averageSeries().
alias('rss')
]
});
var fdsGraph = new Panels.Graph({
title: 'FDs',
span: 4,
targets: [
new Target(SERVER_PREFIX + 'fds').
averageSeries().
movingAverage('10min').
alias('moving avg')
]
});
// Dashboard
var dashboard = new Dashboard({
title: TITLE,
tags: TAGS,
templating: TEMPLATING,
annotations: ANNOTATIONS,
refresh: REFRESH
});
// Layout: panels
volumeRow.addPanel(rpsGraphPanel);
volumeRow.addPanel(rpsStatPanel);
systemRow.addPanel(cpuGraph);
systemRow.addPanel(rssGraph);
systemRow.addPanel(fdsGraph);
// Layout: rows
dashboard.addRow(volumeRow);
dashboard.addRow(systemRow);
// Finish
grafana.publish(dashboard);
}
module.exports = {
generate: generateDashboard
};
if (require.main === module) {
generateDashboard();
}