| 1 |
/* |
| 2 |
* Copyright (C) 2017 Red Hat, Inc. |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
import cockpit from "cockpit"; |
| 7 |
|
| 8 |
import React from "react"; |
| 9 |
|
| 10 |
import { Split, SplitItem } from "@patternfly/react-core/dist/esm/layouts/Split/index.js"; |
| 11 |
import { Grid, GridItem } from "@patternfly/react-core/dist/esm/layouts/Grid/index.js"; |
| 12 |
import { ZoomControls, SvgPlot, bytes_per_sec_config } from "cockpit-components-plot.jsx"; |
| 13 |
|
| 14 |
import { decode_filename, get_other_devices } from "./utils.js"; |
| 15 |
|
| 16 |
const _ = cockpit.gettext; |
| 17 |
|
| 18 |
const single_read_metric = { |
| 19 |
direct: ["disk.all.read_bytes"], |
| 20 |
internal: ["disk.all.read"], |
| 21 |
units: "bytes", |
| 22 |
derive: "rate", |
| 23 |
threshold: 1000 |
| 24 |
}; |
| 25 |
|
| 26 |
const single_write_metric = { |
| 27 |
direct: ["disk.all.write_bytes"], |
| 28 |
internal: ["disk.all.written"], |
| 29 |
units: "bytes", |
| 30 |
derive: "rate", |
| 31 |
threshold: 1000 |
| 32 |
}; |
| 33 |
|
| 34 |
const instances_read_metric = { |
| 35 |
direct: "disk.dev.read_bytes", |
| 36 |
internal: "block.device.read", |
| 37 |
units: "bytes", |
| 38 |
derive: "rate", |
| 39 |
threshold: 1000 |
| 40 |
}; |
| 41 |
|
| 42 |
const instances_write_metric = { |
| 43 |
direct: "disk.dev.write_bytes", |
| 44 |
internal: "block.device.written", |
| 45 |
units: "bytes", |
| 46 |
derive: "rate", |
| 47 |
threshold: 1000 |
| 48 |
}; |
| 49 |
|
| 50 |
export function update_plot_state(ps, client) { |
| 51 |
const devs = []; |
| 52 |
|
| 53 |
// show all top-level block objects: Drives and Other devices |
| 54 |
const blocks = Object.keys(client.drives).map(p => client.drives_block[p]) |
| 55 |
.concat(get_other_devices(client).map(p => client.blocks[p])); |
| 56 |
|
| 57 |
blocks.forEach(block => { |
| 58 |
const dev = block && decode_filename(block.Device).replace(/^\/dev\//, ""); |
| 59 |
if (dev) |
| 60 |
devs.push(dev); |
| 61 |
}); |
| 62 |
|
| 63 |
if (devs.length > 10) { |
| 64 |
ps.plot_single('read', single_read_metric); |
| 65 |
ps.plot_single('write', single_write_metric); |
| 66 |
} else { |
| 67 |
ps.plot_instances('read', instances_read_metric, devs); |
| 68 |
ps.plot_instances('write', instances_write_metric, devs); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
export const StoragePlots = ({ plot_state }) => { |
| 73 |
return ( |
| 74 |
<> |
| 75 |
<Split> |
| 76 |
<SplitItem isFilled /> |
| 77 |
<SplitItem><ZoomControls plot_state={plot_state} /></SplitItem> |
| 78 |
</Split> |
| 79 |
<Grid sm={12} md={6} lg={6} hasGutter> |
| 80 |
<GridItem> |
| 81 |
<SvgPlot className="storage-graph" |
| 82 |
title={_("Reading")} config={bytes_per_sec_config} |
| 83 |
plot_state={plot_state} plot_id='read' /> |
| 84 |
</GridItem> |
| 85 |
<GridItem> |
| 86 |
<SvgPlot className="storage-graph" |
| 87 |
title={_("Writing")} config={bytes_per_sec_config} |
| 88 |
plot_state={plot_state} plot_id='write' /> |
| 89 |
</GridItem> |
| 90 |
</Grid> |
| 91 |
</>); |
| 92 |
}; |