linux ghi-nhanh monitor - It costs 6 mins to read

Being a full-stack developer means to have an open mind towards new technologies, having your hands dirty in each one and to have an understanding of how a web application gets done from a concept to design to the finished product.

The idea of a “full-stack developer” isn’t about being fluent in every possible technology there is, because specialization exists for a reason. It’s more about having an understanding in each of the areas above, to communicate intelligently between team members and to be a good asset if the situation needs it.

SitePoint - Being a Full Stack Developer

Như anh An nói trong bài Full Stack Developer là ai?, Full-Stack Developer nên biết khi nào cần hiểu rộng, khi nào cần hiểu sâu và nó không mâu thuẫn gì với cái gọi là “Nhất nghệ tinh, nhất thân vinh” cả. Con đường trở thành Full-Stack Developer đầy chông gai nhưng nhiều cũng nhiều quả ngọt đang đợi.

Tâm sự lan man về Full Stack Developer thế thôi, mình nghĩ mình vẫn còn phải cố gắng nhiều. Bài viết này không phải là một bài chia sẻ kinh nghiệm về Monitoring System trên Hệ thống Linux (Bởi mình vốn chẳng nhiều kinh nghiệm). Mình cảm thấy nó cần thiết để tìm ra các nút thắt cổ chai để tối ưu Performance của Hệ thống nên share to learn. Đây cũng là một trong những kiến thức mà mình nghĩ mình nên bổ sung thêm trên con đường trở thành một Full stack developer.

Monitoring Linux System

Monitoring CPU usage

Sử dụng gói sar (trong bộ công cụ sysstat) để theo dõi CPU usage trên Hệ thống.

Những ứng dụng không phải chủ chốt như sysstat nên cài đặt nhanh bằng lệnh yum hay apt-get cho tiện. Không mất công biên dịch làm chi.

sar -u 10 8

-u - Hiển thị % sử dụng CPU 10 - Thời gian giữa 2 lệnh sar (số giây) 8 - số lần lệnh sar sẽ chạy

Ý nghĩa của các thông số

%usr - % CPU chạy ở User Mode %sys - % CPU chạy ở System Mode %idle - % CPU đang ở chế độ nghỉ %steal - more_info

Nếu %usr cao, có nghĩa là ứng dụng của Bạn không được tối ưu đúng cách và đang chiếm dụng quá nhiều tài nguyên CPU. Nếu %sys cao, có thể vấn đề nằm ở việc swapping hoặc paging và cần được làm rõ thêm. if the %idle value is low, it serves as an indication that either the CPUs are underpowered or the application load is high. Similarly, if we see nonzero values in the %iowait time column, it serves as a reminder that the I/O subsystem could be a potential bottleneck.

Monitoring paging and swapping

Paging occurs when a part of the operating system process gets transferred from the physical memory to the disk or is read back from the physical memory to the disk.

Swapping occurs when an entire process gets transferred to the disk from the physical memory or is read back to the physical memory from the disk. Depending on the system, either paging or swapping could be an issue.

If paging occurs normally and you see a trend of heavy swapping, then the issue could be related to insufficient memory, or sometimes the issue could be related to disk as well.

If the system is heavily paging and not swapping, the issue could be related to either the CPU or the memory.

vmstat -S m 10 20

Đọc thêm về cách sử dụng vmstat và đọc kết quả từ nó - Use vmstat to monitor Paging and Swapping

Các thông số quan trọng cần chú ý:

si - The si column reports the amount of memory that is moved from swap to “real” memory per second.

so - The so column reports the amount of memory that is moved to swap from “real” memory per second.

Đọc thêm bài viết - Linux Ate My Ram

free -m 

dòng -/+ buffers/cache, cột free chính là số ram còn trống, có thể sử dụng

sar -W

If we see high values in the pswpin/s (pages swapped into the memory per second) column and the pgpgout/s (pages swapped out per second) column, it means that the current memory is inadequate and needs to be either increased or, for certain application components, optimally resized.

http://unix.stackexchange.com/questions/78880/difference-between-sar-w-and-sar-b

Finding the worst user on the system

top - Xem % CPU, %MEM đang bị Process nào chiếm dụng nhiều nhất

Monitoring system load

uptime - Tập trung vào 3 con số Load average - Load average is categorized over the three time intervals, that is, the 1-, 5-, and 15-minute periods. Load averages are not categorized for the number of CPUs on the system. So for a system with a single CPU, a load average of 1 indicates 100 percent busy time period with zero idle time, whereas for a system with 5 CPUs a load average of 1 would indicate an idle time of 80 percent and a busy time period of only 20 percent. (Như vậy 5 CPU thì khi 100% busy time thì Load Average phải là 5.0)

Identifying CPU bottlenecks

Làm sao để xác định CPU không đủ năng lực xử lý?

Identifying disk I/O bottlenecks

http://www.techopedia.com/definition/30479/io-bottleneck http://searchstorage.techtarget.com/report/Troubleshooting-and-identifying-data-storage-performance-bottlenecks

Monitoring disk space usage
fdisk -l
df -h

Monitoring Network Status

TODO- Câu hỏi cần tìm lời đáp

Vẫn còn đang tìm câu trả lời.

Không cần thiết phải Free-up Ram vì Free-up Ram không thực sự hiệu quả, cái đáng làm là tìm điểm thắt cổ chai… và Nếu Ram lúc nào cũng gần đầy thì nó là dấu hiệu cho thấy bạn nên nâng cấp Máy hoặc xem lại Performance của Ứng dụng mình đang chạy, có bị Memory Leaks chỗ nào hay không?)

Thêm nữa, là SWAP sẽ được System tự clean up khi không dùng đến.

http://blog.midnightmonk.com/225/linux/free-up-and-release-unused-or-cached-memory.shtml

Cái này mình đã làm thử khi cài đặt lại Ubuntu Mate 15.04 thì mình có thể chọn lưu các thư mục của hệ thống vào từng ổ cứng hoặc phân vùng cụ thể.

Đọc thêm bài Theo dõi hiệu năng của Hệ điều hành- http://acegik.net/blog/java/performance/theo-doi-hieu-nang-cua-he-dieu-hanh.html