Skip to content

Commit

Permalink
[wip] display stats
Browse files Browse the repository at this point in the history
Signed-off-by: seven <[email protected]>
  • Loading branch information
Blankll committed Jul 16, 2024
1 parent 26f3d24 commit 9d8d22a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 239 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"monaco-editor": "^0.50.0",
"pinia": "^2.1.7",
"pinia-plugin-persistedstate": "^3.2.1",
"pretty-bytes": "^6.1.1",
"tauri-plugin-store-api": "github:tauri-apps/tauri-plugin-store#v1",
"tauri-plugin-system-info-api": "^1.0.2",
"ulidx": "^2.3.0",
Expand Down
217 changes: 18 additions & 199 deletions src/store/connectionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,211 +2,30 @@ import { defineStore } from 'pinia';
import { pureObject } from '../common';
import { loadHttpClient, storeApi } from '../datasources';

export type RawClusterState = {
export type RawClusterStats = {
cluster_name: string;
cluster_uuid: string;
version: number;
state_uuid: string;
master_node: string;
status: string;
nodes: {
[nodeId: string]: {
name: string;
ephemeral_id: string;
transport_address: string;
external_id: string;
attributes: {
zone_id: string;
'ml.allocated_processors_double': string;
'ml.allocated_processors': string;
zone: string;
'ml.machine_memory': string;
'xpack.installed': string;
'ml.max_jvm_size': string;
};
roles: Array<string>;
version: string;
};
};
transport_versions: Array<{ node_id: string; transport_version: string }>;
metadata: {
cluster_uuid: string;
cluster_uuid_committed: boolean;
cluster_coordination: {
term: number;
last_committed_config: Array<string>;
last_accepted_config: Array<string>;
voting_config_exclusions: Array<string>;
};
templates: {
[key: string]: unknown;
};
indices: {
[key: string]: unknown;
};
ingest: {
[key: string]: unknown;
};
data_stream: {
[key: string]: unknown;
};
component_template: {
[key: string]: unknown;
};
index_template: {
[key: string]: unknown;
};
repositories: {
[key: string]: unknown;
};
'index-graveyard': {
[key: string]: unknown;
};
persistent_tasks: {
[key: string]: unknown;
};
index_lifecycle: {
[key: string]: unknown;
};
reserved_state: {
[key: string]: unknown;
};
};
routing_table: {
indices: {
[key: string]: {
shards: {
[key: string]: Array<{
state: string;
primary: boolean;
node: string;
relocating_node: string;
shard: number;
index: string;
allocation_id: {
id: string;
};
recovery_source: {
type: string;
index: {
uuid: string;
name: string;
};
node: {
id: string;
};
restore_source: {
repository: string;
snapshot: string;
};
};
unassigned_info: {
reason: string;
};
allocation: {
id: {
id: string;
};
};
}>;
};
};
count: {
total: number;
master: number;
data: number;
};
};
routing_nodes: {
unassigned: Array<{
state: string;
primary: boolean;
node: string;
relocating_node: string;
shard: number;
index: string;
allocation_id: {
id: string;
};
recovery_source: {
type: string;
index: {
uuid: string;
name: string;
};
node: {
id: string;
};
restore_source: {
repository: string;
snapshot: string;
};
};
unassigned_info: {
reason: string;
};
allocation: {
id: {
id: string;
};
};
}>;
nodes: {
[key: string]: {
node: string;
shards: {
[key: string]: Array<{
state: string;
primary: boolean;
node: string;
relocating_node: string;
shard: number;
index: string;
allocation_id: {
id: string;
};
recovery_source: {
type: string;
index: {
uuid: string;
name: string;
};
node: {
id: string;
};
restore_source: {
repository: string;
snapshot: string;
};
};
unassigned_info: {
reason: string;
};
allocation: {
id: {
id: string;
};
};
}>;
};
};
indices: {
count: number;
shards: {
total: number;
primaries: number;
};
};
snapshots: {
[key: string]: unknown;
};
health: {
disk: {
high_watermark: string;
high_max_headroom: string;
flood_stage_watermark: string;
flood_stage_max_headroom: string;
frozen_flood_stage_watermark: string;
frozen_flood_stage_max_headroom: string;
docs: {
count: number;
};
shard_limits: {
max_shards_per_node: number;
max_shards_per_node_frozen: number;
store: {
size_in_bytes: number;
};
};
snapshot_deletions: {
snapshot_deletions: Array<string>;
};
};

export type Connection = {
Expand All @@ -218,7 +37,7 @@ export type Connection = {
sslCertVerification: boolean;
password?: string;
queryParameters?: string;
rawClusterState?: RawClusterState;
rawClusterState?: RawClusterStats;
};
export type ConnectionIndex = {
health: string;
Expand Down Expand Up @@ -276,9 +95,9 @@ export const useConnectionStore = defineStore('connectionStore', {
if (!this.established) return;
const client = loadHttpClient(this.established as Connection);
this.established.rawClusterState = (await client.get(
'/_cluster/state',
'/_cluster/stats',
'format=json',
)) as RawClusterState;
)) as RawClusterStats;
},
async testConnection(con: Connection) {
const client = loadHttpClient(con);
Expand Down
56 changes: 18 additions & 38 deletions src/views/manage/components/cluster-state.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,35 @@
<p>id: {{ props.cluster?.cluster_uuid }}</p>
</n-card>
<n-card class="cluster-item-box cluster-nodes-box">
<p>{{ $t('manage.nodes') }}: {{ clusterState.cluster.count }}</p>
<p>master: {{ clusterState.cluster.masterNode }}</p>
<p>data: {{ clusterState.cluster.dataNode }}</p>
<p>{{ $t('manage.nodes') }}: {{ props.cluster?.nodes.count.total }}</p>
<p>master: {{ props.cluster?.nodes.count.master }}</p>
<p>data: {{ props.cluster?.nodes.count.data }}</p>
</n-card>
<n-card class="cluster-item-box cluster-shards-box">
<p>{{ $t('manage.shards') }}: {{ clusterState.shards.count }}</p>
xxxx
<p>{{ $t('manage.shards') }}: {{ props.cluster?.indices.shards.total }}</p>
<p>primaries: {{ props.cluster?.indices.shards.primaries }}</p>
<p>
replicas:
{{
(props.cluster?.indices?.shards?.total || 0) -
(props.cluster?.indices.shards?.primaries || 0)
}}
</p>
</n-card>
<n-card class="cluster-item-box cluster-indices-box">
<p>{{ $t('manage.indices') }}: {{ clusterState.indices.count }}</p>
xxxx
<p>{{ $t('manage.indices') }}: {{ props.cluster?.indices.count }}</p>
<p>docs: {{ props.cluster?.indices.docs.count }}</p>
<p>size: {{ prettyBytes(props.cluster?.indices.store.size_in_bytes || 0) }}</p>
</n-card>
</div>
</template>

<script setup lang="ts">
import prettyBytes from 'pretty-bytes';
import { CheckmarkOutline } from '@vicons/carbon';
import { RawClusterState } from '../../../store';

const props = defineProps<{ cluster: RawClusterState | null }>();

const clusterState = computed(() => {
const nodes = Object.entries(props.cluster?.nodes || {}).map(([key, value]) => ({
id: key,
...value,
}));
// const shards = Object.entries(props.cluster?.shards || {}).map(([key, value]) => ({
// id: key,
// ...value,
// }));
const indices = Object.entries(props.cluster?.metadata.indices || {}).map(([key, value]) => ({
id: key,
...(value as Object),
}));
import { RawClusterStats } from '../../../store';

return {
cluster: {
count: nodes.length,
masterNode: nodes.filter(node => node).length,
dataNode: nodes.filter(node => node).length,
},
shards: {
count: 1,
},
indices: {
count: indices.length,
},
};
});
const props = defineProps<{ cluster: RawClusterStats | null }>();
</script>

<style lang="scss" scoped>
Expand Down
4 changes: 2 additions & 2 deletions src/views/manage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<tool-bar @switch-manage-tab="handleManageTabChange" />
<cluster-state
class="state-container"
:cluster="established?.rawClusterState"
:cluster="established?.rawClusterState as RawClusterStats"
v-if="activeTab === $t('manage.cluster')"
/>
<node-state class="state-container" v-if="activeTab === $t('manage.nodes')" />
Expand All @@ -13,7 +13,7 @@
<script setup lang="ts">
import ToolBar from './components/tool-bar.vue';
import ClusterState from './components/cluster-state.vue';
import { useConnectionStore } from '../../store';
import { RawClusterStats, useConnectionStore } from '../../store';
import { storeToRefs } from 'pinia';
import NodeState from './components/node-state.vue';
import { lang } from '../../lang';
Expand Down

0 comments on commit 9d8d22a

Please sign in to comment.