все еде отладк journal
This commit is contained in:
parent
95381f661c
commit
cf11b61746
|
|
@ -1,6 +1,6 @@
|
|||
[agent]
|
||||
name = "wf-agent2"
|
||||
log_level = "INFO"
|
||||
log_level = "DEBUG"
|
||||
|
||||
[control]
|
||||
socket_path = "/run/wf-agent2/control.sock"
|
||||
|
|
@ -56,9 +56,9 @@ token = ""
|
|||
|
||||
[executors.wpa_ctrl]
|
||||
enabled = true
|
||||
interface = "wlp3s0"
|
||||
interface = "wlx90de808a360f"
|
||||
ctrl_path = "/run/wpa_supplicant"
|
||||
source_name = "wpa-ctrl://wlp3s0"
|
||||
source_name = "wpa-ctrl://wlx90de808a360f"
|
||||
|
||||
[executors.system]
|
||||
enabled = false
|
||||
|
|
@ -70,7 +70,7 @@ extra_actions = []
|
|||
enabled = true
|
||||
mode = "tail"
|
||||
source_name = "systemd-journal"
|
||||
unit_allowlist = ["wpa_supplicant.service"]
|
||||
unit_allowlist = ["wpa_supplicant"]
|
||||
max_priority = 7
|
||||
|
||||
[collectors.dbus]
|
||||
|
|
|
|||
|
|
@ -198,18 +198,11 @@ class SystemdJournalBackend:
|
|||
self._journal_module: Any = None
|
||||
|
||||
def connect(self, config: JournalCollectorConfig) -> None:
|
||||
import os
|
||||
|
||||
print(
|
||||
f"JOURNAL runtime uid={os.getuid()} gid={os.getgid()} groups={os.getgroups()}",
|
||||
flush=True,
|
||||
)
|
||||
reader = _create_systemd_reader()
|
||||
journal_module = _SYSTEMD_JOURNAL_MODULE
|
||||
|
||||
try:
|
||||
reader.this_boot()
|
||||
print("JOURNAL reader created", flush=True)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
|
@ -262,19 +255,16 @@ class SystemdJournalBackend:
|
|||
|
||||
self._reader.process()
|
||||
|
||||
data = self._reader.get_next()
|
||||
if not data:
|
||||
return None
|
||||
while True:
|
||||
data = self._reader.get_next()
|
||||
if not data:
|
||||
return None
|
||||
|
||||
entry = JournalEntry.from_mapping(data)
|
||||
print(
|
||||
f"JOURNAL backend got unit={entry.fields.get('_SYSTEMD_UNIT', '')} "
|
||||
f"comm={entry.fields.get('_COMM', '')} "
|
||||
f"priority={entry.fields.get('PRIORITY', '')} "
|
||||
f"message={entry.message}",
|
||||
flush=True,
|
||||
)
|
||||
return entry
|
||||
entry = JournalEntry.from_mapping(data)
|
||||
if self._is_self_entry(entry):
|
||||
continue
|
||||
|
||||
return entry
|
||||
|
||||
def close(self) -> None:
|
||||
self._connected = False
|
||||
|
|
@ -286,6 +276,14 @@ class SystemdJournalBackend:
|
|||
if callable(close):
|
||||
close()
|
||||
|
||||
def _is_self_entry(self, entry: JournalEntry) -> bool:
|
||||
fields = entry.as_mapping()
|
||||
unit = str(fields.get("_SYSTEMD_UNIT", "") or "")
|
||||
comm = str(fields.get("_COMM", "") or "")
|
||||
syslog_id = str(fields.get("SYSLOG_IDENTIFIER", "") or "")
|
||||
|
||||
return unit == "wf-agent2.service" or comm == "agent" or syslog_id == "agent"
|
||||
|
||||
|
||||
class JournalCollector(CollectorBase):
|
||||
def __init__(
|
||||
|
|
@ -324,14 +322,12 @@ class JournalCollector(CollectorBase):
|
|||
return cls(config, pipeline, backend=backend, director_sink=director_sink)
|
||||
|
||||
def start(self) -> None:
|
||||
print(f"JOURNAL collector start connected={self._connected}", flush=True)
|
||||
if self._connected:
|
||||
return
|
||||
self._set_lifecycle_state(CollectorLifecycleState.CONNECTING)
|
||||
self._set_connection_state(CollectorConnectionState.CONNECTING)
|
||||
self._increment_stats(connect_attempt_total=1)
|
||||
try:
|
||||
print("JOURNAL collector calling backend.connect()", flush=True)
|
||||
self.backend.connect(self.config)
|
||||
except Exception as exc:
|
||||
self._record_error(exc)
|
||||
|
|
@ -367,67 +363,94 @@ class JournalCollector(CollectorBase):
|
|||
self._mark_healthy(True)
|
||||
self._clear_error()
|
||||
|
||||
def poll_once(
|
||||
self, *, now_mono_ns_value: int | None = None
|
||||
) -> CollectorPipelineOutcome | None:
|
||||
if not self._connected:
|
||||
return None
|
||||
try:
|
||||
entry = self.backend.read()
|
||||
print(f"JOURNAL read entry={entry is not None}", flush=True)
|
||||
except Exception as exc:
|
||||
self._handle_backend_error(exc)
|
||||
return None
|
||||
if entry is None:
|
||||
self._set_pipeline_state(CollectorPipelineState.IDLE)
|
||||
self._mark_healthy(True)
|
||||
return None
|
||||
|
||||
raw_event = self._entry_to_raw_event(entry, now_mono_ns_value=now_mono_ns_value)
|
||||
context = self._build_context(entry)
|
||||
self._increment_stats(events_received_total=1)
|
||||
def poll_once(
|
||||
self, *, now_mono_ns_value: int | None = None
|
||||
) -> CollectorPipelineOutcome | None:
|
||||
if not self._connected:
|
||||
return None
|
||||
|
||||
source_prefilter_reason = self._source_prefilter_reason(entry)
|
||||
if source_prefilter_reason is not None:
|
||||
self._increment_stats(events_prefilter_dropped_total=1)
|
||||
self._set_pipeline_state(CollectorPipelineState.IDLE)
|
||||
self._mark_healthy(True)
|
||||
print(
|
||||
f"JOURNAL prefilter rejected reason={source_prefilter_reason}",
|
||||
flush=True,
|
||||
)
|
||||
return CollectorPipelineOutcome(
|
||||
accepted=False,
|
||||
stage="prefilter",
|
||||
reason=source_prefilter_reason,
|
||||
raw_event=raw_event,
|
||||
context=context,
|
||||
)
|
||||
outcome = self.pipeline.process(raw_event, context=context)
|
||||
if outcome.accepted:
|
||||
self._increment_stats(
|
||||
events_normalized_total=1,
|
||||
events_marked_total=1,
|
||||
events_emitted_total=1,
|
||||
)
|
||||
self._set_pipeline_state(CollectorPipelineState.ACTIVE)
|
||||
self._mark_healthy(True)
|
||||
self._clear_error()
|
||||
if outcome.envelope is not None and self.director_sink is not None:
|
||||
self.director_sink(outcome.envelope)
|
||||
else:
|
||||
if outcome.stage == "prefilter":
|
||||
self._increment_stats(events_prefilter_dropped_total=1)
|
||||
elif outcome.stage == "validation":
|
||||
self._increment_stats(events_validation_failed_total=1)
|
||||
self._set_pipeline_state(CollectorPipelineState.IDLE)
|
||||
self._mark_healthy(True)
|
||||
try:
|
||||
entry = self.backend.read()
|
||||
except Exception as exc:
|
||||
self._handle_backend_error(exc)
|
||||
return None
|
||||
|
||||
if entry is None:
|
||||
self._set_pipeline_state(CollectorPipelineState.IDLE)
|
||||
self._mark_healthy(True)
|
||||
return None
|
||||
|
||||
fields = entry.as_mapping()
|
||||
unit = str(fields.get("_SYSTEMD_UNIT", "") or "")
|
||||
if unit != "wf-agent2.service":
|
||||
print(
|
||||
f"JOURNAL outcome accepted={outcome.accepted} "
|
||||
f"stage={outcome.stage} reason={outcome.reason}",
|
||||
f"JOURNAL ENTRY unit={unit} "
|
||||
f"comm={fields.get('_COMM', '')} "
|
||||
f"priority={fields.get('PRIORITY', '')} "
|
||||
f"message={entry.message}",
|
||||
flush=True,
|
||||
)
|
||||
return outcome
|
||||
|
||||
raw_event = self._entry_to_raw_event(entry, now_mono_ns_value=now_mono_ns_value)
|
||||
context = self._build_context(entry)
|
||||
self._increment_stats(events_received_total=1)
|
||||
|
||||
source_prefilter_reason = self._source_prefilter_reason(entry)
|
||||
if source_prefilter_reason is not None:
|
||||
self._increment_stats(events_prefilter_dropped_total=1)
|
||||
self._set_pipeline_state(CollectorPipelineState.IDLE)
|
||||
self._mark_healthy(True)
|
||||
if unit != "wf-agent2.service":
|
||||
print(
|
||||
f"JOURNAL DROP prefilter unit={unit} "
|
||||
f"reason={source_prefilter_reason}",
|
||||
flush=True,
|
||||
)
|
||||
return CollectorPipelineOutcome(
|
||||
accepted=False,
|
||||
stage="prefilter",
|
||||
reason=source_prefilter_reason,
|
||||
raw_event=raw_event,
|
||||
context=context,
|
||||
)
|
||||
|
||||
outcome = self.pipeline.process(raw_event, context=context)
|
||||
|
||||
if unit != "wf-agent2.service":
|
||||
print(
|
||||
f"JOURNAL PIPELINE accepted={outcome.accepted} "
|
||||
f"stage={outcome.stage} reason={outcome.reason} "
|
||||
f"type={raw_event.event_type} unit={unit}",
|
||||
flush=True,
|
||||
)
|
||||
|
||||
if outcome.accepted:
|
||||
self._increment_stats(
|
||||
events_normalized_total=1,
|
||||
events_marked_total=1,
|
||||
events_emitted_total=1,
|
||||
)
|
||||
self._set_pipeline_state(CollectorPipelineState.ACTIVE)
|
||||
self._mark_healthy(True)
|
||||
self._clear_error()
|
||||
if outcome.envelope is not None and self.director_sink is not None:
|
||||
if unit != "wf-agent2.service":
|
||||
print(
|
||||
f"JOURNAL SINK type={outcome.envelope.type} "
|
||||
f"source={outcome.envelope.source}",
|
||||
flush=True,
|
||||
)
|
||||
self.director_sink(outcome.envelope)
|
||||
else:
|
||||
if outcome.stage == "prefilter":
|
||||
self._increment_stats(events_prefilter_dropped_total=1)
|
||||
elif outcome.stage == "validation":
|
||||
self._increment_stats(events_validation_failed_total=1)
|
||||
self._set_pipeline_state(CollectorPipelineState.IDLE)
|
||||
self._mark_healthy(True)
|
||||
|
||||
return outcome
|
||||
|
||||
def drain_pending(
|
||||
self, *, limit: int | None = None, now_mono_ns_value: int | None = None
|
||||
|
|
@ -443,7 +466,6 @@ class JournalCollector(CollectorBase):
|
|||
return outcomes
|
||||
|
||||
def reconnect(self) -> bool:
|
||||
print("JOURNAL collector reconnect()", flush=True)
|
||||
self._increment_stats(reconnect_attempt_total=1)
|
||||
self._set_lifecycle_state(CollectorLifecycleState.RECONNECTING)
|
||||
self._set_connection_state(CollectorConnectionState.RECONNECTING)
|
||||
|
|
@ -465,7 +487,6 @@ class JournalCollector(CollectorBase):
|
|||
return True
|
||||
|
||||
def _handle_backend_error(self, exc: Exception) -> None:
|
||||
print(f"JOURNAL backend error: {exc!r}", flush=True)
|
||||
self._record_error(exc)
|
||||
self._set_connection_state(CollectorConnectionState.RECONNECTING)
|
||||
self._set_pipeline_state(CollectorPipelineState.ERROR)
|
||||
|
|
@ -547,7 +568,16 @@ class JournalCollector(CollectorBase):
|
|||
priority = _parse_priority(fields.get("PRIORITY"))
|
||||
|
||||
if unit == "wf-agent2.service":
|
||||
return "ignore self journal entries"
|
||||
return "ignore self journal entries: unit=wf-agent2.service"
|
||||
|
||||
# if unit == "wf-agent2.service":
|
||||
# return "ignore self journal entries: unit=wf-agent2"
|
||||
|
||||
# if unit == "agent":
|
||||
# return "ignore self journal entries: unit=agent"
|
||||
|
||||
# if comm == "agent":
|
||||
# return "ignore self journal entries: comm=agent"
|
||||
|
||||
if self.config.unit_allowlist and unit not in self.config.unit_allowlist:
|
||||
return f"unit not allowed: {unit or '<empty>'}"
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@ Wants=network-online.target
|
|||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=wifi-agent
|
||||
Group=wifi-agent
|
||||
SupplementaryGroups=systemd-journal
|
||||
User=root
|
||||
Group=root
|
||||
#User=wifi-agent
|
||||
#Group=wifi-agent
|
||||
#SupplementaryGroups=systemd-journal
|
||||
RuntimeDirectory=wf-agent2
|
||||
RuntimeDirectoryMode=0750
|
||||
WorkingDirectory=/opt/wf-agent2
|
||||
|
|
|
|||
Loading…
Reference in New Issue