@redkern/node-red-prometheus 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +25 -0
- package/LICENSE +188 -0
- package/README.md +177 -2
- package/SECURITY.md +18 -0
- package/examples/basic-metrics.json +131 -0
- package/examples/section-timer.json +138 -0
- package/lib/cardinality.js +71 -0
- package/lib/default-metrics.js +51 -0
- package/lib/palette.js +154 -0
- package/lib/receiver.js +169 -0
- package/lib/registry.js +241 -0
- package/lib/warn-once.js +20 -0
- package/nodes/icons/redkern-prom-exporter.svg +9 -0
- package/nodes/icons/redkern-prom-metric.svg +9 -0
- package/nodes/locales/en-US/prometheus.html +75 -0
- package/nodes/locales/en-US/prometheus.json +98 -0
- package/nodes/prometheus.html +415 -0
- package/nodes/prometheus.js +337 -0
- package/observability/grafana-dashboard.json +349 -0
- package/observability/prometheus-rule.yaml +42 -0
- package/package.json +74 -4
package/lib/warn-once.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Logs each key once, with a bounded memory: the set is cleared when it grows past `limit`, so a flow that
|
|
4
|
+
// produces unbounded distinct keys repeats a warning instead of leaking memory.
|
|
5
|
+
function createWarnOnce(warn, limit) {
|
|
6
|
+
const warned = new Set();
|
|
7
|
+
return (key, message) => {
|
|
8
|
+
if (warned.has(key)) return false;
|
|
9
|
+
if (warned.size >= limit) warned.clear();
|
|
10
|
+
warned.add(key);
|
|
11
|
+
warn(message, { key });
|
|
12
|
+
return true;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function describeError(error) {
|
|
17
|
+
return error instanceof Error ? error.message : String(error);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = { createWarnOnce, describeError };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="60" viewBox="0 0 40 60">
|
|
2
|
+
<title>Prometheus exporter</title>
|
|
3
|
+
<g fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="2.8">
|
|
4
|
+
<path d="M6 34a14 14 0 0 1 28 0"/>
|
|
5
|
+
<path d="M20 34l6-8"/>
|
|
6
|
+
<path d="M20 52V42m-5 5 5-5 5 5"/>
|
|
7
|
+
</g>
|
|
8
|
+
<circle cx="20" cy="34" r="2.2" fill="#fff"/>
|
|
9
|
+
</svg>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="60" viewBox="0 0 40 60">
|
|
2
|
+
<title>Prometheus metric</title>
|
|
3
|
+
<g fill="none" stroke="#fff" stroke-linecap="round" stroke-linejoin="round" stroke-width="2.8">
|
|
4
|
+
<path d="M6 34a14 14 0 0 1 28 0"/>
|
|
5
|
+
<path d="M20 34l6-8"/>
|
|
6
|
+
<path d="M20 42v10m-5-5h10"/>
|
|
7
|
+
</g>
|
|
8
|
+
<circle cx="20" cy="34" r="2.2" fill="#fff"/>
|
|
9
|
+
</svg>
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<script type="text/html" data-help-name="redkern-prom-metric-config">
|
|
2
|
+
<p>Defines one Prometheus metric: counter, gauge, histogram or summary, with its labels and cardinality limit.</p>
|
|
3
|
+
<h3>Details</h3>
|
|
4
|
+
<p>Metrics live in the palette's own registry, not in the prom-client global registry, so other palettes cannot clash with them.</p>
|
|
5
|
+
<p>Several config nodes with the same <b>Prometheus name</b> share one metric when their type, labels and buckets match.
|
|
6
|
+
A config node with the same name but a different contract shows a red status on the metric nodes that use it.</p>
|
|
7
|
+
<p>A redeploy without changes keeps the metric's series and counters. Changing the type, labels, buckets or percentiles
|
|
8
|
+
recreates the metric, with a warning in the log, and its series start from zero.</p>
|
|
9
|
+
<p><b>Also track duration</b> (counter only) adds a companion histogram <code><name without _total>_duration_seconds</code>
|
|
10
|
+
with the same labels; <i>observe</i> and <i>stop timer</i> on the counter write to it.</p>
|
|
11
|
+
<h3>Cardinality</h3>
|
|
12
|
+
<p><b>Max series</b> (default 1000) limits label combinations per metric. Existing series keep updating; new combinations
|
|
13
|
+
above the limit are dropped, counted in <code>redkern_prom_dropped_series_total{metric}</code>, and the metric nodes turn yellow.</p>
|
|
14
|
+
<p><b>Allowed values</b> lists the accepted values of a label. Any other value is written as <code>other</code>.</p>
|
|
15
|
+
<p>Never use IDs, UUIDs, timestamps or free text as label values.</p>
|
|
16
|
+
<h3>References</h3>
|
|
17
|
+
<ul>
|
|
18
|
+
<li><a href="https://prometheus.io/docs/practices/naming/">Prometheus naming practices</a></li>
|
|
19
|
+
<li><a href="https://github.com/redkern/node-red-prometheus">README</a></li>
|
|
20
|
+
</ul>
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<script type="text/html" data-help-name="redkern-prom-metric">
|
|
24
|
+
<p>Writes a Prometheus metric for each message and forwards the message unchanged.</p>
|
|
25
|
+
<h3>Inputs</h3>
|
|
26
|
+
<dl class="message-properties">
|
|
27
|
+
<dt>any message</dt>
|
|
28
|
+
<dd>Each message triggers one metric write. Values and labels are read from the message, context or environment
|
|
29
|
+
as configured.</dd>
|
|
30
|
+
<dt class="optional">redkern.prom.timers <span class="property-type">object</span></dt>
|
|
31
|
+
<dd>Read by <i>Stop timer</i>.</dd>
|
|
32
|
+
</dl>
|
|
33
|
+
<h3>Outputs</h3>
|
|
34
|
+
<dl class="message-properties">
|
|
35
|
+
<dt>message <span class="property-type">object</span></dt>
|
|
36
|
+
<dd>The same message object. <i>Start timer</i> adds <code>msg.redkern.prom.timers[<key>]</code>
|
|
37
|
+
(milliseconds since the epoch); <i>Stop timer</i> removes it. Nothing else is changed.</dd>
|
|
38
|
+
</dl>
|
|
39
|
+
<h3>Details</h3>
|
|
40
|
+
<p>Actions: <b>Increment</b> (counter, gauge), <b>Decrement</b> and <b>Set</b> (gauge), <b>Observe</b> (histogram, summary,
|
|
41
|
+
or a counter with duration tracking), <b>Start timer</b> and <b>Stop timer and observe</b> to measure a part of the flow:
|
|
42
|
+
put the start node before the part and the stop node after it, using the same metric or the same timer key.</p>
|
|
43
|
+
<p>Values and labels accept <code>num</code>, <code>str</code>, <code>msg</code>, <code>flow</code>, <code>global</code>
|
|
44
|
+
and <code>env</code>. JSONata is not supported. Durations can be given in seconds or milliseconds.</p>
|
|
45
|
+
<p>Labels <code>step</code> (the node name, or a configured value), <code>status</code> (default <code>success</code>)
|
|
46
|
+
and <code>process</code> (the flow tab name) are filled automatically when the metric declares them.
|
|
47
|
+
Other declared labels are set in <b>Extra labels</b>. If a declared label has no value the write is skipped with a warning.</p>
|
|
48
|
+
<p>The node never stops the flow: a failed metric write is logged once and the message is still sent.
|
|
49
|
+
Messages are forwarded in arrival order unless a value comes from an asynchronous context store.</p>
|
|
50
|
+
<p>Status: yellow <i>dropped N</i> when the cardinality limit rejects series, red when the metric config is missing,
|
|
51
|
+
invalid or conflicts with another config node of the same name.</p>
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<script type="text/html" data-help-name="redkern-prom-exporter">
|
|
55
|
+
<p>Serves <code>/metrics</code> for Prometheus: this palette's metrics, default Node.js metrics and the metrics of other redkern palettes.</p>
|
|
56
|
+
<h3>Details</h3>
|
|
57
|
+
<p><b>Dedicated port</b> (default): the kit internal listener on port 9550 (<code>REDKERN_PROM_INTERNAL_PORT</code>)
|
|
58
|
+
at <code>/redkern/prom/metrics</code>. The public <code>httpNode</code> port is never used.</p>
|
|
59
|
+
<p>Authentication: Prometheus sends <code>Authorization: Bearer <token></code> with the value of
|
|
60
|
+
<code>REDKERN_PROM_METRICS_TOKEN</code> (32-4096 printable characters, not reused by other routes).
|
|
61
|
+
Without it the exporter stays red in this mode.</p>
|
|
62
|
+
<p><b>Node-RED admin API</b>: the same Node-RED port, <code>GET <httpAdminRoot>/redkern/prom/metrics</code> with
|
|
63
|
+
permission <code>redkern.prom.read</code>. Requires <code>adminAuth</code>; answers 503 when no exporter is active.</p>
|
|
64
|
+
<p>Only one exporter runs per Node-RED instance; a second one turns red and does not open a port.</p>
|
|
65
|
+
<p>Other redkern palettes (gateway, snowflake, redis, ...) register their metrics with this exporter automatically and
|
|
66
|
+
stop serving them on their own ports. A metric name that appears twice is served once, with a warning.</p>
|
|
67
|
+
<p><b>Collect default metrics</b> adds process, heap, GC and event-loop metrics with the <code>nodered_</code> prefix and
|
|
68
|
+
<code>nodered_flows_deploy_total</code>. <b>Add host label</b> duplicates the <code>pod</code> label from Kubernetes
|
|
69
|
+
service discovery and is off by default.</p>
|
|
70
|
+
<p><b>Include prom-client global registry</b> adds the global registry of this palette's own prom-client copy.</p>
|
|
71
|
+
<h3>References</h3>
|
|
72
|
+
<ul>
|
|
73
|
+
<li><a href="https://github.com/redkern/node-red-prometheus#deployment">Scrape configuration and Helm values</a></li>
|
|
74
|
+
</ul>
|
|
75
|
+
</script>
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
{
|
|
2
|
+
"redkern-prom": {
|
|
3
|
+
"paletteLabel": {
|
|
4
|
+
"metric": "metric",
|
|
5
|
+
"exporter": "exporter"
|
|
6
|
+
},
|
|
7
|
+
"label": {
|
|
8
|
+
"metric": "metric",
|
|
9
|
+
"metricConfig": "metric config",
|
|
10
|
+
"exporterPort": "exporter :__port__",
|
|
11
|
+
"exporterAdmin": "exporter (admin)"
|
|
12
|
+
},
|
|
13
|
+
"inputLabel": "message",
|
|
14
|
+
"outputLabel": "same message",
|
|
15
|
+
"section": {
|
|
16
|
+
"definition": "Metric definition",
|
|
17
|
+
"cardinality": "Cardinality",
|
|
18
|
+
"write": "Metric write",
|
|
19
|
+
"labels": "Labels",
|
|
20
|
+
"endpoint": "Prometheus endpoint",
|
|
21
|
+
"defaults": "Default metrics"
|
|
22
|
+
},
|
|
23
|
+
"field": {
|
|
24
|
+
"name": "Name",
|
|
25
|
+
"metricType": "Type",
|
|
26
|
+
"metricName": "Prometheus name",
|
|
27
|
+
"help": "Description",
|
|
28
|
+
"labelNames": "Label names",
|
|
29
|
+
"buckets": "Buckets",
|
|
30
|
+
"withDuration": "Also track duration",
|
|
31
|
+
"durationBuckets": "Duration buckets",
|
|
32
|
+
"percentiles": "Percentiles",
|
|
33
|
+
"maxAgeSeconds": "Max age, s",
|
|
34
|
+
"ageBuckets": "Age buckets",
|
|
35
|
+
"maxSeriesPerMetric": "Max series",
|
|
36
|
+
"allowlist": "Allowed values",
|
|
37
|
+
"metric": "Metric",
|
|
38
|
+
"operation": "Action",
|
|
39
|
+
"autoStep": "Use node name as step",
|
|
40
|
+
"step": "Step",
|
|
41
|
+
"status": "Status",
|
|
42
|
+
"value": "Value",
|
|
43
|
+
"duration": "Duration",
|
|
44
|
+
"timer": "Timer key",
|
|
45
|
+
"labels": "Extra labels",
|
|
46
|
+
"mode": "Serve on",
|
|
47
|
+
"includeGlobalRegistry": "Include prom-client global registry",
|
|
48
|
+
"defaultMetrics": "Collect default metrics",
|
|
49
|
+
"prefix": "Prefix",
|
|
50
|
+
"hostLabel": "Add host label"
|
|
51
|
+
},
|
|
52
|
+
"type": {
|
|
53
|
+
"counter": "Counter",
|
|
54
|
+
"gauge": "Gauge",
|
|
55
|
+
"histogram": "Histogram",
|
|
56
|
+
"summary": "Summary"
|
|
57
|
+
},
|
|
58
|
+
"operation": {
|
|
59
|
+
"inc": "Increment",
|
|
60
|
+
"dec": "Decrement",
|
|
61
|
+
"set": "Set",
|
|
62
|
+
"observe": "Observe",
|
|
63
|
+
"startTimer": "Start timer",
|
|
64
|
+
"stopTimer": "Stop timer and observe"
|
|
65
|
+
},
|
|
66
|
+
"mode": {
|
|
67
|
+
"internal": "Dedicated port",
|
|
68
|
+
"admin": "Node-RED admin API"
|
|
69
|
+
},
|
|
70
|
+
"unit": {
|
|
71
|
+
"seconds": "seconds",
|
|
72
|
+
"ms": "ms"
|
|
73
|
+
},
|
|
74
|
+
"placeholder": {
|
|
75
|
+
"metricName": "nodered_events_total",
|
|
76
|
+
"labelNames": "step,status,process",
|
|
77
|
+
"buckets": "0.005, 0.05, 0.5, 5",
|
|
78
|
+
"percentiles": "0.5, 0.9, 0.99",
|
|
79
|
+
"timer": "defaults to the metric config id",
|
|
80
|
+
"label": "label",
|
|
81
|
+
"values": "comma-separated values"
|
|
82
|
+
},
|
|
83
|
+
"hint": {
|
|
84
|
+
"metricName": "Changing the name, type, labels or buckets resets the metric's series.",
|
|
85
|
+
"labelNames": "Comma-separated. step, status and process are filled automatically.",
|
|
86
|
+
"maxSeries": "New label combinations above this limit are dropped and counted in redkern_prom_dropped_series_total.",
|
|
87
|
+
"allowlist": "Values outside the list are written as \"other\".",
|
|
88
|
+
"cardinality": "Keep label values bounded: never use IDs, UUIDs or timestamps.",
|
|
89
|
+
"token": "Requires REDKERN_PROM_METRICS_TOKEN: Prometheus sends it as Authorization: Bearer. Without it the exporter stays red; use the admin API mode instead.",
|
|
90
|
+
"port": "Kit internal listener on port 9550 (REDKERN_PROM_INTERNAL_PORT), path /redkern/prom/metrics.",
|
|
91
|
+
"admin": "Served at <httpAdminRoot>/redkern/prom/metrics with permission redkern.prom.read; requires adminAuth.",
|
|
92
|
+
"hostLabel": "Duplicates the pod label added by Kubernetes service discovery; enable only for dashboards that query host."
|
|
93
|
+
},
|
|
94
|
+
"button": {
|
|
95
|
+
"addAllowlist": "allowed values"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -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"> </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"> </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"> </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"> </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"> </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>
|