Measure the real memory used by an Ubuntu systemd service
“How much memory is my application using?” sounds like one question. On an Ubuntu server, it can refer to the main process, the whole systemd service, a managed heap or the entire host. Those values describe different scopes.
Server App Manager uses service cgroup measurements where available and displays host RAM separately. This guide shows how to interpret those readings and build a read-only comparison exercise without turning one snapshot into a diagnosis of a memory leak.
Decide which scope you need
For service operations, begin with the resources attributed to the service and its processes. A main PID is useful for process identity, but its individual memory reading does not automatically include every child.
For a .NET performance investigation, the managed heap can be another useful scope. It still does not represent all native allocations, mappings and other memory associated with the process or service.
At host level, total and available RAM describe the machine's capacity and present state. A dashboard card showing server RAM should never be copied into an individual application's row. Keep the subject of each measurement explicit in notes and screenshots.
Start from the registered unit
Identify the exact systemd unit whose memory you want to understand. Check its environment and current state before reading a number beside its display name.
A service that is stopped may have no active main process or readable current cgroup. An unknown value is not necessarily zero, and an unavailable peak is not evidence that no peak occurred.
For a lab example, use demo-web.service. Record the unit name, approximate sample time and application revision. This gives each later comparison a stable reference and prevents values from another environment being substituted accidentally.
Discover the cgroup instead of guessing its directory
A service can be placed below a custom slice or another nested hierarchy. Do not assume every unit lives directly below one fixed system.slice path.
The current dashboard obtains the unit's control-group location and uses validated access to the relevant files. For an independent, authorized read-only inspection, request the location:
systemctl show demo-web.service -p ControlGroup -p MainPID -p MemoryCurrent -p MemoryPeak
Use the actual returned group path when locating the service under the mounted cgroup v2 hierarchy. Keep the mount location and unit path as separate pieces of information rather than concatenating a guessed deployment directory.
Read the current measurement carefully
The cgroup v2 memory controller exposes memory.current for current attributed usage. A peak file may also be available, depending on the host's kernel and accounting support.
The kernel documentation explains these interfaces and their accounting scope. In particular, service-attributed memory is broader than a .NET managed heap. A comparison must keep the controller's meaning rather than treating all accounted bytes as live application objects. See the cgroup v2 memory documentation.
In the dashboard, open application details and read the current memory, peak, PID and task information together. Treat an unavailable file or unsupported counter as missing evidence. The interface uses N/A rather than filling the gap with host memory.
Keep units consistent
Raw Linux counters commonly express memory in bytes. Human-readable displays scale those values for readability.
When making a comparison, note whether the display uses decimal or binary units. One MiB is 1,048,576 bytes; one decimal MB is 1,000,000 bytes. A value labeled casually as “MB” by another tool can create a visible difference even if the underlying counter agrees.
For an exercise, retain the original byte value and write the conversion explicitly. Avoid rounding several times between tools. Compare like-for-like values before interpreting a small difference as a problem in either the application or the dashboard.
Expect nearby samples to differ
The dashboard and your terminal are unlikely to read a counter at exactly the same moment. An application can allocate, release or cache data between those reads.
Write down nearby timestamps and repeat the observation under a similar workload. A small disagreement between sequential samples is less informative than a persistent difference in scope, unit conversion or cgroup identity.
The dashboard also caches readings between refreshes. Use a manual refresh when checking a specific comparison, then record when it completed. Continuous rapid refreshes create additional work without making two independent samples perfectly simultaneous.
Compare current and peak without confusing them
Current usage answers what the counter attributes now. Peak usage describes a high-water mark over the scope and lifetime represented by that counter.
A peak can stay high after current usage falls. That is expected for a high-water mark and does not mean the application is still consuming the peak amount.
Avoid assuming a peak survived every service restart, cgroup recreation or host reboot. Record the lifecycle surrounding the observation. The source preview displays the available peak and leaves unsupported values as N/A; it does not create a permanent historical chart from a single kernel counter.
Use process details as supporting evidence
The main PID identifies a process chosen by systemd for the unit. Process counts and task counts describe other aspects of the running service.
A task count should not be interpreted as a request rate. A main-process resident measurement should not be assumed to equal the cgroup total. These are related observations with different purposes.
For a lab comparison, use a service that launches a known child process. Inspect the service-wide reading and the main-process view at nearby times. The goal is to explain the difference in membership and scope, not to force the two tools to report the same number.
Read host RAM separately
Server Monitoring shows total, used and available RAM for Ubuntu. These measurements are separate from an application's service row.
The host can use memory for the kernel, other services and caches. An application can hold a modest cgroup allocation while the machine has little available RAM because other workloads consume the rest.
The kernel's procfs documentation describes host and process interfaces. For operational notes, keep host capacity, host availability and service attribution in separate columns. This makes capacity conversations much clearer than reporting a single percentage without saying what it measures.
Investigate N/A before changing accounting
An unavailable value may result from an unsupported metric, missing permissions, a stopped service or a file that changed during sampling. Read the unit state and any displayed error before deciding which explanation fits.
Do not change resource accounting or service configuration solely to make a dashboard row look complete. Such changes belong to the server owner and need their own review.
When reporting a measurement problem, include the app revision, kernel and systemd versions, cgroup hierarchy type, unit state and sanitized observation. Share enough structure to explain the missing reading without exposing private paths or unrelated configuration.
Use a trend before calling something a leak
A single high reading does not establish a memory leak. Repeated samples under a documented workload can identify a pattern that deserves deeper investigation.
Record startup, warm-up, representative work and quieter periods separately. Note whether a restart or deployment reset the observation. If managed-memory diagnosis is needed, use the application's authorized diagnostic workflow rather than interpreting the cgroup total as a heap dump.
Server App Manager provides a practical service-level view. It is a starting point for resource questions, with monitoring documentation that keeps measurement scopes explicit.
Finish the comparison with an honest explanation
A useful result names the unit, control-group identity, sample times, raw units and display conversion. It explains why a process value, a peak or host RAM differs.
If a reading remains unavailable, retain that uncertainty rather than replacing it with an attractive number. Accurate N/A is more useful than a confident measurement of the wrong thing.
For implementation details, inspect the service metrics source alongside the exact application revision used for the exercise.