- LogFileMetricExporter ã«ã¹ã¿ã ãªã½ã¼ã¹ãè¦ã¦ã¿ã
- DaemonSet ã®å®ç¾©ãã¿ã
- ã½ã¼ã¹ãã¿ã
- ã¾ã¨ã
LogFileMetricExporter ã«ã¹ã¿ã ãªã½ã¼ã¹ãè¦ã¦ã¿ã
ã¯ããã«
ä»å¹´ãæ®ãå ãã¨ãªãã¾ãããOpenShift Advent Calendar 2024 24æ¥ç®ã®è¨äºã§ããå¹´ã®ç¬ã®ãå¿ããä¸ãç«ã¡å¯ããããã¨ããããã¾ãã
LogFileMetricExporter
æ¬è¨äºã§ã¯ãOpenShift Cluster Logging 5.8 ãã collector ããåé¢ããã Exporter ã«ã¤ãã¦è¦ã¦ããã¾ãã製åããã¥ã¡ã³ãã§ã¯ä»¥ä¸ã®ããã«è¨è¼ããã¦ãã¾ãã
In logging version 5.8 and newer versions, the LogFileMetricExporter is no longer deployed with the collector by default. You must manually create a LogFileMetricExporter custom resource (CR) to generate metrics from the logs produced by running containers.
If you do not create the LogFileMetricExporter CR, you may see a No datapoints found message in the OpenShift Container Platform web console dashboard for Produced Logs.
ãããã¤ããã®ã§ããã°ãLogFileMetricExporter ã«ã¹ã¿ã ãªã½ã¼ã¹ãå®ç¾©ããå¿
è¦ãããã¾ãã
ãã®ã«ã¹ã¿ã ãªã½ã¼ã¹ããªãå ´åã¯ãWeb Console ã®ããã·ã¥ãã¼ã ã« ProducedLog
ã表示ãããªãã¨ã®ãã¨ã§ãã
ã©ããªæ å ±ãã¨ããã®ã§ããããã
Configuring the logging collector - Logging | Observability | OpenShift Container Platform 4.16
åéã§ããã¡ããªã¯ã¹
å®éã«ãããã¤ãã¦ã©ããªã¡ããªã¯ã¹ãåéã§ãããè¦ã¦ã¿ã¿ã¾ãã ç¹å¥è¦ä»¶ããªããããããã¥ã¡ã³ãã«ãããµã³ãã«ããã®ã¾ã¾æ´»ç¨ãã¾ãã
apiVersion: logging.openshift.io/v1alpha1 kind: LogFileMetricExporter metadata: name: instance namespace: openshift-logging spec: nodeSelector: {} resources: limits: cpu: 500m memory: 256Mi requests: cpu: 200m memory: 128Mi tolerations: []
å®ç¾©ããã¨ãlogfilesmetricexporter
ãç¾ããåãã¼ãã« metricexporter ãèµ·åãã¦ãã¾ããã
NAME READY STATUS RESTARTS AGE cluster-logging-operator-75bfb4b58c-xclvh 1/1 Running 0 8h collector-5pcnz 1/1 Running 0 14m collector-7mwlt 1/1 Running 0 14m collector-hs62g 1/1 Running 0 14m collector-j66g8 1/1 Running 0 14m collector-mrw6g 1/1 Running 0 14m logfilesmetricexporter-8gkfx 1/1 Running 0 14m logfilesmetricexporter-hb5hb 1/1 Running 0 14m logfilesmetricexporter-hn9sm 1/1 Running 0 14m logfilesmetricexporter-qwvqx 1/1 Running 0 14m logfilesmetricexporter-v86x5 1/1 Running 0 14m logging-loki-compactor-0 1/1 Running 0 3h37m logging-loki-distributor-5b4756f5bb-pc8dc 1/1 Running 0 3h37m logging-loki-gateway-5f67b59847-n55z9 2/2 Running 0 3h37m logging-loki-gateway-5f67b59847-rxrhx 2/2 Running 0 3h37m logging-loki-index-gateway-0 1/1 Running 0 3h37m logging-loki-ingester-0 1/1 Running 0 3h37m logging-loki-querier-d666d57c-x4qjt 1/1 Running 0 3h37m logging-loki-query-frontend-7c78459847-b4xfw 1/1 Running 0 3h37m logging-loki-ruler-0 1/1 Running 0 3h37m logging-view-plugin-7597965997-rmb9w 1/1 Running 0 5h57m
ã¡ããªã¯ã¹ã®ã¨ã³ããã¤ã³ãã¯ãObserve > Targets ã§ç¢ºèªããã¨ãããhttps://<pod ip>:2112/metrics
ã§ããã
ã¡ããªã¯ã¹æ å ±ãåéãã¦ã¿ã¾ããPod ã«ä¹ãè¾¼ãã§ã¨ã³ããã¤ã³ãã«ã¢ã¯ã»ã¹ãã¾ãã
$ oc rsh logfilesmetricexporter-8gkfx sh-5.1# sh-5.1# curl -sk https://localhost:2112/metrics # HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles. # TYPE go_gc_duration_seconds summary go_gc_duration_seconds{quantile="0"} 5.6023e-05 go_gc_duration_seconds{quantile="0.25"} 0.000183166 go_gc_duration_seconds{quantile="0.5"} 0.000266248 go_gc_duration_seconds{quantile="0.75"} 0.00034949 go_gc_duration_seconds{quantile="1"} 0.001925796 go_gc_duration_seconds_sum 0.004054525 go_gc_duration_seconds_count 10 # HELP go_goroutines Number of goroutines that currently exist. # TYPE go_goroutines gauge go_goroutines 14 # HELP go_info Information about the Go environment. # TYPE go_info gauge go_info{version="go1.22.7 (Red Hat 1.22.7-1.el9_5)"} 1 # HELP go_memstats_alloc_bytes Number of bytes allocated and still in use. # TYPE go_memstats_alloc_bytes gauge go_memstats_alloc_bytes 4.524896e+06 # HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed. # TYPE go_memstats_alloc_bytes_total counter go_memstats_alloc_bytes_total 1.8430024e+07 # HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table. # TYPE go_memstats_buck_hash_sys_bytes gauge go_memstats_buck_hash_sys_bytes 7742 # HELP go_memstats_frees_total Total number of frees. ...
æ å ±ãå¤ãã®ã§éå¼ãã¨ä»¥ä¸ã®ãããªæãã§ããï¼go ã«é¢ããã¡ããªã¯ã¹ã¯çãã¾ããï¼
ã¡ããªã¯ã¹ | 説æ | ã¡ããªã¯ã¹ã¿ã¤ã |
---|---|---|
log_logged_bytes_total | Total number of bytes written to a single log file path, accounting for rotations | counter |
process_cpu_seconds_total | Total user and system CPU time spent in seconds. | counter |
process_max_fds | Maximum number of open file descriptors. | gauge |
process_open_fds | Number of open file descriptors. | gauge |
process_resident_memory_bytes | Resident memory size in bytes. | gauge |
process_start_time_seconds | Start time of the process since unix epoch in seconds. | gauge |
process_virtual_memory_bytes | Virtual memory size in bytes. | gauge |
process_virtual_memory_max_bytes | Maximum amount of virtual memory available in bytes. | gauge |
promhttp_metric_handler_requests_in_flight | Current number of scrapes being served. | gauge |
promhttp_metric_handler_requests_total | Total number of scrapes by HTTP status code. | counter |
è²ã
ããã¾ãããã¡ã¤ã³ã®ã¡ããªã¯ã¹ã¯ log_logged_bytes_total
ã«ãªãããã§ãããã¼ãã¼ã·ã§ã³ãèæ
®ããåä¸ã®ãã°ãã¡ã¤ã«ãã¹ã«æ¸ãè¾¼ã¾ããåè¨ãã¤ãæ°
ã§ãã
ãããè¦ããã¨ã§ãã³ã³ãããã¨ã«ã©ã®ãããã®ãã°ãåºåããã®ãã確èªã§ãããã§ãã
ããã·ã¥ãã¼ãã§ç¢ºèª
ãã®ã¡ããªã¯ã¹ã¯ãåè¿°ããããã«Web Console ã®ããã·ã¥ãã¼ãã§ãã§ã«ã°ã©ã表示ãå
èµããã¦ãã¾ãã
ããã·ã¥ãã¼ããéãã¦ã¿ã¾ããObserve > Dashboard ã®é ã«éããLogging/Collection
ããã·ã¥ãã¼ããéãã¾ãã
ããã·ã¥ãã¼ãã®ä¸ç¨ã« Produced Logs
ã¨ããé
ç®ãããã¾ãã
Top producing containers
㨠Top producing containers in last 24 hours
ã¨ããã°ã©ããããã¾ãã
Top producing containers
ã°ã©ãã®ã¯ã¨ãªæ å ±ã¯ä»¥ä¸ã¨ãªã£ã¦ããããã°ã®åºåãå¤ãé ã« 10 åã®ã³ã³ããã®æç³»åãã¼ã¿ãçºãããã¨ãã§ãã¾ãã
topk(10, round(rate(log_logged_bytes_total[5m])))
Top producing containers in last 24 hours
topk(10, sum(increase(log_logged_bytes_total[24h])) by (exported_namespace, podname, containername))
ä¸æ¹ã§ããã¡ãã¯24æé以å ã®å¢å æ å ±ããã¨ã«ããã°åºåãå¤ãé ã« 10 åã®ã³ã³ããæ å ±ããªã¹ãã«ãã¦ãã¾ãã
DaemonSet ã®å®ç¾©ãã¿ã
ã©ã®ãããªæ¹æ³ã§ç¢ºèªãã¦ããããè¦ã¦ããã¾ããDaemonSet ã®å®ç¾©ãã¿ã¾ãã
$ oc describe ds logfilesmetricexporter Name: logfilesmetricexporter Selector: component=logfilesmetricexporter,logging-infra=logfilesmetricexporter,provider=openshift Node-Selector: kubernetes.io/os=linux Labels: app.kubernetes.io/component=logfilesmetricexporter app.kubernetes.io/instance=logfilesmetricexporter app.kubernetes.io/managed-by=cluster-logging-operator app.kubernetes.io/name=lfme-service app.kubernetes.io/part-of=cluster-logging app.kubernetes.io/version=5.8.0 component=logfilesmetricexporter implementation= logging-infra=logfilesmetricexporter pod-security.kubernetes.io/enforce=privileged provider=openshift security.openshift.io/scc.podSecurityLabelSync=false Annotations: deprecated.daemonset.template.generation: 1 Desired Number of Nodes Scheduled: 5 Current Number of Nodes Scheduled: 5 Number of Nodes Scheduled with Up-to-date Pods: 5 Number of Nodes Scheduled with Available Pods: 5 Number of Nodes Misscheduled: 0 Pods Status: 5 Running / 0 Waiting / 0 Succeeded / 0 Failed Pod Template: Labels: app.kubernetes.io/component=logfilesmetricexporter app.kubernetes.io/instance=logfilesmetricexporter app.kubernetes.io/managed-by=cluster-logging-operator app.kubernetes.io/name=lfme-service app.kubernetes.io/part-of=cluster-logging app.kubernetes.io/version=5.8.0 component=logfilesmetricexporter implementation= logging-infra=logfilesmetricexporter pod-security.kubernetes.io/enforce=privileged provider=openshift security.openshift.io/scc.podSecurityLabelSync=false Annotations: target.workload.openshift.io/management: {"effect": "PreferredDuringScheduling"} Service Account: logfilesmetricexporter Containers: logfilesmetricexporter: Image: registry.redhat.io/openshift-logging/log-file-metric-exporter-rhel9@sha256:daa8fa30560a787835f7f3fa6d584555ddf8f10beda023a1d747b1f7ab8e2d36 Port: 2112/TCP Host Port: 0/TCP Command: /bin/bash Args: -c /usr/local/bin/log-file-metric-exporter -verbosity=2 -dir=/var/log/pods -http=:2112 -keyFile=/etc/logfilemetricexporter/metrics/tls.key -crtFile=/etc/logfilemetricexporter/metrics/tls.crt -tlsMinVersion=VersionTLS12 -cipherSuites=TLS_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA384,TLS_CHACHA20_POLY1305_SHA256,ECDHE-ECDSA-AES128-GCM-SHA256,ECDHE-RSA-AES128-GCM-SHA256,ECDHE-ECDSA-AES256-GCM-SHA384,ECDHE-RSA-AES256-GCM-SHA384,ECDHE-ECDSA-CHACHA20-POLY1305,ECDHE-RSA-CHACHA20-POLY1305,DHE-RSA-AES128-GCM-SHA256,DHE-RSA-AES256-GCM-SHA384 Limits: cpu: 500m memory: 256Mi Requests: cpu: 200m memory: 128Mi Environment: <none> Mounts: /etc/logfilemetricexporter/metrics from lfme-metrics (ro) /var/log/containers from varlogcontainers (ro) /var/log/pods from varlogpods (ro) Volumes: varlogcontainers: Type: HostPath (bare host directory volume) Path: /var/log/containers HostPathType: varlogpods: Type: HostPath (bare host directory volume) Path: /var/log/pods HostPathType: lfme-metrics: Type: Secret (a volume populated by a Secret) SecretName: lfme-secret Optional: false Priority Class Name: system-node-critical Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal CreateObject 38m logfilemetricexporter CreateObject DaemonSet openshift-logging/logfilesmetricexporter Normal SuccessfulCreate 38m daemonset-controller Created pod: logfilesmetricexporter-hn9sm Normal SuccessfulCreate 38m daemonset-controller Created pod: logfilesmetricexporter-hb5hb Normal SuccessfulCreate 38m daemonset-controller Created pod: logfilesmetricexporter-v86x5 Normal SuccessfulCreate 38m daemonset-controller Created pod: logfilesmetricexporter-qwvqx Normal SuccessfulCreate 38m daemonset-controller Created pod: logfilesmetricexporter-8gkfx
HostPath ãå©ç¨ã㦠/var/log/containers
ã /var/log/pods
ã®ãã£ã¬ã¯ããªé
ä¸ã確èªãã¦ããããã§ãã
ã½ã¼ã¹ãã¿ã
ã½ã¼ã¹ã³ã¼ããæ¢ãã¦ã¿ã¾ããRed Hat Ecosystem Catalog 㧠log file metric exporter
ãæ¤ç´¢ããã¨ä»¥ä¸ã®ã³ã³ããã¤ã¡ã¼ã¸ã«ãã©ãçãã¾ãã
Technical Information ã®ã¿ããéãã¨ãã½ã¼ã¹ã³ã¼ã㯠https://github.com/ViaQ/log-file-metric-exporter ã«ãããã¨ããããã¾ãã
ã½ã¼ã¹ã³ã¼ãã§å®éã«å¦çããã¦ããããªã¨ããã¯ãwatcher.go
ã§ããã
https://github.com/ViaQ/log-file-metric-exporter/blob/main/pkg/logwatch/watcher.go#L123
stat, err := os.Stat(path) if err != nil { return err } if stat.IsDir() { log.V(3).Info("Ignoring path given it is a directory", "path", path) return nil // Ignore directories } defer w.mutex.Unlock() w.mutex.Lock() lastSize, size := w.sizes[l], float64(stat.Size()) log.V(3).Info("Stats", "path", path, "lastSize", lastSize, "size", size) w.sizes[l] = size var add float64 if size > lastSize { // File has grown, add the difference to the counter. add = size - lastSize } else if size < lastSize { // File truncated, starting over. Add the size. add = size }
stat æ å ±ãåå¾ãããã¡ã¤ã«ãµã¤ãºã確èªãååããå¢ãã¦ããã°å¢åã追å ãæ¸ã£ã¦ãããæ°ããªãã¡ã¤ã«ã¨ãã¦ããµã¤ãºã追å ã¨ãããã¨ãç¹°ãè¿ãã¦ãã¾ãã ãã®é¨åããã¼ãã¼ã·ã§ã³ãèæ ®ããã¨ãããã¨ãªã®ã§ããããã
ã¾ã¨ã
LogFileMetricExporter ã«ããåå²ããã Exporter ã«ã¤ãã¦ç¢ºèªããã¾ããã åå²ãããã®ã¯ã³ã³ãããåºåãããã°éãè¨æ¸¬ãã¦ããã¡ããªã¯ã¹ã§ããããã·ã¥ãã¼ããå®ç¾©ããã¦ãããããLogFileMetricExpoter ãªã½ã¼ã¹ãå®ç¾©ããªãå ´åã¯ã°ã©ãã¯è¡¨ç¤ºããã¾ããããã©ã®ãããªå¤ãåºåããããã確èªãããã¨ãã§ãã¾ããã
LogFileMetricExporter ã«ã¤ãã¦ä¸æç¹ããªããªããã£ãããã¾ãããããã§å¹´ãè¶ããã§ããããã