# atoptool/atop architecture

> Architecture diagram of the GitHub repository atoptool/atop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/atoptool/atop
- Repository: https://github.com/atoptool/atop

## Overview

##### Project type and purpose
- Atop is a Linux system- and process-level performance monitor and logger, written in C, with optional kernel/BPF modules and daemons for extended metrics (network, GPU, cgroups).
- It provides both an interactive full-screen ASCII UI (atop), daily raw‐counter logging (atopacctd + atopsar), and utilities (atopcat, atopconvert) for post-processing.

##### File structure and README
- Top-level binaries & scripts: “atop.c”, “acctproc.c/h”, “atopacctd.c/h”, “atopgpud”, shell scripts and service/timer units.
- Data‐collection modules: cgroups.c/h, gpucom.c/h, ifprop.c/h, netatop*.c, photoproc.c/h, photosyst.c/h, rawlog.c/h, show*.c/h, etc.
- Config & packaging: systemd units, init scripts, Makefile, rpmspec, man pages.
- Previous versions under “prev/”: historical headers for backwards compatibility.

A. Kernel‐space interfaces
1. Native /proc and syscalls (CPU, memory, disk, process tables)
2. Optional netatop kernel module or BPF module (netatop-bpf) for per-process network stats
B. Data‐collection layer (user‐space daemons & libraries)
1. atop (interactive full-screen UI)
2. atopacctd (daemon for interval‐based raw logging)
3. atopgpud (optional GPU daemon)
4. Library modules: cgroups, photoproc, gpucom, netstats, parseable/json, etc.
C. Storage & rotation
1. Raw log files on disk (compressed counters)
2. Systemd timer or cron + atop‐rotate.service for log rotation
D. Post‐processing utilities
1. atopsar (generate reports from raw logs)
2. atopcat / atopconvert (view or convert log data)
E. Packaging & deployment
1. Service units (systemd: atop.service, atopacctd.service, atopgpud.service)
2. SysV/OpenRC scripts (atop.init, atopacct.init)
3. Makefile, rpmspec files

##### Relationships and data flows
- atopacctd writes raw counter snapshots to log files → storage folder.
- atop (UI) reads live data directly and can read from logs (for retrospective view).
- atopsar, atopcat, atopconvert read raw logs → produce reports/CSV/ASCII.
- Cron/systemd timer triggers rotation service → log rotation and archival.
- Optional netatop and atopgpud feed additional metrics into the same collection pipeline.

##### Architectural patterns & design principles
- Layered architecture: kernel data sources → user-space collectors → storage → presentation
- Modular collectors: each resource-type (CPU, memory, disk, network, GPU, cgroups) is a separate module, loaded at compile time.
- Daemonization: distinct processes handle logging (atopacctd) vs. live UI (atop).
- Extensibility points: add new modules (e.g. netatop-bpf) by implementing collector interfaces (shown in json.h / parseable.h).
- Separation of concerns: I/O & parsing in “json.c/h” and “parseable.c/h”; display logic in “drawbar.c”, “show*.c”.

##### Technologies & frameworks to call out
- Language: C
- IPC / Metrics sourcing: /proc, netlink, BPF, kernel module interfaces
- Compression: inline gzip during rawlog writes
- Scheduling: systemd timers, cron jobs, shell scripts
- Packaging: RPM spec, Makefile, init scripts
- Terminal UI: ASCII full-screen via ncurses-style drawing routines

## Diagram (Mermaid)

```mermaid
flowchart TD
  title["Atop System Architecture"]

  subgraph "Kernel-space Interfaces"
    direction TB
    PROC["Native /proc & syscalls"]:::kernel
    NETLINK["Netlink interface"]:::kernel
    BPFNET["Optional BPF Module"]:::kernel
  end

  subgraph "User-space Collectors"
    direction TB
    subgraph "Interactive UI"
      ATOP["atop (interactive UI)"]:::app
    end
    subgraph "Logging Daemon"
      ACCTD["atopacctd"]:::app
    end
    subgraph "GPU Daemon"
      GPUD["atopgpud"]:::app
    end
    subgraph "Resource Collector Modules"
      CGROUPS["cgroups"]:::module
      PHOTOPROC["photoproc"]:::module
      PHOTOSYST["photosyst"]:::module
      IFPROP["ifprop"]:::module
      NETSTATS["netstats"]:::module
      RAWLOGMOD["rawlog"]:::module
      PARSE["parseable"]:::module
      JSONMOD["json"]:::module
    end
  end

  subgraph "Storage & Rotation"
    direction TB
    LOGS["Raw Log Files"]:::storage
    ROTATE_SVC["atop-rotate.service / timer"]:::service
    CRON["Cron jobs (atop.daily / atop.cronsysv)"]:::service
  end

  subgraph "Post-processing Utilities"
    direction TB
    SAR["atopsar"]:::util
    CAT["atopcat"]:::util
    CONV["atopconvert"]:::util
  end

  subgraph "Packaging & Deployment"
    direction TB
    MAKE["Makefile"]:::service
    SPEC["RPM Specs"]:::service
    SVCUI["atop.service"]:::service
    SVCAC["atopacctd.service"]:::service
    SVCGP["atopgpud.service"]:::service
    INITUI["atop.init / openrc"]:::service
    INITAC["atopacct.init / openrc"]:::service
  end

  PROC -->|"poll /proc"| ATOP
  PROC -->|"poll /proc"| ACCTD
  PROC -->|"poll /proc"| GPUD
  NETLINK -->|"netlink"| ATOP
  NETLINK -->|"netlink"| ACCTD
  BPFNET -->|"BPF socket"| ATOP
  BPFNET -->|"BPF socket"| ACCTD

  ACCTD -->|"write raw counters"| LOGS
  ATOP -->|"read logs"| LOGS

  CRON -->|"trigger daily"| ROTATE_SVC
  ROTATE_SVC -->|"rotate/archive"| LOGS

  LOGS -->|"read logs"| SAR
  LOGS -->|"read logs"| CAT
  LOGS -->|"read logs"| CONV

  class PROC,NETLINK,BPFNET kernel
  class ATOP,ACCTD,GPUD app
  class CGROUPS,PHOTOPROC,PHOTOSYST,IFPROP,NETSTATS,RAWLOGMOD,PARSE,JSONMOD module
  class LOGS storage
  class SAR,CAT,CONV util
  class ROTATE_SVC,CRON,MAKE,SPEC,SVCUI,SVCAC,SVCGP,INITUI,INITAC service

  classDef kernel fill:#cccccc,stroke:#333,stroke-width:1px
  classDef app fill:#add8e6,stroke:#000,stroke-width:1px
  classDef module fill:#e0e0ff,stroke:#000,stroke-width:1px
  classDef storage fill:#ffff99,stroke:#000,stroke-width:1px
  classDef util fill:#90ee90,stroke:#000,stroke-width:1px
  classDef service fill:#ffcc99,stroke:#000,stroke-width:1px

  click PROC "https://github.com/atoptool/atop/blob/master/procdbase.c"
  click NETLINK "https://github.com/atoptool/atop/blob/master/netlink.c"
  click BPFNET "https://github.com/atoptool/atop/blob/master/netatopbpfif.c"
  click BPFNET "https://github.com/atoptool/atop/blob/master/netatopif.c"
  click BPFNET "https://github.com/atoptool/atop/blob/master/netatop.h"
  click BPFNET "https://github.com/atoptool/atop/blob/master/netatopd.h"
  click ATOP "https://github.com/atoptool/atop/blob/master/atop.c"
  click ATOP "https://github.com/atoptool/atop/blob/master/atop.h"
  click ATOP "https://github.com/atoptool/atop/blob/master/drawbar.c"
  click ATOP "https://github.com/atoptool/atop/blob/master/showgeneric.c"
  click ATOP "https://github.com/atoptool/atop/blob/master/showgeneric.h"
  click ATOP "https://github.com/atoptool/atop/blob/master/showlinux.c"
  click ATOP "https://github.com/atoptool/atop/blob/master/showlinux.h"
  click ATOP "https://github.com/atoptool/atop/blob/master/showprocs.c"
  click ATOP "https://github.com/atoptool/atop/blob/master/showsys.c"
  click ACCTD "https://github.com/atoptool/atop/blob/master/atopacctd.c"
  click ACCTD "https://github.com/atoptool/atop/blob/master/atopacctd.h"
  click GPUD "https://github.com/atoptool/atop/tree/master/atopgpud"
  click GPUD "https://github.com/atoptool/atop/blob/master/gpucom.c"
  click GPUD "https://github.com/atoptool/atop/blob/master/gpucom.h"
  click CGROUPS "https://github.com/atoptool/atop/blob/master/cgroups.c"
  click CGROUPS "https://github.com/atoptool/atop/blob/master/cgroups.h"
  click PHOTOPROC "https://github.com/atoptool/atop/blob/master/photoproc.c"
  click PHOTOPROC "https://github.com/atoptool/atop/blob/master/photoproc.h"
  click PHOTOSYST "https://github.com/atoptool/atop/blob/master/photosyst.c"
  click PHOTOSYST "https://github.com/atoptool/atop/blob/master/photosyst.h"
  click IFPROP "https://github.com/atoptool/atop/blob/master/ifprop.c"
  click IFPROP "https://github.com/atoptool/atop/blob/master/ifprop.h"
  click NETSTATS "https://github.com/atoptool/atop/blob/master/netstats.h"
  click RAWLOGMOD "https://github.com/atoptool/atop/blob/master/rawlog.c"
  click RAWLOGMOD "https://github.com/atoptool/atop/blob/master/rawlog.h"
  click PARSE "https://github.com/atoptool/atop/blob/master/parseable.c"
  click PARSE "https://github.com/atoptool/atop/blob/master/parseable.h"
  click JSONMOD "https://github.com/atoptool/atop/blob/master/json.c"
  click JSONMOD "https://github.com/atoptool/atop/blob/master/json.h"
  click ROTATE_SVC "https://github.com/atoptool/atop/blob/master/atop-rotate.service"
  click ROTATE_SVC "https://github.com/atoptool/atop/blob/master/atop-rotate.timer"
  click CRON "https://github.com/atoptool/atop/blob/master/atop.daily"
  click CRON "https://github.com/atoptool/atop/blob/master/atop.cronsysv"
  click SAR "https://github.com/atoptool/atop/blob/master/atopsar.c"
  click CAT "https://github.com/atoptool/atop/blob/master/atopcat.c"
  click CONV "https://github.com/atoptool/atop/blob/master/atopconvert.c"
  click MAKE "https://github.com/atoptool/atop/tree/master/Makefile"
  click SPEC "https://github.com/atoptool/atop/blob/master/rpmspec/atop.specsystemd"
  click SPEC "https://github.com/atoptool/atop/blob/master/rpmspec/atop.specsysv"
  click SVCUI "https://github.com/atoptool/atop/blob/master/atop.service"
  click SVCAC "https://github.com/atoptool/atop/blob/master/atopacct.service"
  click SVCGP "https://github.com/atoptool/atop/blob/master/atopgpud.service"
  click INITUI "https://github.com/atoptool/atop/blob/master/atop.init"
  click INITUI "https://github.com/atoptool/atop/blob/master/atop.rc.openrc"
  click INITAC "https://github.com/atoptool/atop/blob/master/atopacct.init"
  click INITAC "https://github.com/atoptool/atop/blob/master/atopacct.rc.openrc"
```
