mirror of
https://github.com/siderolabs/talos.git
synced 2025-08-20 14:11:11 +02:00
Fixes #1563 This implements dmesg reading via `/dev/kmsg`, with message parsing and formatting. Kernel log facility and severity are parsed, timestamp is calculated relative to boot time (it's accurate unless time jumps a lot during node lifetime). New flags to follow dmesg was added, tail flag allows to stream only new message (ignoring old messages). We could try to implement tailing last N messages, just a bit more work, open to suggestions (for symmetry with regular logs). Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
24 lines
562 B
Go
24 lines
562 B
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
package kmsg
|
|
|
|
import (
|
|
"fmt"
|
|
"syscall"
|
|
"time"
|
|
)
|
|
|
|
func getBootTime() (time.Time, error) {
|
|
var sysinfo syscall.Sysinfo_t
|
|
|
|
err := syscall.Sysinfo(&sysinfo)
|
|
if err != nil {
|
|
return time.Time{}, fmt.Errorf("could not get boot time: %w", err)
|
|
}
|
|
|
|
// sysinfo only has seconds
|
|
return time.Now().Add(-1 * (time.Duration(sysinfo.Uptime) * time.Second)), nil
|
|
}
|