@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,415 @@
1
+ <script type="text/javascript">
2
+ (function () {
3
+ "use strict";
4
+
5
+ // PRM-UI-1: kit editor standard (orange, semicircle gauge icons, labels from the message catalog). PRM-NR-1.
6
+ var CATEGORY = "redkern prom";
7
+ var COLOR = "#FDD0A2";
8
+ var NS = "redkern-prom.";
9
+ var VALUE_TYPES = ["num", "str", "msg", "flow", "global", "env"];
10
+ var METRIC_NAME = /^[a-zA-Z_:][a-zA-Z0-9_:]*$/;
11
+ var LABEL_NAME = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
12
+
13
+ function list(value) {
14
+ return String(value || "").split(",").map(function (item) { return item.trim(); }).filter(Boolean);
15
+ }
16
+
17
+ function numbers(value, check) {
18
+ var items = list(value);
19
+ if (!items.length) { return true; }
20
+ var parsed = items.map(Number);
21
+ for (var i = 0; i < parsed.length; i++) {
22
+ if (!isFinite(parsed[i])) { return false; }
23
+ if (check && !check(parsed[i], i, parsed)) { return false; }
24
+ }
25
+ return true;
26
+ }
27
+
28
+ RED.nodes.registerType("redkern-prom-metric-config", {
29
+ category: "config",
30
+ defaults: {
31
+ name: { value: "" },
32
+ metricType: { value: "counter", required: true },
33
+ metricName: {
34
+ value: "",
35
+ required: true,
36
+ validate: function (v) { return METRIC_NAME.test(v) && v.indexOf("redkern_prom_") !== 0; }
37
+ },
38
+ help: { value: "" },
39
+ labelNames: {
40
+ value: "",
41
+ validate: function (v) {
42
+ var names = list(v);
43
+ return names.every(function (n, i) {
44
+ return LABEL_NAME.test(n) && n.indexOf("__") !== 0 && n !== "le" && n !== "quantile" && names.indexOf(n) === i;
45
+ });
46
+ }
47
+ },
48
+ buckets: {
49
+ value: "",
50
+ validate: function (v) { return numbers(v, function (n, i, all) { return i === 0 || n > all[i - 1]; }); }
51
+ },
52
+ withDuration: { value: false },
53
+ durationBuckets: {
54
+ value: "",
55
+ validate: function (v) { return numbers(v, function (n, i, all) { return i === 0 || n > all[i - 1]; }); }
56
+ },
57
+ percentiles: {
58
+ value: "",
59
+ validate: function (v) { return numbers(v, function (n) { return n > 0 && n < 1; }); }
60
+ },
61
+ maxAgeSeconds: { value: "", validate: RED.validators.number(true) },
62
+ ageBuckets: { value: "", validate: RED.validators.number(true) },
63
+ maxSeriesPerMetric: {
64
+ value: 1000,
65
+ required: true,
66
+ validate: function (v) { var n = Number(v); return Math.floor(n) === n && n >= 1; }
67
+ },
68
+ allowlist: { value: [] }
69
+ },
70
+ paletteLabel: function () { return this._(NS + "label.metricConfig"); },
71
+ label: function () {
72
+ if (this.name) { return this.name; }
73
+ if (this.metricName) { return this.metricName + " (" + this.metricType + ")"; }
74
+ return this._(NS + "label.metricConfig");
75
+ },
76
+ oneditprepare: function () {
77
+ var node = this;
78
+ function refresh() {
79
+ var kind = $("#node-config-input-metricType").val();
80
+ $(".redkern-prom-histogram").toggle(kind === "histogram");
81
+ $(".redkern-prom-summary").toggle(kind === "summary");
82
+ $(".redkern-prom-counter").toggle(kind === "counter");
83
+ $(".redkern-prom-duration").toggle(kind === "counter" && $("#node-config-input-withDuration").prop("checked"));
84
+ }
85
+ $("#node-config-input-metricType, #node-config-input-withDuration").on("change", refresh);
86
+ $("#node-config-input-maxSeriesPerMetric").spinner({ min: 1 });
87
+
88
+ var allow = $("#node-config-input-allowlist-container").css("min-height", "120px").editableList({
89
+ addButton: node._(NS + "button.addAllowlist"),
90
+ addItem: function (container, i, row) {
91
+ row = row || {};
92
+ container.css({ display: "flex", gap: "6px" });
93
+ $("<input/>", { type: "text", class: "redkern-prom-allow-label", placeholder: node._(NS + "placeholder.label") })
94
+ .css("width", "30%").val(row.label || "").appendTo(container);
95
+ $("<input/>", { type: "text", class: "redkern-prom-allow-values", placeholder: node._(NS + "placeholder.values") })
96
+ .css("width", "65%").val(Array.isArray(row.values) ? row.values.join(", ") : (row.values || "")).appendTo(container);
97
+ },
98
+ removable: true,
99
+ sortable: false
100
+ });
101
+ (this.allowlist || []).forEach(function (row) { allow.editableList("addItem", row); });
102
+ refresh();
103
+ },
104
+ oneditsave: function () {
105
+ var rows = [];
106
+ $("#node-config-input-allowlist-container").editableList("items").each(function () {
107
+ var label = $(this).find(".redkern-prom-allow-label").val().trim();
108
+ var values = list($(this).find(".redkern-prom-allow-values").val());
109
+ if (label && values.length) { rows.push({ label: label, values: values }); }
110
+ });
111
+ this.allowlist = rows;
112
+ }
113
+ });
114
+
115
+ RED.nodes.registerType("redkern-prom-metric", {
116
+ category: CATEGORY,
117
+ color: COLOR,
118
+ icon: "redkern-prom-metric.svg",
119
+ inputs: 1,
120
+ outputs: 1,
121
+ defaults: {
122
+ name: { value: "" },
123
+ metric: { value: "", type: "redkern-prom-metric-config", required: true },
124
+ operation: { value: "inc" },
125
+ autoStep: { value: true },
126
+ step: { value: "" },
127
+ stepType: { value: "str" },
128
+ status: { value: "success" },
129
+ statusType: { value: "str" },
130
+ value: {
131
+ value: "1",
132
+ validate: function (v, opt) {
133
+ var op = this.operation || "inc";
134
+ return (op !== "inc" && op !== "dec" && op !== "set") || RED.validators.typedInput("valueType").call(this, v, opt);
135
+ }
136
+ },
137
+ valueType: { value: "num" },
138
+ duration: {
139
+ value: "",
140
+ validate: function (v, opt) {
141
+ return this.operation !== "observe" || RED.validators.typedInput("durationType").call(this, v, opt);
142
+ }
143
+ },
144
+ durationType: { value: "msg" },
145
+ durationUnit: { value: "seconds" },
146
+ timer: { value: "" },
147
+ labels: { value: [] }
148
+ },
149
+ paletteLabel: function () { return this._(NS + "paletteLabel.metric"); },
150
+ label: function () {
151
+ if (this.name) { return this.name; }
152
+ var config = RED.nodes.node(this.metric);
153
+ var metricName = config && config.metricName;
154
+ return metricName ? this.operation + " " + metricName : this._(NS + "label.metric");
155
+ },
156
+ labelStyle: function () { return this.name ? "node_label_italic" : ""; },
157
+ inputLabels: function () { return this._(NS + "inputLabel"); },
158
+ outputLabels: function () { return this._(NS + "outputLabel"); },
159
+ oneditprepare: function () {
160
+ var node = this;
161
+ $("#node-input-step").typedInput({ default: "str", types: ["str", "msg", "flow", "global", "env"], typeField: "#node-input-stepType" });
162
+ $("#node-input-status").typedInput({ default: "str", types: ["str", "msg", "flow", "global", "env"], typeField: "#node-input-statusType" });
163
+ $("#node-input-value").typedInput({ default: "num", types: VALUE_TYPES, typeField: "#node-input-valueType" });
164
+ $("#node-input-duration").typedInput({ default: "msg", types: VALUE_TYPES, typeField: "#node-input-durationType" });
165
+
166
+ function refresh() {
167
+ var op = $("#node-input-operation").val();
168
+ $(".redkern-prom-value").toggle(op === "inc" || op === "dec" || op === "set");
169
+ $(".redkern-prom-observe").toggle(op === "observe");
170
+ $(".redkern-prom-timer").toggle(op === "startTimer" || op === "stopTimer");
171
+ $(".redkern-prom-step").toggle(!$("#node-input-autoStep").prop("checked"));
172
+ }
173
+ $("#node-input-operation, #node-input-autoStep").on("change", refresh);
174
+
175
+ var labels = $("#node-input-label-list").css("min-height", "120px").editableList({
176
+ addItem: function (container, i, row) {
177
+ row = row || {};
178
+ container.css({ display: "flex", gap: "6px", "align-items": "center" });
179
+ $("<input/>", { type: "text", class: "redkern-prom-label-name", placeholder: node._(NS + "placeholder.label") })
180
+ .css("width", "30%").val(row.name || "").appendTo(container);
181
+ var value = $("<input/>", { type: "text", class: "redkern-prom-label-value" }).css("width", "65%").appendTo(container);
182
+ value.typedInput({ default: "str", types: ["str", "msg", "flow", "global", "env"] });
183
+ value.typedInput("value", row.value || "");
184
+ value.typedInput("type", row.valueType || "str");
185
+ },
186
+ removable: true,
187
+ sortable: true
188
+ });
189
+ (this.labels || []).forEach(function (row) { labels.editableList("addItem", row); });
190
+
191
+ function addDeclaredLabels() {
192
+ var config = RED.nodes.node($("#node-input-metric").val());
193
+ if (!config) { return; }
194
+ var existing = {};
195
+ labels.editableList("items").each(function () {
196
+ existing[$(this).find(".redkern-prom-label-name").val().trim()] = true;
197
+ });
198
+ list(config.labelNames).forEach(function (name) {
199
+ if (name !== "step" && name !== "status" && name !== "process" && !existing[name]) {
200
+ labels.editableList("addItem", { name: name, value: "", valueType: "str" });
201
+ }
202
+ });
203
+ }
204
+ $("#node-input-metric").on("change", addDeclaredLabels);
205
+ refresh();
206
+ },
207
+ oneditsave: function () {
208
+ var rows = [];
209
+ $("#node-input-label-list").editableList("items").each(function () {
210
+ var name = $(this).find(".redkern-prom-label-name").val().trim();
211
+ var value = $(this).find(".redkern-prom-label-value");
212
+ if (name) { rows.push({ name: name, value: value.typedInput("value"), valueType: value.typedInput("type") }); }
213
+ });
214
+ this.labels = rows;
215
+ }
216
+ });
217
+
218
+ RED.nodes.registerType("redkern-prom-exporter", {
219
+ category: CATEGORY,
220
+ color: COLOR,
221
+ icon: "redkern-prom-exporter.svg",
222
+ inputs: 0,
223
+ outputs: 0,
224
+ defaults: {
225
+ name: { value: "" },
226
+ mode: { value: "internal" },
227
+ includeGlobalRegistry: { value: false },
228
+ defaultMetrics: { value: true },
229
+ prefix: { value: "nodered_", validate: function (v) { return v === "" || METRIC_NAME.test(v); } },
230
+ hostLabel: { value: false }
231
+ },
232
+ paletteLabel: function () { return this._(NS + "paletteLabel.exporter"); },
233
+ label: function () {
234
+ if (this.name) { return this.name; }
235
+ return this.mode === "admin" ? this._(NS + "label.exporterAdmin") : this._(NS + "label.exporterPort", { port: 9550 });
236
+ },
237
+ labelStyle: function () { return this.name ? "node_label_italic" : ""; },
238
+ oneditprepare: function () {
239
+ function refresh() {
240
+ var internal = $("#node-input-mode").val() === "internal";
241
+ $(".redkern-prom-internal").toggle(internal);
242
+ $(".redkern-prom-admin").toggle(!internal);
243
+ $(".redkern-prom-defaults").toggle($("#node-input-defaultMetrics").prop("checked"));
244
+ }
245
+ $("#node-input-mode, #node-input-defaultMetrics").on("change", refresh);
246
+ refresh();
247
+ }
248
+ });
249
+ })();
250
+ </script>
251
+
252
+ <script type="text/html" data-template-name="redkern-prom-metric-config">
253
+ <div class="form-row">
254
+ <label for="node-config-input-name"><i class="fa fa-tag"></i> <span data-i18n="redkern-prom.field.name"></span></label>
255
+ <input type="text" id="node-config-input-name">
256
+ </div>
257
+ <h4 data-i18n="redkern-prom.section.definition"></h4>
258
+ <div class="form-row">
259
+ <label for="node-config-input-metricType"><i class="fa fa-sliders"></i> <span data-i18n="redkern-prom.field.metricType"></span></label>
260
+ <select id="node-config-input-metricType">
261
+ <option value="counter" data-i18n="redkern-prom.type.counter"></option>
262
+ <option value="gauge" data-i18n="redkern-prom.type.gauge"></option>
263
+ <option value="histogram" data-i18n="redkern-prom.type.histogram"></option>
264
+ <option value="summary" data-i18n="redkern-prom.type.summary"></option>
265
+ </select>
266
+ </div>
267
+ <div class="form-row">
268
+ <label for="node-config-input-metricName"><i class="fa fa-line-chart"></i> <span data-i18n="redkern-prom.field.metricName"></span></label>
269
+ <input type="text" id="node-config-input-metricName" data-i18n="[placeholder]redkern-prom.placeholder.metricName">
270
+ </div>
271
+ <div class="form-tips" data-i18n="redkern-prom.hint.metricName"></div>
272
+ <div class="form-row">
273
+ <label for="node-config-input-help"><span data-i18n="redkern-prom.field.help"></span></label>
274
+ <input type="text" id="node-config-input-help">
275
+ </div>
276
+ <div class="form-row">
277
+ <label for="node-config-input-labelNames"><i class="fa fa-tags"></i> <span data-i18n="redkern-prom.field.labelNames"></span></label>
278
+ <input type="text" id="node-config-input-labelNames" data-i18n="[placeholder]redkern-prom.placeholder.labelNames">
279
+ </div>
280
+ <div class="form-tips" data-i18n="redkern-prom.hint.labelNames"></div>
281
+ <div class="form-row redkern-prom-histogram">
282
+ <label for="node-config-input-buckets"><span data-i18n="redkern-prom.field.buckets"></span></label>
283
+ <input type="text" id="node-config-input-buckets" data-i18n="[placeholder]redkern-prom.placeholder.buckets">
284
+ </div>
285
+ <div class="form-row redkern-prom-counter">
286
+ <label for="node-config-input-withDuration">&nbsp;</label>
287
+ <input type="checkbox" id="node-config-input-withDuration" style="display:inline-block; width:auto; vertical-align:top;">
288
+ <label for="node-config-input-withDuration" style="width:auto" data-i18n="redkern-prom.field.withDuration"></label>
289
+ </div>
290
+ <div class="form-row redkern-prom-duration">
291
+ <label for="node-config-input-durationBuckets"><span data-i18n="redkern-prom.field.durationBuckets"></span></label>
292
+ <input type="text" id="node-config-input-durationBuckets" data-i18n="[placeholder]redkern-prom.placeholder.buckets">
293
+ </div>
294
+ <div class="form-row redkern-prom-summary">
295
+ <label for="node-config-input-percentiles"><span data-i18n="redkern-prom.field.percentiles"></span></label>
296
+ <input type="text" id="node-config-input-percentiles" data-i18n="[placeholder]redkern-prom.placeholder.percentiles">
297
+ </div>
298
+ <div class="form-row redkern-prom-summary">
299
+ <label for="node-config-input-maxAgeSeconds"><span data-i18n="redkern-prom.field.maxAgeSeconds"></span></label>
300
+ <input type="text" id="node-config-input-maxAgeSeconds" style="width:80px">
301
+ <label for="node-config-input-ageBuckets" style="margin-left:10px; width:auto" data-i18n="redkern-prom.field.ageBuckets"></label>
302
+ <input type="text" id="node-config-input-ageBuckets" style="width:60px">
303
+ </div>
304
+ <h4 data-i18n="redkern-prom.section.cardinality"></h4>
305
+ <div class="form-row">
306
+ <label for="node-config-input-maxSeriesPerMetric"><span data-i18n="redkern-prom.field.maxSeriesPerMetric"></span></label>
307
+ <input type="text" id="node-config-input-maxSeriesPerMetric" style="width:100px">
308
+ </div>
309
+ <div class="form-tips" data-i18n="redkern-prom.hint.maxSeries"></div>
310
+ <div class="form-row node-config-input-allowlist-container-row">
311
+ <label><span data-i18n="redkern-prom.field.allowlist"></span></label>
312
+ <ol id="node-config-input-allowlist-container"></ol>
313
+ </div>
314
+ <div class="form-tips" data-i18n="redkern-prom.hint.allowlist"></div>
315
+ </script>
316
+
317
+ <script type="text/html" data-template-name="redkern-prom-metric">
318
+ <div class="form-row">
319
+ <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="redkern-prom.field.name"></span></label>
320
+ <input type="text" id="node-input-name">
321
+ </div>
322
+ <div class="form-row">
323
+ <label for="node-input-metric"><i class="fa fa-line-chart"></i> <span data-i18n="redkern-prom.field.metric"></span></label>
324
+ <input type="text" id="node-input-metric">
325
+ </div>
326
+ <div class="form-row">
327
+ <label for="node-input-operation"><i class="fa fa-bolt"></i> <span data-i18n="redkern-prom.field.operation"></span></label>
328
+ <select id="node-input-operation">
329
+ <option value="inc" data-i18n="redkern-prom.operation.inc"></option>
330
+ <option value="dec" data-i18n="redkern-prom.operation.dec"></option>
331
+ <option value="set" data-i18n="redkern-prom.operation.set"></option>
332
+ <option value="observe" data-i18n="redkern-prom.operation.observe"></option>
333
+ <option value="startTimer" data-i18n="redkern-prom.operation.startTimer"></option>
334
+ <option value="stopTimer" data-i18n="redkern-prom.operation.stopTimer"></option>
335
+ </select>
336
+ </div>
337
+ <div class="form-row redkern-prom-value">
338
+ <label for="node-input-value"><span data-i18n="redkern-prom.field.value"></span></label>
339
+ <input type="text" id="node-input-value">
340
+ <input type="hidden" id="node-input-valueType">
341
+ </div>
342
+ <div class="form-row redkern-prom-observe">
343
+ <label for="node-input-duration"><span data-i18n="redkern-prom.field.duration"></span></label>
344
+ <input type="text" id="node-input-duration" style="width:calc(70% - 90px)">
345
+ <input type="hidden" id="node-input-durationType">
346
+ <select id="node-input-durationUnit" style="width:80px">
347
+ <option value="seconds" data-i18n="redkern-prom.unit.seconds"></option>
348
+ <option value="ms" data-i18n="redkern-prom.unit.ms"></option>
349
+ </select>
350
+ </div>
351
+ <div class="form-row redkern-prom-timer">
352
+ <label for="node-input-timer"><i class="fa fa-clock-o"></i> <span data-i18n="redkern-prom.field.timer"></span></label>
353
+ <input type="text" id="node-input-timer" data-i18n="[placeholder]redkern-prom.placeholder.timer">
354
+ </div>
355
+ <h4 data-i18n="redkern-prom.section.labels"></h4>
356
+ <div class="form-row">
357
+ <label for="node-input-autoStep">&nbsp;</label>
358
+ <input type="checkbox" id="node-input-autoStep" style="display:inline-block; width:auto; vertical-align:top;">
359
+ <label for="node-input-autoStep" style="width:auto" data-i18n="redkern-prom.field.autoStep"></label>
360
+ </div>
361
+ <div class="form-row redkern-prom-step">
362
+ <label for="node-input-step"><span data-i18n="redkern-prom.field.step"></span></label>
363
+ <input type="text" id="node-input-step">
364
+ <input type="hidden" id="node-input-stepType">
365
+ </div>
366
+ <div class="form-row">
367
+ <label for="node-input-status"><span data-i18n="redkern-prom.field.status"></span></label>
368
+ <input type="text" id="node-input-status">
369
+ <input type="hidden" id="node-input-statusType">
370
+ </div>
371
+ <div class="form-row node-input-label-list-row">
372
+ <label><i class="fa fa-tags"></i> <span data-i18n="redkern-prom.field.labels"></span></label>
373
+ <ol id="node-input-label-list"></ol>
374
+ </div>
375
+ <div class="form-tips" data-i18n="redkern-prom.hint.cardinality"></div>
376
+ </script>
377
+
378
+ <script type="text/html" data-template-name="redkern-prom-exporter">
379
+ <div class="form-row">
380
+ <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="redkern-prom.field.name"></span></label>
381
+ <input type="text" id="node-input-name">
382
+ </div>
383
+ <h4 data-i18n="redkern-prom.section.endpoint"></h4>
384
+ <div class="form-row">
385
+ <label for="node-input-mode"><i class="fa fa-share-alt"></i> <span data-i18n="redkern-prom.field.mode"></span></label>
386
+ <select id="node-input-mode">
387
+ <option value="internal" data-i18n="redkern-prom.mode.internal"></option>
388
+ <option value="admin" data-i18n="redkern-prom.mode.admin"></option>
389
+ </select>
390
+ </div>
391
+ <div class="form-tips redkern-prom-internal" data-i18n="redkern-prom.hint.port"></div>
392
+ <div class="form-tips redkern-prom-admin" data-i18n="redkern-prom.hint.admin"></div>
393
+ <div class="form-tips redkern-prom-internal" data-i18n="redkern-prom.hint.token"></div>
394
+ <div class="form-row">
395
+ <label for="node-input-includeGlobalRegistry">&nbsp;</label>
396
+ <input type="checkbox" id="node-input-includeGlobalRegistry" style="display:inline-block; width:auto; vertical-align:top;">
397
+ <label for="node-input-includeGlobalRegistry" style="width:auto" data-i18n="redkern-prom.field.includeGlobalRegistry"></label>
398
+ </div>
399
+ <h4 data-i18n="redkern-prom.section.defaults"></h4>
400
+ <div class="form-row">
401
+ <label for="node-input-defaultMetrics">&nbsp;</label>
402
+ <input type="checkbox" id="node-input-defaultMetrics" style="display:inline-block; width:auto; vertical-align:top;">
403
+ <label for="node-input-defaultMetrics" style="width:auto" data-i18n="redkern-prom.field.defaultMetrics"></label>
404
+ </div>
405
+ <div class="form-row redkern-prom-defaults">
406
+ <label for="node-input-prefix"><span data-i18n="redkern-prom.field.prefix"></span></label>
407
+ <input type="text" id="node-input-prefix">
408
+ </div>
409
+ <div class="form-row redkern-prom-defaults">
410
+ <label for="node-input-hostLabel">&nbsp;</label>
411
+ <input type="checkbox" id="node-input-hostLabel" style="display:inline-block; width:auto; vertical-align:top;">
412
+ <label for="node-input-hostLabel" style="width:auto" data-i18n="redkern-prom.field.hostLabel"></label>
413
+ </div>
414
+ <div class="form-tips redkern-prom-defaults" data-i18n="redkern-prom.hint.hostLabel"></div>
415
+ </script>