Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics: show system boots in metrics #21444

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions pkg/metrics/metrics.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,20 @@ class MetricsMinute extends React.Component {
});

let desc;
if (this.props.isExpanded && this.props.events) {
if (this.props.isExpanded && this.props.booted) {
const timestamp = this.props.startTime + (this.props.minute * 60000);
desc = (
<div className="metrics-events">
<time>{ timeformat.time(timestamp) }</time>
<span className="spikes_count" />
<span className="spikes_info">
<span className="type">
{_("Boot")}
</span>
</span>
</div>
);
} else if (this.props.isExpanded && this.props.events) {
const timestamp = this.props.startTime + (this.props.minute * 60000);

const logsPanel = (
Expand Down Expand Up @@ -1170,6 +1183,7 @@ class MetricsHour extends React.Component {
if (this.state.dataItems !== nextProps.data.length ||
this.state.isHourExpanded !== nextState.isHourExpanded ||
this.props.startTime !== nextProps.startTime ||
this.props.boots !== nextProps.boots ||
Object.keys(this.props.selectedVisibility).some(itm => this.props.selectedVisibility[itm] != nextProps.selectedVisibility[itm])) {
this.updateGraphs(nextProps.data, nextProps.startTime, nextProps.selectedVisibility, nextState.isHourExpanded);
return false;
Expand Down Expand Up @@ -1237,6 +1251,8 @@ class MetricsHour extends React.Component {
const dataOffset = minute * SAMPLES_PER_MIN;
const dataSlice = normData.slice(dataOffset, dataOffset + SAMPLES_PER_MIN);
const rawSlice = this.props.data.slice(dataOffset, dataOffset + SAMPLES_PER_MIN);
const is_boot = this.props.boots.includes(minute);

minuteGraphs.push(
<MetricsMinute
isExpanded={isHourExpanded}
Expand All @@ -1246,7 +1262,8 @@ class MetricsHour extends React.Component {
rawData={rawSlice}
events={minute_events[minute]}
startTime={this.props.startTime}
selectedVisibility={selectedVisibility} />
selectedVisibility={selectedVisibility}
booted={is_boot} />
);
}

Expand Down Expand Up @@ -1559,7 +1576,8 @@ class MetricsHistory extends React.Component {
packagekitExists: false,
isBeibootBridge: false,
isPythonPCPInstalled: null,
selectedVisibility: this.columns.reduce((a, v) => ({ ...a, [v[0]]: true }), {})
selectedVisibility: this.columns.reduce((a, v) => ({ ...a, [v[0]]: true }), {}),
boots: [], // journalctl --list-boots as [{started: Date, ended: Date}]
};

this.handleMoreData = this.handleMoreData.bind(this);
Expand Down Expand Up @@ -1621,8 +1639,24 @@ class MetricsHistory extends React.Component {
} catch (_ex) {}

const isBeibootBridge = cmdline?.includes("ic# cockpit-bridge");

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops! Can fix in a repush

this.setState({ packagekitExists, isBeibootBridge });
martinpitt marked this conversation as resolved.
Show resolved Hide resolved

try {
// Only 14 days of metrics are shown
// Requires superuser on Debian/Ubuntu, on Fedora/Arch users in the wheel group can list without superuser.
const output = await cockpit.spawn(["journalctl", "--list-boots", "--since", "-15d", "--output", "json"], { superuser: "try" });
const list_boots = JSON.parse(output);
const boots = list_boots.map(boot => {
return {
started: new Date(boot?.first_entry / 1000),
ended: new Date(boot?.last_entry / 1000),
current_boot: boot?.index === 0,
};
});
this.setState({ boots });
} catch (exc) {
console.warn("journalctl --list-boots failed", exc);
Comment on lines +1657 to +1658
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 added lines are not executed by any test.

}
}

handleMoreData() {
Expand Down Expand Up @@ -1927,14 +1961,20 @@ class MetricsHistory extends React.Component {
<Card isPlain>
<CardBody className="metrics-history">
{ this.state.hours.map((time, i) => {
const date_time = new Date(time);
const boot_minutes = this.state.boots.filter(reboot => reboot.started.getDay() === date_time.getDay() &&
reboot.started.getYear() === date_time.getYear() &&
reboot.started.getHours() === date_time.getHours())
.map(reboot => reboot.started.getMinutes());
const showHeader = i == 0 || timeformat.date(time) != timeformat.date(this.state.hours[i - 1]);

return (
<React.Fragment key={timeformat.dateTime(time)}>
{showHeader && <TextContent><Text component={TextVariants.h3} className="metrics-time"><time>{ timeformat.date(time) }</time></Text></TextContent>}
<MetricsHour key={time} startTime={parseInt(time)}
selectedVisibility={this.state.selectedVisibility}
data={this.data[time]} clipLeading={i == 0} />
data={this.data[time]} clipLeading={i == 0}
boots={boot_minutes} />
</React.Fragment>
);
})}
Expand Down
11 changes: 10 additions & 1 deletion test/verify/check-metrics
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,23 @@ class TestHistoryMetrics(testlib.MachineCase):
return

m.upload(["verify/files/metrics-archives/journal.journal.gz"], "/tmp")
# we need to move all other existing journals out of the way, otherwise boot order is going back in time
m.execute("""gunzip /tmp/journal.journal.gz
systemctl stop systemd-journald
rm /var/log/journal/*/*.journal
cp /tmp/journal.journal /var/log/journal/*/""")
b.reload()
b.enter_page("/metrics")

# details for above load event
# Expand metrics when loaded
b.wait_in_text(".metrics-heading", "CPU")
b.click("#metrics-hour-1615197600000 button.metrics-events-expander")

# Show boot as event
with b.wait_timeout(60):
b.wait_in_text(".metrics-minute[data-minute='35']", "Boot")

# details for above load event
b.click(f"{load_minute_sel} .metrics-events button.spikes_info")
b.wait_in_text(".cockpit-log-panel", "load-hog")
action = "Stopping" if load_minute == 39 else "Started"
Expand Down
Loading