HARVESTER:Fix storage used

This commit is contained in:
n313893254 2021-10-13 15:58:11 +08:00 committed by wujun
parent f3d74eb7c2
commit 098b7f639d
4 changed files with 49 additions and 19 deletions

View File

@ -1,6 +1,6 @@
<script>
import ConsumptionGauge from '@/components/ConsumptionGauge';
import { METRIC } from '@/config/types';
import { METRIC, LONGHORN } from '@/config/types';
import { formatSi, exponentNeeded, UNITS } from '@/utils/units';
export default {
@ -29,21 +29,33 @@ export default {
},
storageUsage() {
const inStore = this.$store.getters['currentProduct'].inStore;
const longhornNode = this.$store.getters[`${ inStore }/byId`](LONGHORN.NODES, `longhorn-system/${ this.row.id }`);
let out = 0;
if (this.metrics) {
out = this.metrics.storageUsage;
}
const diskStatus = longhornNode?.status?.diskStatus || {};
Object.values(diskStatus).map((disk) => {
if (disk?.storageAvailable && disk?.storageMaximum) {
out += disk.storageMaximum - disk.storageAvailable;
}
});
return out;
},
storageTotal() {
const inStore = this.$store.getters['currentProduct'].inStore;
const longhornNode = this.$store.getters[`${ inStore }/byId`](LONGHORN.NODES, `longhorn-system/${ this.row.id }`);
let out = 0;
if (this.metrics) {
out = this.metrics.storageTotal;
}
const diskStatus = longhornNode?.status?.diskStatus || {};
Object.values(diskStatus).map((disk) => {
if (disk?.storageMaximum) {
out += disk.storageMaximum;
}
});
return out;
},
@ -56,11 +68,12 @@ export default {
},
methods: {
memoryFormatter(value, exponent) {
memoryFormatter(value) {
const minExponent = exponentNeeded(this.storageTotal, 1024);
const formatOptions = {
addSuffix: false,
increment: 1024,
minExponent: exponent
minExponent,
};
return formatSi(value, formatOptions);

View File

@ -127,11 +127,17 @@ export default {
},
storageTotal() {
const inStore = this.$store.getters['currentProduct'].inStore;
const longhornNode = this.$store.getters[`${ inStore }/byId`](LONGHORN.NODES, `longhorn-system/${ this.row.id }`);
let out = 0;
if (this.metrics) {
out = this.metrics.storageTotal;
}
const diskStatus = longhornNode?.status?.diskStatus || {};
Object.values(diskStatus).map((disk) => {
if (disk?.storageMaximum) {
out += disk.storageMaximum;
}
});
return out;
},

View File

@ -255,12 +255,12 @@ export default {
storageUsage() {
let out = 0;
this.longhornNode.filter(n => n.spec.allowScheduling).forEach((node) => {
this.longhornNode.forEach((node) => {
const diskStatus = node?.status?.diskStatus || {};
Object.values(diskStatus).map((disk) => {
if (disk?.storageAvailable && disk?.storageMaximum) {
out += disk.storageMaximum - disk.storageAvailable;
if (disk?.conditions?.Schedulable?.status === 'True' && disk?.storageAvailable && disk?.storageMaximum) {
out += (disk.storageMaximum - disk.storageAvailable);
}
});
});
@ -271,8 +271,14 @@ export default {
storageTotal() {
let out = 0;
this.metricNodes.forEach((node) => {
out += node.storageTotal;
this.longhornNode.forEach((node) => {
const diskStatus = node?.status?.diskStatus || {};
Object.values(diskStatus).map((disk) => {
if (disk?.storageMaximum) {
out += disk.storageMaximum;
}
});
});
return out;

View File

@ -2,7 +2,9 @@
import ResourceTable from '@/components/ResourceTable';
import Loading from '@/components/Loading';
import { STATE, NAME, AGE } from '@/config/table-headers';
import { METRIC, NODE, SCHEMA, HCI } from '@/config/types';
import {
METRIC, NODE, SCHEMA, HCI, LONGHORN
} from '@/config/types';
import { allHash } from '@/utils/promise';
import metricPoller from '@/mixins/metric-poller';
import CopyToClipboard from '@/components/CopyToClipboard';
@ -25,7 +27,10 @@ export default {
mixins: [metricPoller],
async fetch() {
const _hash = { nodes: this.$store.dispatch('harvester/findAll', { type: NODE }) };
const _hash = {
nodes: this.$store.dispatch('harvester/findAll', { type: NODE }),
longhornNodes: this.$store.dispatch('harvester/findAll', { type: LONGHORN.NODES }),
};
if (this.$store.getters['harvester/schemaFor'](METRIC.NODE)) {
_hash.metric = this.$store.dispatch('harvester/findAll', { type: METRIC.NODE });