NUS Hackers Wiki
NUS Hackers Wiki
  • NUS Hackers Wiki
  • Hackerschool
    • Virtual Machines and Linux
    • Beginners' Guide to the Terminal
      • Introduction to the Terminal
      • Modern Shell Tools
      • Shell Scripting
      • Real World Scripting
      • Resources
    • Self-Hosting: Three Easy Pieces
      • 1. Setting up your server
      • 2. Running Services
      • 3. Monitoring your server
    • Vim
    • Introduction to Zig
      • Language Basics
      • Error Handling
      • Memory Management
      • Working with C
      • Exploring comptime
    • CI/CD with Github Actions
      • Background
      • Basics of Github Actions
        • Target workflow
        • Running unit tests
        • Linting code
        • Deploying to Github Pages
      • Advanced use cases
        • Pollers
        • Github script
        • Executing third-party scripts
        • Reusable workflows
      • Cookbook
    • Lightning Git
      • Git Concepts
      • Getting Started with Git
      • Making your first commit
      • Branching
      • Merge Conflicts
      • Integrating remote repositories
      • Collaborative Workflows
      • Commit Manipulation and Reflog
      • Interactive rebasing
      • filter-repo
  • Orbital
    • JavaScript
      • Browser Developer Tools
      • Getting Started
      • Datatypes
      • Operators and Operations
      • Loops and Conditions
      • Functions
      • Strings
      • Arrays
      • HTML
        • Getting Started
        • Tag Attributes
        • HTML Forms
        • Browser Inspector
      • CSS
        • Selectors
        • Colors in CSS
        • Measurements in CSS
        • The Box Model
        • Adding Styles - Part 1
        • Adding Styles - Part 2
      • Working with the DOM
        • Querying the DOM - Selectors
        • Querying the DOM - Element Attributes
        • Querying the DOM - Element Styles
        • Events with JS and HTML
        • Exercise: Click Counter
        • Editing the DOM
        • Fetch Requests
        • Exercise: The NUSMods API
    • React
      • Setup
      • State
    • React Native
      • Setup
      • Intro to JSX
      • Basic Syntax
      • Handling UI
      • Props
      • State Management
    • Git
      • Setup
      • Command Glossary
      • Fundamental Concepts
        • Getting Started
        • Integrating Remote Repositories
        • Branching
        • Merge Conflicts
      • Collaborative Workflows
        • Fork and PR Workflow
        • Branch and PR Workflow
      • Advanced Concepts
        • Ignoring Files
        • Commit Message Conventions
        • Github Collaborators
        • CI/CD with Github Actions
        • Advanced Git Commands
      • FAQ
    • Telegram Bot
      • Creating a TeleBot
      • API Calls
      • Telebot Basics
      • Integrating API's
    • Relational Database
      • Database Overview
      • Database Design
      • Entity Relationship Diagram
      • SQL Basics & PostgreSQL
    • TypeScript
      • Types and Interfaces
      • Utility Types
      • Typing Component Props, Events, and Hooks
      • Why You Should Avoid Using any (and What to Do Instead)
      • TypeScript Tricks You’ll Use All the Time in React
Powered by GitBook
On this page
  • Understanding your system
  • Monitoring with top
Edit on GitHub
Export as PDF
  1. Hackerschool
  2. Self-Hosting: Three Easy Pieces

3. Monitoring your server

Understanding your system

So now we want to be able to navigate, operate and monitor our system. To do this, most servers have a relatively homogenous system: systemd!

systemd is a software suite that provides an array of system components for Linux operating systems. The main aim is to unify service configuration and behavior across Linux distributions.

systemctl is the command-line tool that manages the systemd system and service manager in Linux.

  • How to work with systemd units, etc

    • Many modern Linux distros go with systemd — it can handle services for you in a convenient manner

    • It comes with systemctl, along with a lot of other things — DNS caching resolvers, time sync, a bootloader, etc, But we'll want to focus on systemctl

    • Start/stop/restart services: systemctl start unit.service, etc

    • Check service status: systemctl status unit.service

journalctl is a utility for querying and displaying logs from journald, systemd’s logging service.

To see live logs:

journalctl -f

To see the first 20 lines

journalctl -n 20

To check a specific service:

journalctl -u sshd

To get all logs from last boot

journalctl -b

To filter by time (last 15 minutes for example)

journalctl --since "15 minutes ago"

Monitoring with top

Aside from reading warnings, and making sure our services are running, we often times also want to make sure our system as a whole is running as expected. This is where top and htop come into play

What is top?

  • top command is used to show the Linux processes. It provides a dynamic real-time view of the running system.

  • Think of it as a super powerful task manager for Linux.

Basic Usage

  • Just type top to start the program.

  • Pressing q will simply exit the command mode.

  • Pressing h will show you the help menu.

What does everything mean?

  • PID: Shows task’s unique process id.

  • PR: The process’s priority. The lower the number, the higher the priority.

  • VIRT: Total virtual memory used by the task.

  • USER: User name of owner of task.

  • %CPU: Represents the CPU usage.

  • TIME+: CPU Time, the same as ‘TIME’, but reflecting more granularity through hundredths of a second.

  • SHR: Represents the Shared Memory size (kb) used by a task.

  • NI: Represents a Nice Value of task. A Negative nice value implies higher priority, and positive Nice value means lower priority.

  • %MEM: Shows the Memory usage of task.

  • RES: How much physical RAM the process is using, measured in kilobytes.

  • COMMAND: The name of the command that started the process.

top cheatsheet

Some exercises!

  • Try running top and see what you can find out about your system!

  • What are the top 5 processes using the most CPU?

  • What would I press if I want to kill the processes using the most memory?

  • I want to see what processes start running when I start my computer. How would I do that?

Solution
  • What are the top 5 processes using the most CPU?

    • top -> Shift + P

  • What would I press if I want to kill the processes using the most memory?

    • top -> Shift + M -> k

  • I want to see what processes start running when I start my computer.

    • top -> f -> PID -> s -> q -> Shift + R

Previous2. Running ServicesNextVim

Last updated 7 months ago

https://gist.github.com/ericandrewlewis/4983670c508b2f6b181703df43438c3gist.github.com