This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
сервис_opentelemetry [2026/10/08 19:06] val |
сервис_opentelemetry [2026/11/05 15:10] (current) val [OpenTelemetry Collector] |
||
|---|---|---|---|
| Line 3: | Line 3: | ||
| ===== OpenTelemetry Collector ===== | ===== OpenTelemetry Collector ===== | ||
| * [[https://grafana.com/docs/loki/latest/send-data/otel/otel-collector-getting-started/]] | * [[https://grafana.com/docs/loki/latest/send-data/otel/otel-collector-getting-started/]] | ||
| + | |||
| <code> | <code> | ||
| - | wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.162.0/otelcol-contrib_0.162.0_linux_amd64.deb | + | $ wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.162.0/otelcol-contrib_0.162.0_linux_amd64.deb |
| + | |||
| + | # dpkg -i otelcol-contrib_0.162.0_linux_amd64.deb | ||
| + | </code><code> | ||
| + | # cat /etc/otelcol-contrib/config.yaml | ||
| + | </code><code> | ||
| + | receivers: | ||
| + | journald: | ||
| + | convert_to_semantic_conventions: true | ||
| + | resource: | ||
| + | service.name: ИМЯ_СИСТЕМЫ-journald | ||
| + | #Можно и просто journald , так как ниже добавляется и индексируется host_name | ||
| + | |||
| + | # filelog/roundcube: | ||
| + | # include: | ||
| + | # - /var/log/roundcube/*.log | ||
| + | # start_at: end | ||
| + | # resource: | ||
| + | # service.name: server-roundcube | ||
| + | # operators: | ||
| + | # - type: regex_parser | ||
| + | # regex: '^\[(?P<log_time>\d{2}-[A-Za-z]{3}-\d{4} \d{2}:\d{2}:\d{2} [+-]\d{4})\]:\s*(?P<message>.*)$' | ||
| + | # - type: time_parser | ||
| + | # parse_from: attributes.log_time | ||
| + | # layout: '%d-%b-%Y %H:%M:%S %z' | ||
| + | # - type: move | ||
| + | # from: attributes.message | ||
| + | # to: body | ||
| + | # - type: remove | ||
| + | # field: attributes.log_time | ||
| + | |||
| + | processors: | ||
| + | batch: | ||
| + | # filter/exclude_unimportant: | ||
| + | # error_mode: ignore | ||
| + | # logs: | ||
| + | # log_record: | ||
| + | # - 'IsMatch(body, "(?i)cron")' | ||
| + | transform: | ||
| + | error_mode: ignore | ||
| + | log_statements: | ||
| + | - context: log | ||
| + | statements: | ||
| + | - set(resource.attributes["syslog_identifier"], attributes["syslog.identifier"]) where attributes["syslog.identifier"] != nil | ||
| + | - set(resource.attributes["host_name"], resource.attributes["host.name"]) where resource.attributes["host.name"] != nil | ||
| + | - set(resource.attributes["loki.resource.labels"], "syslog_identifier, host_name") | ||
| + | |||
| + | exporters: | ||
| + | otlphttp/loki: | ||
| + | endpoint: "http://server:3100/otlp" | ||
| + | tls: | ||
| + | insecure: true | ||
| + | |||
| + | # debug: | ||
| + | # verbosity: detailed | ||
| + | |||
| + | service: | ||
| + | pipelines: | ||
| + | logs: | ||
| + | receivers: [journald] | ||
| + | # receivers: [journald, filelog/roundcube] | ||
| + | processors: [transform, batch] | ||
| + | # processors: [filter/exclude_unimportant, transform, batch] | ||
| + | exporters: [otlphttp/loki] | ||
| + | # exporters: [otlphttp/loki, debug] | ||
| + | </code><code> | ||
| + | # otelcol-contrib validate --config /etc/otelcol-contrib/config.yaml | ||
| + | |||
| + | # usermod -aG systemd-journal otelcol-contrib | ||
| + | |||
| + | # #ls -l /var/log/roundcube/ | ||
| + | # #usermod -aG adm otelcol-contrib | ||
| + | |||
| + | # service otelcol-contrib restart | ||
| </code> | </code> | ||