Skip to content

Commit 4324458

Browse files
committed
feat: #207 allow to collect metrics from non-swarm nodes
1 parent b64048c commit 4324458

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

Diff for: api-nodes/Http/Controllers/MetricsController.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ class MetricsController
4545
// Please don't judge me for this code. I'm a PHP developer.
4646
public function __invoke(Request $request, Logger $log, Node $node)
4747
{
48-
if ($node->swarm === null) {
49-
return new Response('{}', 204);
50-
}
51-
5248
// TODO: cache this with the new Laravel cache system (stale-while-revalidate from the recent release)
5349
$interfaces = collect($node->data->host->networks)->pluck('if_name')->unique()->toArray();
5450

@@ -228,7 +224,7 @@ public function __invoke(Request $request, Logger $log, Node $node)
228224
}
229225
}
230226

231-
$response = Metrics::importPrometheusMetrics($node->swarm->id, $node->id, $ingestMetrics);
227+
$response = Metrics::importPrometheusMetrics($node->id, $ingestMetrics);
232228
}
233229

234230
$response = new Response('{}', 204);

Diff for: app/Services/Metrics.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
// Multitenancy for single node: https://docs.victoriametrics.com/single-server-victoriametrics/#prometheus-querying-api-enhancements
88
class Metrics
99
{
10-
public static function importPrometheusMetrics($swarmId, $nodeId, $metrics)
10+
public static function importPrometheusMetrics($nodeId, $metrics)
1111
{
1212
$query = '';
13-
$query .= '?extra_label=swarm_id='.$swarmId;
14-
$query .= '&extra_label=node_id='.$nodeId;
13+
$query .= '?extra_label=node_id='.$nodeId;
1514

1615
return Http::withBody(implode("\n", $metrics), 'text/plain')->post(config('database.victoriametrics.url').'/api/v1/import/prometheus'.$query);
1716
}

Diff for: resources/js/Pages/Nodes/Index.vue

+15-5
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,29 @@ function getMetric(metric) {
2323
}
2424
2525
const avgLoad = computed(() => {
26-
return `${getMetric("ptah_node_load_avg_1m")} / ${getMetric("ptah_node_load_avg_5m")} / ${getMetric("ptah_node_load_avg_15m")}`;
26+
const metric1m = getMetric("ptah_node_load_avg_1m") ?? "...";
27+
const metric5m = getMetric("ptah_node_load_avg_5m") ?? "...";
28+
const metric15m = getMetric("ptah_node_load_avg_15m") ?? "...";
29+
30+
return `${metric1m} / ${metric5m} / ${metric15m}`;
2731
});
2832
2933
const cpuUsage = computed(() => {
30-
return getMetric("cpu_usage") + "%";
34+
const metric = getMetric("cpu_usage") ?? "...";
35+
36+
return metric + "%";
3137
});
3238
3339
const memoryUsage = computed(() => {
34-
return getMetric("memory_usage") + "%";
40+
const metric = getMetric("memory_usage") ?? "...";
41+
42+
return metric + "%";
3543
});
3644
3745
const diskUsage = computed(() => {
38-
return getMetric("disk_usage") + "%";
46+
const metric = getMetric("disk_usage") ?? "...";
47+
48+
return metric + "%";
3949
});
4050
4151
const refreshTimeoutId = ref(0);
@@ -126,7 +136,7 @@ onUnmounted(() => {
126136
</template>
127137
</div>
128138
</div>
129-
<div class="flex justify-between">
139+
<div class="flex justify-between" v-if="node.online">
130140
<div class="flex flex-col">
131141
<div class="flex flex-row justify-between">
132142
<div class="flex flex-col">

0 commit comments

Comments
 (0)