Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

logcenter

Centralized log collector for a node. Every yuno ships its log records to logcenter over UDP (the peer of the kernel’s to_udp log handler, default udp://127.0.0.1:1992). logcenter counts them by priority, writes them to size/disk-guarded rotatory files, aggregates a summary report, watches free disk/memory, and can e-mail the report or even restart the node on a queue alarm.

Architecture

C_LOGCENTER            <- counting, rotation, summary, monitoring, self-heal
    > C_GSS_UDP_S      <- UDP server (udp://127.0.0.1:1992), receives log records
    > C_TIMER          <- periodic disk/memory monitor

Summary e-mails are sent by publishing EV_SEND_EMAIL to the emailsender service (see emailsender).

Wire format

Each UDP datagram from the to_udp handler is:

<priority:1 char><sequence:8 hex><message bytes...><crc:8 hex>

logcenter computes the trailing CRC and tracks the sequence (a mismatch or a gap is only logged under the debug trace, and the record is filed all the same), strips both, then files the message. If the message body is JSON ({...}) it is also folded into the summary tree.

The priority is one character, '0' to '9' (LOG_EMERG to LOG_MONITOR), the sequence is 8 hex digits in upper case, and the CRC is the sum of every byte before it (priority, sequence and message), in 8 hex digits too. An INFO record (priority 6) with sequence 161:

6000000A1{"msgset":"Info","msg":"hello"}00000BEA

A record whose first byte is anything else is counted in no stat and written to no log, and logcenter says it with the WARNING “Log record with an invalid priority, not written” (peername, priority_byte, len, records): the first one, then at most one per minute with the records since. A yuno whose to_udp handler is not in the Yuneta output format shows up this way. Up to 7.33.0 nothing was said, and a first byte below '0' added 1 to a word of memory before the counters of the priorities.

Three more refusals are said the same way, each with its own minute (any process that reaches the UDP port sends as many as it wants):

RecordWARNINGWhat happens to it
under 17 bytes (priority, sequence and crc), an empty frame included“Log record too short, not written”counted in no stat, written to no log
first byte not '0'..'9'“Log record with an invalid priority, not written”the same, and its body is not parsed
priority of the summary, body starts with { and is not json“Log record is not json, not in the summary”written and counted by its priority, left out of the summary
msgset, msg, path, attr, event or queue_size of another type than its own“Log record with a field of the wrong type”written and counted by its priority. In the summary without that field, out of it when the field is msgset or msg

Only the records of the summary are parsed: alert, critical, error, warning and info. The others (debug, audit, monitor, emergency, notice) are written as they come, json or not. priority_byte is the first byte of the frame (-1 for an empty one), for example:

{"msgset": "Protocol", "msg": "Log record too short, not written", "peername": "127.0.0.1:40112", "priority_byte": -1, "len": 0, "records": 1400, "next_warning_in_ms": 60000}

and a record that gets the last warning (msgset must be a string):

{"msgset": 1, "msg": "Queue full"}

Up to 7.33.0 each short frame was an ERROR “gbuffer too small” -- one per NUL byte of a datagram --, each record that is not json a WARNING “frame is not json” with a dump of its bytes, whatever its priority, and each field of another type an ERROR “path MUST BE a json str” with a stack.

A record longer than one datagram (1500 bytes) is sent in PIECES, a NUL after the last one. C_GSS_UDP_S joins the pieces per PEER, "ip:port" of the sending yuno, so the long records of two yunos that arrive interleaved come out whole. Up to 7.25.4 every peer shared one channel, and such records were joined into one corrupt record -- one real cause of “json_load_callback() FAILED” on logcenter, written off until then as UDP noise.

pause-yuno and play-yuno of logcenter stop and start its UDP server, which opens a new socket and a new read on it. Up to 7.25.4 the read went on with the number of the socket the pause had closed -- the log file opened by the play just before sometimes got that number -- and logcenter stopped receiving with nothing logged. See C_UDP_S (Stop and start again).

What it does with each record

A UDP datagram (priority, sequence, message, crc) arrives at C_GSS_UDP_S; logcenter verifies the CRC and sequence, strips the framing, then fans out — counts by priority, writes a disk-guarded rotatory file, and if the body is JSON folds it into a summary tree; the summary is e-mailed and can restart the node on a queue alarm.

One datagram fans out three ways; only JSON bodies reach the summary tree.

  1. Counts it by syslog priority — Alert, Critical, Error, Warning, Info, Debug, Audit, Monitor.

  2. Writes it to a rotatory log file under the yuno’s logs/ directory, named from log_filename (mask DD/MM/CCYY-W-ZZZ). Rotation is bounded by max_rotatoryfile_size and pauses when free disk drops below min_free_disk. Each NEW file (a new day, or a size rotation) sends the summary e-mail and then resets the counters and the summary trees. With send_summary_disabled it does neither: no e-mail, and the counters go on adding up until reset-counters or a restart (they are not persistent). The same file opened again after a write that failed (a quota, no inodes, EIO) or after an rm is not a new file: no e-mail. When the new file of a day cannot be opened at once, its e-mail goes at the first open that works, once. A log_filename with no date letter (logcenter.log) is one file for ever: it is appended to at every start, never emptied by a date. See rotatory.

  3. Aggregates JSON records into a summary grouped by msgset → msg → count (separately for errors, warnings, infos).

Configuration

Inspect the effective config at runtime with ycommand command-yuno id=<id> service=__yuno__ command=view-config.

AttributeDefaultPurpose
urludp://127.0.0.1:1992UDP server to receive log records
from(required)From address for the summary e-mail
to(required)Recipient(s) of the summary e-mail (,/; separated)
subjectLog Center SummarySummary e-mail subject
log_filenameW.logRotatory file name (mask DD/MM/CCYY-W-ZZZ)
rpermission0Mode of the log file, set in the config only. 0: 0660, the rpermission of the environment without the bits of the other users. Another mode as a decimal number: 436 is 0664. See The mode of the log file
max_rotatoryfile_size600Max log file size (MB) before rotating
rotatory_bf_size10Rotatory write buffer (MB)
min_free_disk20Stop writing / warn below this % free disk
min_free_mem20Warn below this % free RAM
send_summary_disabledfalseSuppress summary e-mails
max_summary_keys0Entries (a msgset, a msg, a detail of a msg) that the summary takes between two resets of the counters. 0: no bound. See The bound of the summary
restart_on_alarmfalseRun restart_yuneta_command on a queue alarm
restart_yuneta_command/yuneta/bin/restart-yuneta -s (where it exists, or else yshutdown -s; … yuneta_agent --start …)Command run on alarm, with sh -c (with no signal blocked: up to 7.29.3 it ran with system(), which gave it the signals the yuno keeps blocked for its signalfd). restart-yuneta stops the yunos but logcenter and restarts the agent IN its systemd unit (sudo -n systemctl restart yuneta_agent.service). Up to 7.25.22, the default started the agent with --start, outside its unit, where systemd did not see it and the next boot did not start it. Config only: up to 7.25.21, write-attr was able to set it and persist it ("global": {"logcenter.restart_yuneta_command": "..."})
queue_restart_limit0Only restart if reported queue_size ≥ this (cmd enforces ≥ 10000)
timeout_restart_yuneta3600Min seconds between restarts (must be ≥ 3600)
timeout1000Monitor tick (ms)

The mode of the log file

The file holds the records of every yuno of the node (peers, users, commands, the kw of the events a yuno traces), so it is made for the user and the group of the yuno: mode 0660, as the log files of each yuno. A file that is already there with a wider mode is narrowed when logcenter opens it (at its play, and at each new file). No bit is ever added. Up to 7.33.0 it was 0664: every account of the machine read it.

An account that is not in group yuneta and reads the file (a log shipper of its own) no longer does: add it to the group, or give logcenter another mode in its config, a decimal number (json has no octal):

"global": {
    "Logcenter.rpermission": 436
}

436 is 0664, 416 is 0640. The logs directory keeps the xpermission of the environment (02775). search and tail are not affected: logcenter reads its own file.

Commands

CommandParametersDescription
display-summary—Return the summary report (includes internal errors)
send-summary—E-mail the summary report now (via emailsender)
enable-send-summary / disable-send-summary—Toggle send_summary_disabled
reset-counters—Zero the priority counters and summary trees
searchtext, maxcountSearch the stored log records
taillinesOutput the last lines log records (default 100)
restart-yuneta-on-queue-alarmenable, queue_restart_limit, timeout_restart_yunetaConfigure the queue-alarm self-heal
helpcmd, levelCommand help

search and tail read the log file (log_filename). When it cannot be read they answer result -1 and the cause in comment, and log an ERROR (“Cannot open log file”, with path and serrno). With no log file at all (log_filename empty) the comment is “No log file”. Up to 7.33.0 they answered result 0 and an empty list, the same as a search that matches nothing:

$ ycommand -c 'command-yuno yuno_role=logcenter service=logcenter command=search text=Queue'
ERROR -1: logcenter^mynode: Cannot open log file '/yuneta/realms/.../logs/logcenter.log': No such file or directory

The summary report (from display-summary / send-summary) looks like:

{
    "Global Counters": { "Alert": 0, "Critical": 0, "Error": 2, "Warning": 39, "Info": 1185, "Debug": 1937, "Audit": 0, "Monitor": 0 },
    "Node Owner": "artgins",
    "Global Errors":   { "App": { "email NOT sent": 1 }, "Liburing": { "getaddrinfo() FAILED": 1 } },
    "Global Warnings": { "Info": { "No authz db, authz only to local access": 1 } },
    "Global Infos":    { "Connect Disconnect": { "Connected": 295, "Disconnected": 386 } }
}

Monitoring & self-heal

The bound of the summary

The summary has one entry per msgset, per msg and per detail of a msg (the path, attr or event of three known messages). The records give the names, and any process that reaches the UDP port sends records. With no bound, a sender that puts a new msg in each record makes the summary grow until the memory of the yuno ends. The summary is emptied when it is sent by e-mail or with reset-counters, so with send_summary_disabled it grows until a restart.

max_summary_keys bounds it. When the summary holds that many entries, a record with a new msgset, msg or detail is counted under (others), in place of an entry of its own, and logcenter logs one WARNING (“Summary full: the records of a new msgset, msg or detail are counted under (others)”) until the counters are reset. The records of the entries that the summary already has are counted as always, and every record is still written to the log file and counted by its priority.

It is 0 by default (no bound, as up to 7.33.0): the summary is unbounded until you set it. A node logs a few hundred different entries a day, so a bound of some thousands changes nothing for it:

"kw": {
    "max_summary_keys": 5000
}
ycommand -c 'command-yuno id=<id> service=__yuno__ command=write-attr gobj_name=logcenter attribute=max_summary_keys value=5000'

With a bound of 5, and six WARNING records (Flood/m1, Flood/m2, Flood/m3, Other/m4, Flood/m1 after one Queue record):

"Global Warnings": {
    "Queue": { "Queue opened: the gate accepts messages": 1 },
    "Flood": { "m1": 2, "m2": 1, "(others)": 1 },
    "(others)": { "(others)": 1 }
}

Debugging

GClassLevelShows
C_LOGCENTERdebugCRC/sequence mismatches on incoming datagrams

Enable with ycommand command-yuno id=<id> service=__yuno__ command=set-gclass-trace gclass=C_LOGCENTER set=1 level=debug.