From 74a0718d113c2824c4b52d7a4103ac6cb18bf0a7 Mon Sep 17 00:00:00 2001 From: Clemens Tolboom Date: Wed, 24 Jan 2024 10:42:56 +0100 Subject: [PATCH 01/28] Can we use actuator --- ui/src/App.vue | 15 +++++++++++++-- ui/src/api/api.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/ui/src/App.vue b/ui/src/App.vue index 5a32918c8..9657f121a 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -14,6 +14,11 @@ +
+
+            {{ JSON.stringify(metrics, null, 3) }}
+          
+
@@ -23,8 +28,8 @@ import Navbar from "@/components/Navbar.vue"; import Tabs from "@/components/Tabs.vue"; import Login from "@/views/Login.vue"; -import { defineComponent, onMounted, ref, Ref } from "vue"; -import { getPrincipal, getVersion, logout } from "@/api/api"; +import { defineComponent, onMounted, ref, Ref, toRaw } from "vue"; +import { getPrincipal, getVersion, getMetrics, logout } from "@/api/api"; import { useRouter } from "vue-router"; import { ApiError } from "@/helpers/errors"; @@ -39,11 +44,13 @@ export default defineComponent({ const isAuthenticated: Ref = ref(false); const username: Ref = ref(""); const version: Ref = ref(""); + const metrics: Ref> = ref([]); const router = useRouter(); onMounted(() => { loadUser(); loadVersion(); + loadMetrics(); }); const loadUser = async () => { @@ -68,10 +75,14 @@ export default defineComponent({ version.value = await getVersion(); }; + const loadMetrics = async () => { + metrics.value = await getMetrics(); + }; return { username, isAuthenticated, version, + metrics, loadUser, loadVersion, }; diff --git a/ui/src/api/api.ts b/ui/src/api/api.ts index 56f29629c..d8157cacb 100644 --- a/ui/src/api/api.ts +++ b/ui/src/api/api.ts @@ -85,6 +85,47 @@ export async function getVersion() { return result.build.version; } +export async function getMetrics() { + let result = await get("/actuator/metrics") + .then((data) => { + // Check if the data has 'names' property + if (data.hasOwnProperty("names")) { + // Initialize an empty tree + let tree = { _bare: {} }; + + // Process each name + data.names.forEach((name: string) => { + tree["_bare"][name] = {}; + // Split the name into parts + let parts = name.split("."); + + // Start at the root of the tree + let node = tree; + + // For each part, add a node to the tree if it doesn't exist + parts.forEach((part: PropertyKey) => { + if (!node.hasOwnProperty(part)) { + node[part] = {}; + } + + // Move to the next level of the tree + node = node[part]; + }); + }); + + // Log the tree + console.log(tree); + return tree; + } else { + console.log("No names found in the data"); + } + }) + .catch((error) => { + console.error("Error:", error); + }); + return result; +} + export async function deleteUser(email: string) { return delete_("/access/users", email); } From c161c882746efd2c2704c0711173bf7141dfec3d Mon Sep 17 00:00:00 2001 From: Clemens Tolboom Date: Thu, 25 Jan 2024 15:13:43 +0100 Subject: [PATCH 02/28] Restructure little --- ui/src/App.vue | 15 ++------------ ui/src/api/api.ts | 23 +++++++++++++++++---- ui/src/components/Actuator.vue | 33 ++++++++++++++++++++++++++++++ ui/src/components/ActuatorItem.vue | 26 +++++++++++++++++++++++ ui/src/views/Users.vue | 4 ++++ 5 files changed, 84 insertions(+), 17 deletions(-) create mode 100644 ui/src/components/Actuator.vue create mode 100644 ui/src/components/ActuatorItem.vue diff --git a/ui/src/App.vue b/ui/src/App.vue index 9657f121a..5a32918c8 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -14,11 +14,6 @@ -
-
-            {{ JSON.stringify(metrics, null, 3) }}
-          
-
@@ -28,8 +23,8 @@ import Navbar from "@/components/Navbar.vue"; import Tabs from "@/components/Tabs.vue"; import Login from "@/views/Login.vue"; -import { defineComponent, onMounted, ref, Ref, toRaw } from "vue"; -import { getPrincipal, getVersion, getMetrics, logout } from "@/api/api"; +import { defineComponent, onMounted, ref, Ref } from "vue"; +import { getPrincipal, getVersion, logout } from "@/api/api"; import { useRouter } from "vue-router"; import { ApiError } from "@/helpers/errors"; @@ -44,13 +39,11 @@ export default defineComponent({ const isAuthenticated: Ref = ref(false); const username: Ref = ref(""); const version: Ref = ref(""); - const metrics: Ref> = ref([]); const router = useRouter(); onMounted(() => { loadUser(); loadVersion(); - loadMetrics(); }); const loadUser = async () => { @@ -75,14 +68,10 @@ export default defineComponent({ version.value = await getVersion(); }; - const loadMetrics = async () => { - metrics.value = await getMetrics(); - }; return { username, isAuthenticated, version, - metrics, loadUser, loadVersion, }; diff --git a/ui/src/api/api.ts b/ui/src/api/api.ts index d8157cacb..9bab722ea 100644 --- a/ui/src/api/api.ts +++ b/ui/src/api/api.ts @@ -85,13 +85,17 @@ export async function getVersion() { return result.build.version; } +interface Tree { + [key: string]: any; +} + export async function getMetrics() { let result = await get("/actuator/metrics") .then((data) => { // Check if the data has 'names' property if (data.hasOwnProperty("names")) { // Initialize an empty tree - let tree = { _bare: {} }; + let tree: Tree = { _bare: {} }; // Process each name data.names.forEach((name: string) => { @@ -100,10 +104,10 @@ export async function getMetrics() { let parts = name.split("."); // Start at the root of the tree - let node = tree; + let node: Tree = tree; // For each part, add a node to the tree if it doesn't exist - parts.forEach((part: PropertyKey) => { + parts.forEach((part: string) => { if (!node.hasOwnProperty(part)) { node[part] = {}; } @@ -115,7 +119,7 @@ export async function getMetrics() { // Log the tree console.log(tree); - return tree; + return JSON.parse(JSON.stringify(tree)); } else { console.log("No names found in the data"); } @@ -126,6 +130,17 @@ export async function getMetrics() { return result; } +export async function getMetric(name: string) { + let result = await get(`/actuator/metrics/${name}`) + .then((data) => { + return JSON.parse(JSON.stringify(data)); + }) + .catch((error) => { + console.error("Error:", error); + }); + return result; +} + export async function deleteUser(email: string) { return delete_("/access/users", email); } diff --git a/ui/src/components/Actuator.vue b/ui/src/components/Actuator.vue new file mode 100644 index 000000000..8eeb09199 --- /dev/null +++ b/ui/src/components/Actuator.vue @@ -0,0 +1,33 @@ + + diff --git a/ui/src/components/ActuatorItem.vue b/ui/src/components/ActuatorItem.vue new file mode 100644 index 000000000..eca09c9fa --- /dev/null +++ b/ui/src/components/ActuatorItem.vue @@ -0,0 +1,26 @@ + + diff --git a/ui/src/views/Users.vue b/ui/src/views/Users.vue index 344bc7d37..dd24bdc0a 100644 --- a/ui/src/views/Users.vue +++ b/ui/src/views/Users.vue @@ -1,5 +1,6 @@