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> <script>
import ConsumptionGauge from '@/components/ConsumptionGauge'; import ConsumptionGauge from '@/components/ConsumptionGauge';
import { METRIC } from '@/config/types'; import { METRIC, LONGHORN } from '@/config/types';
import { formatSi, exponentNeeded, UNITS } from '@/utils/units'; import { formatSi, exponentNeeded, UNITS } from '@/utils/units';
export default { export default {
@ -29,21 +29,33 @@ export default {
}, },
storageUsage() { 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; let out = 0;
if (this.metrics) { const diskStatus = longhornNode?.status?.diskStatus || {};
out = this.metrics.storageUsage;
Object.values(diskStatus).map((disk) => {
if (disk?.storageAvailable && disk?.storageMaximum) {
out += disk.storageMaximum - disk.storageAvailable;
} }
});
return out; return out;
}, },
storageTotal() { 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; let out = 0;
if (this.metrics) { const diskStatus = longhornNode?.status?.diskStatus || {};
out = this.metrics.storageTotal;
Object.values(diskStatus).map((disk) => {
if (disk?.storageMaximum) {
out += disk.storageMaximum;
} }
});
return out; return out;
}, },
@ -56,11 +68,12 @@ export default {
}, },
methods: { methods: {
memoryFormatter(value, exponent) { memoryFormatter(value) {
const minExponent = exponentNeeded(this.storageTotal, 1024);
const formatOptions = { const formatOptions = {
addSuffix: false, addSuffix: false,
increment: 1024, increment: 1024,
minExponent: exponent minExponent,
}; };
return formatSi(value, formatOptions); return formatSi(value, formatOptions);

View File

@ -127,11 +127,17 @@ export default {
}, },
storageTotal() { 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; let out = 0;
if (this.metrics) { const diskStatus = longhornNode?.status?.diskStatus || {};
out = this.metrics.storageTotal;
Object.values(diskStatus).map((disk) => {
if (disk?.storageMaximum) {
out += disk.storageMaximum;
} }
});
return out; return out;
}, },

View File

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

View File

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