@redkern/node-red-prometheus 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,337 @@
1
+ 'use strict';
2
+
3
+ const { getPalette } = require('../lib/palette.js');
4
+ const { normalizeDefinition } = require('../lib/registry.js');
5
+ const { createWarnOnce, describeError } = require('../lib/warn-once.js');
6
+
7
+ const TYPE_CONFIG = 'redkern-prom-metric-config';
8
+ const TYPE_METRIC = 'redkern-prom-metric';
9
+ const TYPE_EXPORTER = 'redkern-prom-exporter';
10
+ const AUTO_LABELS = Object.freeze(['step', 'status', 'process']);
11
+ const OPERATIONS = Object.freeze(['inc', 'dec', 'set', 'observe', 'startTimer', 'stopTimer']);
12
+ const VALUE_TYPES = Object.freeze(['msg', 'flow', 'global', 'env', 'num', 'str']);
13
+ const PREFIX = /^(?:[a-zA-Z_:][a-zA-Z0-9_:]*)?$/;
14
+
15
+ module.exports = function (RED) {
16
+ const palette = getPalette(RED);
17
+ const { rk } = palette;
18
+
19
+ // ---------------------------------------------------------------------------------------------
20
+ // redkern-prom-metric-config: one Prometheus metric (PRM-MET-1, PRM-REG-3..5, PRM-CARD-1..4)
21
+ // ---------------------------------------------------------------------------------------------
22
+ function MetricConfigNode(config) {
23
+ RED.nodes.createNode(this, config);
24
+ const node = this;
25
+ const k = rk.bind(node);
26
+ k.onClose(palette.acquire());
27
+ node.metricName = String(config.metricName || '').trim();
28
+ node.metricType = config.metricType;
29
+ node.handle = undefined;
30
+ node.durationHandle = undefined;
31
+ node.problem = undefined;
32
+ if (!rk.enabled) {
33
+ node.problem = { code: 'PALETTE_DISABLED', text: 'disabled' };
34
+ return;
35
+ }
36
+
37
+ const parsed = normalizeDefinition({
38
+ type: config.metricType,
39
+ name: node.metricName,
40
+ help: config.help,
41
+ labelNames: splitList(config.labelNames),
42
+ buckets: config.buckets,
43
+ percentiles: config.percentiles,
44
+ maxAgeSeconds: config.maxAgeSeconds,
45
+ ageBuckets: config.ageBuckets,
46
+ maxSeries: parseLimit(config.maxSeriesPerMetric),
47
+ allowlist: parseAllowlist(config.allowlist)
48
+ });
49
+ if (!parsed.ok) {
50
+ node.problem = { code: 'CONFIG_INVALID', text: 'config invalid' };
51
+ for (const error of parsed.errors) k.log.error(error.message, { key: error.code });
52
+ return;
53
+ }
54
+ const definition = parsed.value;
55
+ const ensured = palette.metrics.ensure(node.id, definition);
56
+ if (!ensured.ok) {
57
+ node.problem = { code: ensured.code, text: 'metric conflict' };
58
+ k.log.error(ensured.message, { key: ensured.code });
59
+ return;
60
+ }
61
+ node.handle = ensured.handle;
62
+ k.onClose(() => { palette.metrics.release(node.id, definition.name); });
63
+
64
+ if (definition.type === 'counter' && config.withDuration) {
65
+ const durationName = `${definition.name.replace(/_total$/, '')}_duration_seconds`;
66
+ const duration = normalizeDefinition({
67
+ type: 'histogram',
68
+ name: durationName,
69
+ help: `${definition.help} duration in seconds`,
70
+ labelNames: definition.labelNames,
71
+ buckets: config.durationBuckets,
72
+ maxSeries: definition.maxSeries,
73
+ allowlist: definition.allowlist
74
+ });
75
+ const durationEnsured = duration.ok ? palette.metrics.ensure(node.id, duration.value) : { ok: false, code: 'CONFIG_INVALID', message: duration.errors.map((e) => e.message).join('; ') };
76
+ if (!durationEnsured.ok) {
77
+ k.log.error(durationEnsured.message, { key: durationEnsured.code });
78
+ node.problem = { code: durationEnsured.code, text: 'metric conflict' };
79
+ } else {
80
+ node.durationHandle = durationEnsured.handle;
81
+ k.onClose(() => { palette.metrics.release(node.id, durationName); });
82
+ }
83
+ }
84
+ }
85
+ RED.nodes.registerType(TYPE_CONFIG, MetricConfigNode);
86
+
87
+ // ---------------------------------------------------------------------------------------------
88
+ // redkern-prom-metric: writes a metric and always forwards msg (PRM-MET-2..6)
89
+ // ---------------------------------------------------------------------------------------------
90
+ function MetricNode(config) {
91
+ RED.nodes.createNode(this, config);
92
+ const node = this;
93
+ const k = rk.bind(node);
94
+ k.onClose(palette.acquire());
95
+ const metricConfig = RED.nodes.getNode(config.metric);
96
+ const operation = OPERATIONS.includes(config.operation) ? config.operation : 'inc';
97
+ const autoStep = config.autoStep !== false;
98
+ const timerKey = String(config.timer || config.metric || '');
99
+ const labelRows = Array.isArray(config.labels) ? config.labels.filter((row) => row && typeof row.name === 'string' && row.name.trim()) : [];
100
+ let drops = 0;
101
+
102
+ const warnOnce = createWarnOnce((message, meta) => k.log.warn(message, meta), 256);
103
+
104
+ if (!rk.enabled) {
105
+ // The kit already shows the disabled/invalid palette overlay.
106
+ } else if (!metricConfig) {
107
+ k.status('error', 'no metric config');
108
+ } else if (metricConfig.problem) {
109
+ k.status('error', metricConfig.problem.text);
110
+ } else if (metricConfig.handle) {
111
+ const unsubscribe = [metricConfig.handle, metricConfig.durationHandle].filter(Boolean).map((handle) => handle.onDrop(() => {
112
+ drops += 1;
113
+ k.status('warn', `dropped ${drops}`);
114
+ }));
115
+ k.onClose(() => { for (const off of unsubscribe) off(); });
116
+ }
117
+
118
+ node.on('input', (msg, send, done) => {
119
+ const forward = () => {
120
+ send(msg);
121
+ done();
122
+ };
123
+ let pending;
124
+ try {
125
+ pending = write(msg);
126
+ } catch (error) {
127
+ warnOnce(`WRITE_FAILED:${describeError(error)}`, `Metric write failed: ${describeError(error)}`);
128
+ forward();
129
+ return;
130
+ }
131
+ if (pending && typeof pending.then === 'function') {
132
+ pending.then(forward, (error) => {
133
+ warnOnce(`WRITE_FAILED:${describeError(error)}`, `Metric write failed: ${describeError(error)}`);
134
+ forward();
135
+ });
136
+ } else forward();
137
+ });
138
+
139
+ // Returns undefined when finished synchronously, or a promise when a context store is asynchronous.
140
+ function write(msg) {
141
+ if (!rk.enabled || !metricConfig || !metricConfig.handle) {
142
+ if (rk.enabled) warnOnce('METRIC_UNAVAILABLE', 'Metric configuration is missing or invalid; metric write was skipped');
143
+ return undefined;
144
+ }
145
+ const op = operation;
146
+
147
+ if (op === 'startTimer') {
148
+ const timers = timersOf(msg, true);
149
+ timers[timerKey] = now();
150
+ return undefined;
151
+ }
152
+
153
+ const handle = (op === 'observe' || op === 'stopTimer') && metricConfig.handle.type === 'counter'
154
+ ? metricConfig.durationHandle
155
+ : metricConfig.handle;
156
+ if (!handle) {
157
+ warnOnce(`NO_DURATION:${op}`, `Operation "${op}" on counter "${metricConfig.metricName}" needs "Also track duration"`);
158
+ return undefined;
159
+ }
160
+ const writeOp = op === 'stopTimer' ? 'observe' : op;
161
+ if (!handle.supports(writeOp)) {
162
+ warnOnce(`UNSUPPORTED:${op}`, `Operation "${op}" is not supported by ${handle.type} "${handle.name}"`);
163
+ return undefined;
164
+ }
165
+
166
+ const values = {};
167
+ const tasks = [];
168
+ const evaluate = (key, value, type) => {
169
+ const result = evaluateProperty(RED, node, value, type, msg);
170
+ if (result && typeof result.then === 'function') tasks.push(result.then((resolved) => { values[key] = resolved; }));
171
+ else values[key] = result;
172
+ };
173
+
174
+ const declared = handle.labelNames;
175
+ if (declared.includes('step')) {
176
+ if (autoStep) values['label:step'] = node.name || node.id;
177
+ else evaluate('label:step', config.step, config.stepType || 'str');
178
+ }
179
+ if (declared.includes('status')) evaluate('label:status', config.status === undefined ? 'success' : config.status, config.statusType || 'str');
180
+ if (declared.includes('process')) evaluate('label:process', 'NR_FLOW_NAME', 'env');
181
+ for (const row of labelRows) evaluate(`label:${row.name.trim()}`, row.value, row.valueType || 'str');
182
+
183
+ if (op === 'stopTimer') {
184
+ const timers = timersOf(msg, false);
185
+ const started = timers ? timers[timerKey] : undefined;
186
+ if (typeof started !== 'number') {
187
+ warnOnce('TIMER_MISSING', `stopTimer for "${handle.name}" found no started timer in msg.redkern.prom.timers`);
188
+ return undefined;
189
+ }
190
+ delete timers[timerKey];
191
+ values.value = (now() - started) / 1000;
192
+ } else if (op === 'observe') {
193
+ evaluate('value', config.duration, config.durationType || 'num');
194
+ } else {
195
+ evaluate('value', config.value === undefined || config.value === '' ? '1' : config.value, config.valueType || 'num');
196
+ }
197
+
198
+ const finish = () => {
199
+ let value = Number(values.value);
200
+ if (op === 'observe' && config.durationUnit === 'ms') value /= 1000;
201
+ const labels = {};
202
+ for (const key of Object.keys(values)) {
203
+ if (!key.startsWith('label:')) continue;
204
+ const labelValue = toLabelValue(values[key]);
205
+ if (labelValue !== undefined) labels[key.slice(6)] = labelValue;
206
+ }
207
+ const extra = Object.keys(labels).filter((name) => !declared.includes(name));
208
+ const missing = declared.filter((name) => labels[name] === undefined);
209
+ if (extra.length) warnOnce(`EXTRA:${extra.sort().join(',')}`, `Metric "${handle.name}" ignored labels it does not declare: ${extra.join(', ')}`);
210
+ if (missing.length) {
211
+ warnOnce(`MISSING:${missing.sort().join(',')}`, `Metric "${handle.name}" write skipped: missing labels ${missing.join(', ')}`);
212
+ return;
213
+ }
214
+ const final = Object.fromEntries(declared.map((name) => [name, labels[name]]));
215
+ const result = handle.write(writeOp, final, value);
216
+ // supports() was checked above, so the only failure left is an invalid value.
217
+ if (result === 'invalid') warnOnce(`INVALID_VALUE:${op}`, `Metric "${handle.name}" write skipped: value is not a valid number for ${op}`);
218
+ };
219
+ if (tasks.length === 0) return finish();
220
+ return Promise.all(tasks).then(finish);
221
+ }
222
+ }
223
+ RED.nodes.registerType(TYPE_METRIC, MetricNode);
224
+
225
+ // ---------------------------------------------------------------------------------------------
226
+ // redkern-prom-exporter: /metrics on a dedicated port or on httpAdmin (PRM-EXP-1..5, PRM-DEF-1..3)
227
+ // ---------------------------------------------------------------------------------------------
228
+ function ExporterNode(config) {
229
+ RED.nodes.createNode(this, config);
230
+ const node = this;
231
+ const k = rk.bind(node);
232
+ k.onClose(palette.acquire());
233
+ const mode = config.mode === 'admin' ? 'admin' : 'internal';
234
+ const prefix = config.prefix === undefined ? 'nodered_' : String(config.prefix);
235
+ const options = {
236
+ mode,
237
+ defaultMetrics: config.defaultMetrics !== false,
238
+ prefix,
239
+ hostLabel: config.hostLabel === true,
240
+ includeGlobalRegistry: config.includeGlobalRegistry === true
241
+ };
242
+ if (!rk.enabled) return;
243
+ if (!PREFIX.test(prefix)) {
244
+ k.log.error('Default metrics prefix must be a valid Prometheus name prefix', { key: 'INVALID_PREFIX' });
245
+ k.status('error', 'invalid prefix');
246
+ return;
247
+ }
248
+ if (!palette.claimExporter(node.id, options)) {
249
+ k.log.error('Another redkern-prom-exporter is already active on this Node-RED instance', { key: 'DUPLICATE_EXPORTER' });
250
+ k.status('error', 'duplicate exporter');
251
+ return;
252
+ }
253
+ k.onClose(() => palette.releaseExporter(node.id));
254
+
255
+ if (mode === 'admin') {
256
+ if (!palette.adminRoute.available) {
257
+ k.status('error', 'adminAuth required');
258
+ return;
259
+ }
260
+ palette.adminRoute.add(node.id, node);
261
+ k.onClose(() => { palette.adminRoute.remove(node.id); });
262
+ k.status('ok', 'admin /metrics');
263
+ return;
264
+ }
265
+
266
+ if (!k.internalServer) {
267
+ k.log.error('The dedicated metrics port needs REDKERN_PROM_METRICS_TOKEN (or redkernPromExporterMetricsToken in settings.js); use the admin API mode otherwise', { key: 'TOKEN_REQUIRED' });
268
+ k.status('error', 'token required');
269
+ return;
270
+ }
271
+ // Kit internal server: lazy listener with per-node leases, retry with backoff and status overlays.
272
+ const lease = k.internalServer.acquire(node.id, { node });
273
+ k.track(lease.ready.then(() => k.status('ok', `port ${rk.config.value.internalPort}`)), { label: 'metrics listener' });
274
+ }
275
+ RED.nodes.registerType(TYPE_EXPORTER, ExporterNode);
276
+ };
277
+
278
+ function splitList(value) {
279
+ if (Array.isArray(value)) return value.map(String).map((item) => item.trim()).filter(Boolean);
280
+ return String(value || '').split(',').map((item) => item.trim()).filter(Boolean);
281
+ }
282
+
283
+ function parseLimit(value) {
284
+ if (value === undefined || value === null || value === '') return undefined;
285
+ const number = Number(value);
286
+ return Number.isSafeInteger(number) && number > 0 ? number : undefined;
287
+ }
288
+
289
+ function parseAllowlist(rows) {
290
+ const allowlist = {};
291
+ if (!Array.isArray(rows)) return allowlist;
292
+ for (const row of rows) {
293
+ if (!row || typeof row.label !== 'string' || !row.label.trim()) continue;
294
+ const values = splitList(row.values);
295
+ if (values.length) allowlist[row.label.trim()] = values;
296
+ }
297
+ return allowlist;
298
+ }
299
+
300
+ function timersOf(msg, create) {
301
+ if (!msg.redkern || typeof msg.redkern !== 'object') {
302
+ if (!create) return undefined;
303
+ msg.redkern = {};
304
+ }
305
+ if (!msg.redkern.prom || typeof msg.redkern.prom !== 'object') {
306
+ if (!create) return undefined;
307
+ msg.redkern.prom = {};
308
+ }
309
+ if (!msg.redkern.prom.timers || typeof msg.redkern.prom.timers !== 'object') {
310
+ if (!create) return undefined;
311
+ msg.redkern.prom.timers = {};
312
+ }
313
+ return msg.redkern.prom.timers;
314
+ }
315
+
316
+ function now() {
317
+ return performance.timeOrigin + performance.now();
318
+ }
319
+
320
+ function toLabelValue(value) {
321
+ if (value === undefined || value === null) return undefined;
322
+ if (typeof value === 'string') return value;
323
+ if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') return String(value);
324
+ return undefined;
325
+ }
326
+
327
+ function evaluateProperty(RED, node, value, type, msg) {
328
+ const valueType = VALUE_TYPES.includes(type) ? type : 'str';
329
+ if (valueType === 'flow' || valueType === 'global') {
330
+ return new Promise((resolve, reject) => {
331
+ RED.util.evaluateNodeProperty(value, valueType, node, msg, (error, result) => (error ? reject(error) : resolve(result)));
332
+ });
333
+ }
334
+ return RED.util.evaluateNodeProperty(value, valueType, node, msg);
335
+ }
336
+
337
+ module.exports.internals = { splitList, parseLimit, parseAllowlist, toLabelValue, timersOf, evaluateProperty };
@@ -0,0 +1,349 @@
1
+ {
2
+ "uid": "redkern-prom-overview",
3
+ "title": "redkern | Node-RED Prometheus palette",
4
+ "tags": [
5
+ "redkern",
6
+ "node-red"
7
+ ],
8
+ "schemaVersion": 39,
9
+ "version": 1,
10
+ "editable": true,
11
+ "time": {
12
+ "from": "now-6h",
13
+ "to": "now"
14
+ },
15
+ "refresh": "1m",
16
+ "templating": {
17
+ "list": [
18
+ {
19
+ "name": "datasource",
20
+ "type": "datasource",
21
+ "query": "prometheus",
22
+ "current": {}
23
+ },
24
+ {
25
+ "name": "job",
26
+ "type": "query",
27
+ "datasource": {
28
+ "type": "prometheus",
29
+ "uid": "${datasource}"
30
+ },
31
+ "query": "label_values(nodered_flows_deploy_total, job)",
32
+ "includeAll": true,
33
+ "multi": true,
34
+ "refresh": 2
35
+ },
36
+ {
37
+ "name": "pod",
38
+ "type": "query",
39
+ "datasource": {
40
+ "type": "prometheus",
41
+ "uid": "${datasource}"
42
+ },
43
+ "query": "label_values(nodered_flows_deploy_total{job=~\"$job\"}, pod)",
44
+ "includeAll": true,
45
+ "multi": true,
46
+ "refresh": 2
47
+ }
48
+ ]
49
+ },
50
+ "description": "PRM-MET-8: palette health. Shipped in observability/ of @redkern/node-red-prometheus.",
51
+ "panels": [
52
+ {
53
+ "id": 1,
54
+ "type": "timeseries",
55
+ "title": "Dropped series per second",
56
+ "datasource": {
57
+ "type": "prometheus",
58
+ "uid": "${datasource}"
59
+ },
60
+ "gridPos": {
61
+ "x": 0,
62
+ "y": 0,
63
+ "w": 12,
64
+ "h": 8
65
+ },
66
+ "fieldConfig": {
67
+ "defaults": {
68
+ "unit": "short"
69
+ },
70
+ "overrides": []
71
+ },
72
+ "options": {
73
+ "legend": {
74
+ "displayMode": "list",
75
+ "placement": "bottom"
76
+ },
77
+ "tooltip": {
78
+ "mode": "multi"
79
+ }
80
+ },
81
+ "targets": [
82
+ {
83
+ "refId": "A",
84
+ "expr": "sum by (metric) (rate(redkern_prom_dropped_series_total{job=~\"$job\", pod=~\"$pod\"}[$__rate_interval]))",
85
+ "legendFormat": "{{metric}}"
86
+ }
87
+ ]
88
+ },
89
+ {
90
+ "id": 2,
91
+ "type": "timeseries",
92
+ "title": "Deploys",
93
+ "datasource": {
94
+ "type": "prometheus",
95
+ "uid": "${datasource}"
96
+ },
97
+ "gridPos": {
98
+ "x": 12,
99
+ "y": 0,
100
+ "w": 12,
101
+ "h": 8
102
+ },
103
+ "fieldConfig": {
104
+ "defaults": {
105
+ "unit": "short"
106
+ },
107
+ "overrides": []
108
+ },
109
+ "options": {
110
+ "legend": {
111
+ "displayMode": "list",
112
+ "placement": "bottom"
113
+ },
114
+ "tooltip": {
115
+ "mode": "multi"
116
+ }
117
+ },
118
+ "targets": [
119
+ {
120
+ "refId": "A",
121
+ "expr": "sum by (pod) (increase(nodered_flows_deploy_total{job=~\"$job\", pod=~\"$pod\"}[$__range]))",
122
+ "legendFormat": "{{pod}}"
123
+ }
124
+ ]
125
+ },
126
+ {
127
+ "id": 3,
128
+ "type": "timeseries",
129
+ "title": "Event loop lag p99",
130
+ "datasource": {
131
+ "type": "prometheus",
132
+ "uid": "${datasource}"
133
+ },
134
+ "gridPos": {
135
+ "x": 0,
136
+ "y": 8,
137
+ "w": 12,
138
+ "h": 8
139
+ },
140
+ "fieldConfig": {
141
+ "defaults": {
142
+ "unit": "s"
143
+ },
144
+ "overrides": []
145
+ },
146
+ "options": {
147
+ "legend": {
148
+ "displayMode": "list",
149
+ "placement": "bottom"
150
+ },
151
+ "tooltip": {
152
+ "mode": "multi"
153
+ }
154
+ },
155
+ "targets": [
156
+ {
157
+ "refId": "A",
158
+ "expr": "max by (pod) (nodered_nodejs_eventloop_lag_p99_seconds{job=~\"$job\", pod=~\"$pod\"})",
159
+ "legendFormat": "{{pod}}"
160
+ }
161
+ ]
162
+ },
163
+ {
164
+ "id": 4,
165
+ "type": "timeseries",
166
+ "title": "Heap used",
167
+ "datasource": {
168
+ "type": "prometheus",
169
+ "uid": "${datasource}"
170
+ },
171
+ "gridPos": {
172
+ "x": 12,
173
+ "y": 8,
174
+ "w": 12,
175
+ "h": 8
176
+ },
177
+ "fieldConfig": {
178
+ "defaults": {
179
+ "unit": "bytes"
180
+ },
181
+ "overrides": []
182
+ },
183
+ "options": {
184
+ "legend": {
185
+ "displayMode": "list",
186
+ "placement": "bottom"
187
+ },
188
+ "tooltip": {
189
+ "mode": "multi"
190
+ }
191
+ },
192
+ "targets": [
193
+ {
194
+ "refId": "A",
195
+ "expr": "sum by (pod) (nodered_nodejs_heap_size_used_bytes{job=~\"$job\", pod=~\"$pod\"})",
196
+ "legendFormat": "{{pod}}"
197
+ }
198
+ ]
199
+ },
200
+ {
201
+ "id": 5,
202
+ "type": "timeseries",
203
+ "title": "CPU",
204
+ "datasource": {
205
+ "type": "prometheus",
206
+ "uid": "${datasource}"
207
+ },
208
+ "gridPos": {
209
+ "x": 0,
210
+ "y": 16,
211
+ "w": 12,
212
+ "h": 8
213
+ },
214
+ "fieldConfig": {
215
+ "defaults": {
216
+ "unit": "percentunit"
217
+ },
218
+ "overrides": []
219
+ },
220
+ "options": {
221
+ "legend": {
222
+ "displayMode": "list",
223
+ "placement": "bottom"
224
+ },
225
+ "tooltip": {
226
+ "mode": "multi"
227
+ }
228
+ },
229
+ "targets": [
230
+ {
231
+ "refId": "A",
232
+ "expr": "sum by (pod) (rate(nodered_process_cpu_seconds_total{job=~\"$job\", pod=~\"$pod\"}[$__rate_interval]))",
233
+ "legendFormat": "{{pod}}"
234
+ }
235
+ ]
236
+ },
237
+ {
238
+ "id": 6,
239
+ "type": "timeseries",
240
+ "title": "GC duration per second",
241
+ "datasource": {
242
+ "type": "prometheus",
243
+ "uid": "${datasource}"
244
+ },
245
+ "gridPos": {
246
+ "x": 12,
247
+ "y": 16,
248
+ "w": 12,
249
+ "h": 8
250
+ },
251
+ "fieldConfig": {
252
+ "defaults": {
253
+ "unit": "s"
254
+ },
255
+ "overrides": []
256
+ },
257
+ "options": {
258
+ "legend": {
259
+ "displayMode": "list",
260
+ "placement": "bottom"
261
+ },
262
+ "tooltip": {
263
+ "mode": "multi"
264
+ }
265
+ },
266
+ "targets": [
267
+ {
268
+ "refId": "A",
269
+ "expr": "sum by (pod, kind) (rate(nodered_nodejs_gc_duration_seconds_sum{job=~\"$job\", pod=~\"$pod\"}[$__rate_interval]))",
270
+ "legendFormat": "{{pod}} {{kind}}"
271
+ }
272
+ ]
273
+ },
274
+ {
275
+ "id": 7,
276
+ "type": "timeseries",
277
+ "title": "Scrape up",
278
+ "datasource": {
279
+ "type": "prometheus",
280
+ "uid": "${datasource}"
281
+ },
282
+ "gridPos": {
283
+ "x": 0,
284
+ "y": 24,
285
+ "w": 12,
286
+ "h": 8
287
+ },
288
+ "fieldConfig": {
289
+ "defaults": {
290
+ "unit": "short"
291
+ },
292
+ "overrides": []
293
+ },
294
+ "options": {
295
+ "legend": {
296
+ "displayMode": "list",
297
+ "placement": "bottom"
298
+ },
299
+ "tooltip": {
300
+ "mode": "multi"
301
+ }
302
+ },
303
+ "targets": [
304
+ {
305
+ "refId": "A",
306
+ "expr": "up{job=~\"$job\", pod=~\"$pod\"}",
307
+ "legendFormat": "{{pod}}"
308
+ }
309
+ ]
310
+ },
311
+ {
312
+ "id": 8,
313
+ "type": "timeseries",
314
+ "title": "Scrape duration",
315
+ "datasource": {
316
+ "type": "prometheus",
317
+ "uid": "${datasource}"
318
+ },
319
+ "gridPos": {
320
+ "x": 12,
321
+ "y": 24,
322
+ "w": 12,
323
+ "h": 8
324
+ },
325
+ "fieldConfig": {
326
+ "defaults": {
327
+ "unit": "s"
328
+ },
329
+ "overrides": []
330
+ },
331
+ "options": {
332
+ "legend": {
333
+ "displayMode": "list",
334
+ "placement": "bottom"
335
+ },
336
+ "tooltip": {
337
+ "mode": "multi"
338
+ }
339
+ },
340
+ "targets": [
341
+ {
342
+ "refId": "A",
343
+ "expr": "scrape_duration_seconds{job=~\"$job\", pod=~\"$pod\"}",
344
+ "legendFormat": "{{pod}}"
345
+ }
346
+ ]
347
+ }
348
+ ]
349
+ }