Skip to content

Commit

Permalink
[wip] node page
Browse files Browse the repository at this point in the history
Signed-off-by: seven <[email protected]>
  • Loading branch information
Blankll committed Jul 17, 2024
1 parent 8020379 commit babcdd6
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 3 deletions.
67 changes: 67 additions & 0 deletions src/store/connectionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ import { defineStore } from 'pinia';
import { pureObject } from '../common';
import { loadHttpClient, storeApi } from '../datasources';

export type SearchNode = {
ip: string;
name: string;
roles: Array<string>;
master: string;
heap: {
percent: string;
};
ram: {
percent: string;
};
cpu: string;
};

export type RawClusterStats = {
cluster_name: string;
cluster_uuid: string;
Expand All @@ -12,6 +26,7 @@ export type RawClusterStats = {
master: number;
data: number;
};
instances: Array<SearchNode>;
versions: Array<string>;
};
indices: {
Expand Down Expand Up @@ -135,6 +150,58 @@ export const useConnectionStore = defineStore('connectionStore', {
})) as ConnectionIndex[];
this.established = { ...connection, indices };
},
async fetchNodes() {
if (!this.established) return;
const client = loadHttpClient(this.established as Connection);
try {
const data = await client.get('/_cat/nodes', 'format=json');
this.established.rawClusterState!.nodes.instances = data.map(
(node: {
ip: string;
name: string;
'node.role': string;
master: string;
'heap.percent': string;
'ram.percent': string;
cpu: string;
}) => ({
ip: node.ip,
name: node.name,
roles: node['node.role']
.split('')
.map((char: string) => {
switch (char) {
case 'd':
return 'data';
case 'i':
return 'ingest';
case 'm':
return 'master';
case 'l':
return 'ml';
case 'r':
return 'remote_cluster_client';
case 't':
return 'transform';
default:
return '';
}
})
.filter((role: string) => role !== ''),
master: node.master,
heap: {
percent: node['heap.percent'],
},
ram: {
percent: node['ram.percent'],
},
cpu: node.cpu,
}),
);
} catch (err) {
console.error('failed to fetch nodes', err);
}
},
async fetchIndices() {
if (!this.established) throw new Error('no connection established');
const client = loadHttpClient(this.established as Connection);
Expand Down
36 changes: 33 additions & 3 deletions src/views/manage/components/node-state.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
<template>
<div>nodes page</div>
<div class="node-list-container">
<n-card
class="node-item"
hoverable
v-for="node in established?.rawClusterState?.nodes.instances"
:key="node.name"
:title="node.name"
>
</n-card>
</div>
</template>
<script setup lang="ts"></script>
<script setup lang="ts">
import { useConnectionStore } from '../../../store';
import { storeToRefs } from 'pinia';
<style scoped></style>
const connectionStore = useConnectionStore();
const { fetchNodes } = connectionStore;
const { established } = storeToRefs(connectionStore);
fetchNodes();
</script>
<style scoped lang="scss">
.node-list-container {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
gap: 15px;
margin-top: 10px;
cursor: pointer;
.node-item {
max-width: 200px;
}
}
</style>

0 comments on commit babcdd6

Please sign in to comment.