Pertemuan 11: Pemantauan Kinerja Sistem

1. Pendahuluan

Pemantauan kinerja sistem adalah kegiatan essential bagi administrator sistem untuk memastikan ketersediaan (availability), keandalan (reliability), dan kinerja (performance) sistem.

Focus: Setelah mempelajari audit keamanan, sekarang kita fokus pada bagaimana memantau dan mengoptimalkan kinerja sistem secara proaktif.
Proactive Detection
Identify issues early
Capacity Planning
Plan for growth
Resource Optimization
Optimize allocation
SLA Compliance
Meet service levels

2. Konsep Dasar Performance Monitoring

Mengapa Performance Monitoring Penting?
Proactive Issue Detection

Mengidentifikasi masalah sebelum berdampak pada pengguna

  • Early warning systems
  • Trend analysis
  • Anomaly detection
  • Predictive maintenance
Capacity Planning

Perencanaan kapasitas untuk future growth

  • Resource forecasting
  • Scaling strategies
  • Budget planning
  • Infrastructure roadmap
Resource Optimization

Mengoptimalkan alokasi resource

  • Load balancing
  • Resource allocation
  • Performance tuning
  • Cost optimization
SLA Compliance

Memastikan Service Level Agreements terpenuhi

  • Uptime monitoring
  • Performance metrics
  • Compliance reporting
  • Quality of service
Cost Management

Mengontrol biaya infrastruktur

  • Cloud cost optimization
  • Resource utilization
  • Waste reduction
  • ROI calculation
Performance Monitoring Pyramid
Business Metrics Revenue, User Satisfaction
Application Metrics Response Time, Throughput
System Metrics CPU, Memory, Disk, Network
Infrastructure Metrics Hardware Health

3. Key Performance Indicators (KPIs)

CPU Performance Metrics
CPU Utilization

85%

Percentage of CPU capacity used

Warning: >90%
Load Average

2.5

System load over 1, 5, 15 minutes

Ideal: < cores count
Context Switches

15k/s

Process switching frequency

High = CPU contention
Memory Performance Metrics
Memory Usage

72%

Physical memory utilization

Swap Usage

15%

Swap space utilization

Warning: >20%
Page Faults

250/s

Memory page faults per second

High = Memory pressure
Cache Hit Ratio

94%

Buffer cache effectiveness

Ideal: >90%
Disk I/O Performance Metrics
I/O Utilization

65%

Disk bandwidth utilization

Warning: >80%
I/O Wait

8%

CPU waiting for I/O

Warning: >10%
Queue Length

4.2

Average I/O queue length

Ideal: < 2 per spindle
Network Performance Metrics
Bandwidth Usage

45%

Network capacity utilization

Packet Loss

0.2%

Dropped packets percentage

Warning: >1%
Latency

24ms

Round-trip time

Good: < 50ms
Error Rate

0.05%

Network errors percentage

Warning: >0.1%

4. Linux Performance Monitoring Tools

Real-time Monitoring Tools
top & htop

Real-time process monitoring

# Basic process monitoring
top
htop

# Custom top output
top -p 1234,5678 # Monitor specific PIDs
top -u apache # Monitor specific user processes

# htop shortcuts
# F1: Help, F2: Setup, F3: Search
# F4: Filter, F5: Tree view, F9: Kill process
vmstat

Virtual Memory Statistics

# Basic usage
vmstat 1 10 # Update every 1 second, 10 times

# Detailed interpretation
vmstat -s # Summary statistics
vmstat -d # Disk statistics
vmstat -a # Active/inactive memory

# Output analysis:
# r: Running processes
# b: Blocked processes
# swpd: Swap used
# free: Free memory
# si: Swap in, so: Swap out
iostat

I/O Statistics

# Install sysstat package
sudo apt install sysstat

# Basic I/O monitoring
iostat 1 5 # Every 1s, 5 times
iostat -x 1 # Extended statistics
iostat -d -k 1 # Device stats in KB/s

# Key metrics:
# %util: Disk utilization
# await: Average I/O wait time
# r/s, w/s: Read/write operations per second
# rKB/s, wKB/s: Read/write KB per second
System Activity Reporter (sar)
# Install sysstat
sudo apt install sysstat

# Enable data collection
sudo systemctl enable sysstat
sudo systemctl start sysstat

# CPU monitoring
sar -u 1 3 # CPU utilization
sar -q 1 3 # Load average

# Memory monitoring
sar -r 1 3 # Memory utilization
sar -B 1 3 # Paging statistics
Advanced Monitoring Tools
dstat
# Install dstat
sudo apt install dstat

# Comprehensive monitoring
dstat -cdlmnpsy 1

# Custom columns
dstat -c --top-cpu -d --top-bio --top-latency 1
nmon
# Install nmon
sudo apt install nmon

# Interactive monitoring
nmon

# Key shortcuts:
# c: CPU, m: Memory
# d: Disk, n: Network
# t: Top processes
pidstat
# Process-specific monitoring
pidstat -u 1 5 # CPU by process
pidstat -r 1 5 # Memory by process
pidstat -d 1 5 # Disk I/O by process

# Detailed process monitoring
pidstat -p 1234 1 5 # Specific PID
pidstat -t 1 5 # Thread-level

5. Windows Performance Monitoring

Performance Monitor (perfmon)
GUI Monitoring

Graphical performance monitoring

# Launch perfmon
perfmon

# Common performance counters:
# \Processor(_Total)\% Processor Time
# \Memory\Available MBytes
# \LogicalDisk(C:)\% Disk Time
# \Network Interface(*)\Bytes Total/sec

# Create data collector sets
# Add performance counters
# Schedule data collection
PowerShell Commands
# Real-time CPU monitoring
Get-Counter "\Processor(_Total)\% Processor Time" -Continuous

# Memory monitoring
Get-Counter "\Memory\Available MBytes" -Continuous
Get-Counter "\Memory\Pages/sec" -Continuous

# Disk monitoring
Get-Counter "\LogicalDisk(C:)\% Disk Time" -Continuous
Get-Counter "\LogicalDisk(C:)\Avg. Disk Queue Length" -Continuous

# Network monitoring
Get-Counter "\Network Interface(*)\Bytes Total/sec" -Continuous
Resource Monitor (resmon)
Usage & Features
# Launch Resource Monitor
resmon

# Key tabs:
# Overview: Summary of resource usage
# CPU: Process and service CPU usage
# Memory: Physical and virtual memory
# Disk: Disk activity per process
# Network: Network usage and connections

# Alternative launch methods:
# Task Manager → Performance → Open Resource Monitor
# Start Menu → Search "Resource Monitor"
Process Monitoring
# Process monitoring with PowerShell
Get-Process | Sort-Object CPU -Descending | Select-Object -First 5

Get-Process | Sort-Object WorkingSet -Descending | Select-Object -First 5

# Service monitoring
Get-Service | Where-Object {$_.Status -eq "Running"}

# Network connections
Get-NetTCPConnection | Where-Object {$_.State -eq "Established"}

# Disk usage
Get-WmiObject -Class Win32_LogicalDisk | Select-Object DeviceID, Size, FreeSpace

6. Network Performance Monitoring

Basic Network Tools
Bandwidth Monitoring
# Bandwidth monitoring
iftop -i eth0
nethogs eth0

# Network statistics
netstat -i # Interface statistics
netstat -s # Protocol statistics

# Modern alternative
ss -s # Socket statistics
ip -s link # Interface statistics
Advanced Network Monitoring
# Continuous network monitoring
sar -n DEV 1 0 # Continuous network stats

# TCP connection monitoring
netstat -tn | grep ESTABLISHED | wc -l
ss -t state established | wc -l

# Network latency and routing
traceroute google.com
mtr google.com

# Network interface details
ethtool eth0
ip addr show eth0
Real-time Network Monitoring Script
Automated Network Monitor
#!/bin/bash
# network_monitor.sh

INTERFACE="eth0"
LOG_FILE="/var/log/network_monitor.log"
ALERT_THRESHOLD=80 # Percentage

while true; do
  # Get network utilization
  RX_BYTES=$(cat /sys/class/net/$INTERFACE/statistics/rx_bytes)
  TX_BYTES=$(cat /sys/class/net/$INTERFACE/statistics/tx_bytes)
  
  sleep 1
  
  RX_BYTES_NEW=$(cat /sys/class/net/$INTERFACE/statistics/rx_bytes)
  TX_BYTES_NEW=$(cat /sys/class/net/$INTERFACE/statistics/tx_bytes)
  
  RX_RATE=$((($RX_BYTES_NEW - $RX_BYTES) / 1024)) # KB/s
  TX_RATE=$((($TX_BYTES_NEW - $TX_BYTES) / 1024)) # KB/s
  
  # Get interface speed
  SPEED=$(ethtool $INTERFACE 2>/dev/null | grep Speed | awk '{print $2}' | sed 's/Mb\/s//')
  
  if [ ! -z "$SPEED" ]; then
    MAX_RATE=$((($SPEED * 1024) / 8)) # Convert to KB/s
    UTILIZATION=$((($RX_RATE + $TX_RATE) * 100 / $MAX_RATE))
    
    if [ $UTILIZATION -gt $ALERT_THRESHOLD ]; then
      echo "$(date): High network utilization: $UTILIZATION%" >> $LOG_FILE
      echo "High network usage alert!" | mail -s "Network Alert" admin@company.com
    fi
  fi
  
  echo "$(date) - RX: ${RX_RATE}KB/s TX: ${TX_RATE}KB/s" >> $LOG_FILE
  sleep 5
done

7. Disk and Filesystem Monitoring

Disk Space Monitoring
Basic Disk Usage
# Basic disk usage
df -h # Human readable
df -i # Inode usage

# Detailed disk analysis
du -sh /var/* # Directory sizes
du -x --max-depth=1 / | sort -nr | head -10

# Find large files
find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null

# Monitor specific directory
du -sh /home /var /opt
I/O Performance Analysis
# I/O wait analysis
iostat -x 1

# Process-level I/O
iotop
pidstat -d 1

# Disk latency testing
hdparm -tT /dev/sda

# Real-time disk monitoring
watch -n 1 'iostat -x 1 1'

# Check disk health
smartctl -a /dev/sda
badblocks -v /dev/sda
Automated Disk Monitoring Script
Disk Space Alert System
#!/bin/bash
# disk_monitor.sh

THRESHOLD=85 # Percentage
LOG_FILE="/var/log/disk_monitor.log"
ALERT_EMAIL="admin@company.com"

# Check disk usage
df -h | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output; do
  usage=$(echo $output | awk '{ print $1}' | cut -d'%' -f1)
  partition=$(echo $output | awk '{ print $2 }')
  
  if [ $usage -ge $THRESHOLD ]; then
    echo "$(date): Disk usage alert: $partition - $usage%" >> $LOG_FILE
    echo "Warning: Disk usage on $partition is $usage%" | mail -s "Disk Space Alert" $ALERT_EMAIL
  fi
done

# Check inode usage
df -i | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output; do
  usage=$(echo $output | awk '{ print $1}' | cut -d'%' -f1)
  partition=$(echo $output | awk '{ print $2 }')
  
  if [ $usage -ge $THRESHOLD ]; then
    echo "$(date): Inode usage alert: $partition - $usage%" >> $LOG_FILE
    echo "Warning: Inode usage on $partition is $usage%" | mail -s "Inode Alert" $ALERT_EMAIL
  fi
done

8. Log-based Performance Monitoring

System Log Analysis
Performance-related Log Entries
# Performance-related log entries
grep -i "error\|warning\|critical" /var/log/syslog
grep -i "out of memory" /var/log/syslog
grep -i "disk full" /var/log/syslog

# Kernel messages
dmesg | grep -i memory
dmesg | grep -i disk
dmesg | grep -i error

# Application performance logs
tail -f /var/log/apache2/access.log | awk '{print $4, $7, $9}'
tail -f /var/log/mysql/error.log | grep -i performance
Custom Performance Logging
#!/bin/bash
# performance_logger.sh

LOG_FILE="/var/log/performance.log"

while true; do
  TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
  CPU=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}')
  MEM=$(free -m | awk 'NR==2{printf "%.2f%%", $3*100/$2}')
  DISK=$(df / | awk 'NR==2{printf $5}')
  LOAD=$(cat /proc/loadavg | awk '{print $1}')
  
  echo "$TIMESTAMP - CPU: $CPU, Memory: $MEM, Disk: $DISK, Load: $LOAD" >> $LOG_FILE
  sleep 60
done

# Add to crontab for automated monitoring
# * * * * * /path/to/performance_logger.sh
Performance Trend Analysis
Weekly Performance Report
#!/bin/bash
# weekly_performance_report.sh

REPORT_FILE="/var/log/weekly_performance_report.txt"
LOG_FILE="/var/log/performance.log"

{
  echo "=== WEEKLY PERFORMANCE REPORT ==="
  echo "Generated: $(date)"
  echo "=================================="
  echo ""
  
  # CPU Analysis
  echo "CPU USAGE SUMMARY:"
  grep "CPU:" $LOG_FILE | awk '{print $6}' | sort -n | \
    awk 'NR==1{min=$1} NR==END{max=$1} {sum+=$1} END{print "Min: "min"%, Max: "max"%, Avg: "sum/NR"%}"'
  echo ""
  
  # Memory Analysis
  echo "MEMORY USAGE SUMMARY:"
  grep "Memory:" $LOG_FILE | awk '{print $8}' | sed 's/%//' | \
    awk 'NR==1{min=$1} NR==END{max=$1} {sum+=$1} END{print "Min: "min"%, Max: "max"%, Avg: "sum/NR"%}"'
  echo ""
  
  # Load Average Analysis
  echo "LOAD AVERAGE SUMMARY:"
  grep "Load:" $LOG_FILE | awk '{print $10}' | \
    awk 'NR==1{min=$1} NR==END{max=$1} {sum+=$1} END{print "Min: "min", Max: "max", Avg: "sum/NR}'
  echo ""
  
  # Peak usage times
  echo "PEAK USAGE TIMES:"
  grep "CPU:" $LOG_FILE | sort -k6 -nr | head -5
  echo ""

} > $REPORT_FILE

# Send report via email
cat $REPORT_FILE | mail -s "Weekly Performance Report" admin@company.com

Ringkasan Pembelajaran

Pada pertemuan ini kita telah mempelajari pemantauan kinerja sistem yang komprehensif, termasuk tools, metrics, dan best practices untuk performance optimization.

Key Takeaways:
  • Pemahaman KPI dan performance metrics
  • Monitoring tools di Linux dan Windows
  • Network, disk, dan memory monitoring
  • Automated monitoring scripts
Next Topic Preview:

Pertemuan berikutnya: Penjadwalan Tugas Otomatis - automation dengan cron, systemd, dan task scheduler.