Tag Archives: Docker/k8s

[Solved] Docker/k8s use Arthas to generate flame diagram Error: Perf events unavailable. See stderr of the target process.

Arthas generate flame diagram command

profiler start

Error message

Perf events unavailable. See stderr of the target process.

reason:

Officials listed the following reasons:

/proc/sys/kernel/perf_event_Paranoid is set to restricted mode (>= 2) (usually for this reason)

seccomp disables perf_event_Open API in a container (seccomp disables perf_event_open API in the container.)

OS runs under a hypervisor that does not virtualize performance counters

perf_event_Open API is not supported on this system, e.g. WSL

Solution:

Docker

Modify docker-compose.yml and add

    cap_add:
        - SYS_ADMIN

For example:

version: '1'
services:
  xxx:
    container_name: xxx
    hostname: xxx
    image: xxx
    ...
    # Make it possible to print flame maps in arthas
    cap_add:
        - SYS_ADMIN

k8s

Modify SVC configuration file and add

    securityContext:
      capabilities:
        add:
        - SYS_ADMIN

For example:

metadata:
  labels:
    service: hello-world
spec:
  containers:
  - image: "alpine:3.4"
    command: ["/bin/echo", "hello", "world"]
  
    # Make it possible to print flame maps in arthas
    securityContext:
      capabilities:
        add:
        - SYS_ADMIN