Unsaon Pag-monitor sa Apache Web Server Load ug Page Statistics


Niini nga artikulo, mahibal-an nimo kung giunsa ang pag-monitor sa load sa web server sa Apache ug mga hangyo gamit ang mod_status module sa imong mga distribusyon sa Linux sama sa CentOS, RHEL, ug Fedora.

Unsa ang mod_status?

Ang mod_status usa ka module sa Apache nga makatabang sa pagmonitor sa load sa web server ug kasamtangang mga koneksyon sa httpd nga adunay HTML interface nga ma-access pinaagi sa web browser.

Ang mod_status sa Apache nagpakita sa usa ka yano nga panid sa HTML nga adunay sulud nga kasayuran bahin sa karon nga estadistika sa webserver lakip na.

  • Total nga gidaghanon sa mga umaabot nga hangyo
  • Total nga gidaghanon sa byte ug counts server
  • Ang paggamit sa CPU sa Webserver
  • Server Load
  • Server Uptime
  • Total Trapiko
  • Total nga gidaghanon sa walay trabaho nga mga trabahante
  • Mga PID sa tagsa-tagsa ka kliyente ug daghan pa.

Ang default nga Apache Project nakapahimo sa ilang panid sa istatistika sa server sa publiko. Aron adunay demo sa panid sa status sa busy nga web site, bisitaha.

  • https://status.apache.org/

Gigamit namo ang mosunod nga Testing Environment para niining artikuloha aron masusi ang dugang bahin sa mod_status uban ang pipila ka praktikal nga mga pananglitan ug mga screen-shot.

  1. Sistema sa Operating – CentOS 8/7
  2. Aplikasyon – Apache Web Server
  3. IP Address – 5.175.142.66
  4. DocumentRoot – /var/www/html
  5. Payl sa Apache Configuration – /etc/httpd/conf/httpd.conf
  6. Default nga HTTP Port – 80 TCP
  7. Mga Setting sa Pag-configure sa Pagsulay – httpd -t

Ang mga kinahanglanon alang sa kini nga panudlo mao nga kinahanglan nimong mahibal-an kung giunsa ang pag-install ug pag-configure sa usa ka Basic Apache Server. Kung wala ka kahibalo kung giunsa ang pag-setup sa Apache, basaha ang mosunod nga artikulo nga makatabang kanimo sa pag-set up sa imong kaugalingon nga Apache Web Server.

  1. Paghimo sa Imong Kaugalingong Webserver ug Pag-host og Website sa Linux

Giunsa Pag-enable ang mod_status sa Apache

Ang default nga pag-install sa Apache adunay mod_status nga gipagana. Kung dili, siguroha nga mahimo kini sa Apache configuration file.

 vi /etc/httpd/conf/httpd.conf

Pangitaa ang pulong nga \mod_status o ipadayon ang pag-scroll paubos hangtod makakita ka og linya nga adunay sulod.

#LoadModule status_module modules/mod_status.so

Kung makakita ka og '#' nga karakter sa sinugdanan sa LoadModule, kana nagpasabot nga ang mod_status gi-disable. Kuhaa ang '#' aron mahimo ang mod_status.

LoadModule status_module modules/mod_status.so

Karon pangitaa pag-usab ang pulong nga \Lokasyon o i-scroll down hangtud makakita ka og seksyon para sa mod_status nga kinahanglan tan-awon sama sa mosunod.

# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
# Change the ".example.com" to match your domain to enable.
#
#<Location /server-status>
#    SetHandler server-status
#    Order deny,allow
#    Deny from all
#    Allow from .example.com
#</Location>

Sa ibabaw nga seksyon, uncomment ang mga linya alang sa Location directive, SetHandler, ug ang mga pagdili sa direktoryo sumala sa imong mga panginahanglan. Pananglitan, gitipigan nako kini nga yano sa Order Allow, ipanghimakak ug gitugotan kini sa tanan.

<Location /server-status>
   SetHandler server-status
   Order allow,deny
   Deny from all
   Allow from all 
</Location>

Note: Ang naa sa ibabaw nga configuration mao ang default configuration para sa default Apache web site (usa ka website). Kung nakamugna ka usa o daghan pa nga Apache Virtual Hosts, ang pag-configure sa ibabaw dili molihok.

Mao nga, sa panguna, kinahanglan nimo nga ipasabut ang parehas nga pagsumpo alang sa matag virtual host alang sa bisan unsang mga domain nga imong gi-configure sa Apache. Pananglitan, ang virtual host configuration alang sa mod_status mahimong sama niini.

<VirtualHost *:80>
    ServerAdmin [email 
    DocumentRoot /var/www/html/example.com
    ServerName example.com
    ErrorLog logs/example.com-error_log
    CustomLog logs/example.com-access_log common
<Location /server-status>
   SetHandler server-status
   Order allow,deny
   Deny from all
   Allow from example.com 
</Location>
</VirtualHost>

Ang mga setting sa “ExtendedStatus” makadugang ug dugang impormasyon sa pahina sa estadistika sama sa paggamit sa CPU, hangyo kada segundo, kinatibuk-ang trapiko, ug uban pa. Aron mahimo kini, i-edit ang samang httpd.conf file ug pangitaa ang pulong nga \Extended ug Uncomment ang linya ug ibutang ang status \On para sa ExtendedStatus direktiba.

# ExtendedStatus controls whether Apache will generate "full" status
# information (ExtendedStatus On) or just basic information (ExtendedStatus
# Off) when the "server-status" handler is called. The default is Off.
#
ExtendedStatus On

Karon siguruha nga husto nimo nga gipagana ug gi-configure ang panid sa status sa server sa Apache. Mahimo usab nimo nga susihon ang mga sayup sa httpd.conf configuration gamit ang mosunod nga sugo.

 httpd -t

Syntax OK

Sa higayon nga, makuha nimo ang syntax OK ra, mahimo nimong i-restart ang serbisyo sa httpd.

 service httpd restart
OR
 systemctl restart httpd
Stopping httpd:                                          [  OK  ]
Starting httpd:                                          [  OK  ]

Ang Apache status page mahimong ma-access pinaagi sa imong domain name nga adunay/server-status sa mosunod nga URL.

http://serveripaddress/server-status

OR

http://serev-hostname/server-status

Makita nimo ang usa ka butang nga susama sa mosunod nga panid nga adunay ExtendedStatus nga gipagana.

Sa snapshot sa ibabaw, imong makita nga ang usa ka HTML interface, nga nagpakita sa tanang impormasyon mahitungod sa server uptime, proseso Id uban sa iyang tagsa-tagsa nga kliyente, ang panid nga ilang gisulayan nga ma-access.

Gipakita usab niini ang kahulugan ug paggamit sa tanan nga mga abbreviation nga gigamit aron ipakita ang kahimtang nga makatabang kanato nga mas masabtan ang sitwasyon.

Mahimo usab nimo nga i-refresh ang panid matag segundos (isulti ang 5 segundos) aron makita ang na-update nga estadistika. Aron mabutang ang awtomatik nga pag-refresh, palihug idugang ang ?refresh=N sa katapusan sa URL. Diin ang N mahimong pulihan sa gidaghanon sa mga segundo nga gusto nimo nga ma-refresh ang imong panid.

http://serveripaddress/server-status/?refresh=5

Mahimo usab nimo nga tan-awon ang Apache status page gikan sa command-line interface gamit ang espesyal nga command-line browsers nga gitawag og links o lynx. Mahimo nimo kining i-install gamit ang default package manager utility nga gitawag og yum sama sa gipakita sa ubos.

# yum install links

OR

# yum install lynx

Sa higayon nga, imong na-install ang, mahimo nimong makuha ang parehas nga estadistika sa imong terminal pinaagi sa paggamit sa mosunud nga mando.

 links http://serveripaddress/server-status
OR
 lynx http://serveripaddress/server-status
OR
  /etc/init.d/httpd fullstatus
                     Apache Server Status for localhost
   Server Version: Apache/2.2.15 (Unix) DAV/2 PHP/5.3.3
   Server Built: Aug 13 2013 17:29:28

   --------------------------------------------------------------------------
   Current Time: Tuesday, 14-Jan-2014 04:34:13 EST
   Restart Time: Tuesday, 14-Jan-2014 00:33:05 EST
   Parent Server Generation: 0
   Server uptime: 4 hours 1 minute 7 seconds
   Total accesses: 2748 - Total Traffic: 9.6 MB
   CPU Usage: u.9 s1.06 cu0 cs0 - .0135% CPU load
   .19 requests/sec - 695 B/second - 3658 B/request
   1 requests currently being processed, 4 idle workers
 .__.__W...

   Scoreboard Key:
   "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
   "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
   "C" Closing connection, "L" Logging, "G" Gracefully finishing,
   "I" Idle cleanup of a worker, "." Open slot with no current process

Srv PID     Acc    M CPU   SS  Req Conn Child Slot     Client        VHost             Request
0-0 -    0/0/428   . 0.30 5572 0   0.0  0.00  1.34 127.0.0.1      5.175.142.66 OPTIONS * HTTP/1.0
                                                                               GET
1-0 5606 0/639/639 _ 0.46 4    0   0.0  2.18  2.18 115.113.134.14 5.175.142.66 /server-status?refresh=5
                                                                               HTTP/1.1
                                                                               GET
2-0 5607 0/603/603 _ 0.43 0    0   0.0  2.09  2.09 115.113.134.14 5.175.142.66 /server-status?refresh=5
                                                                               HTTP/1.1
3-0 -    0/0/337   . 0.23 5573 0   0.0  0.00  1.09 127.0.0.1      5.175.142.66 OPTIONS * HTTP/1.0
                                                                               GET
4-0 5701 0/317/317 _ 0.23 9    0   0.0  1.21  1.21 115.113.134.14 5.175.142.66 /server-status?refresh=5
                                                                               HTTP/1.1
                                                                               GET
5-0 5708 0/212/213 _ 0.15 6    0   0.0  0.85  0.85 115.113.134.14 5.175.142.66 /server-status?refresh=5
                                                                               HTTP/1.1
6-0 5709 0/210/210 W 0.16 0    0   0.0  0.84  0.84 127.0.0.1      5.175.142.66 GET /server-status
                                                                               HTTP/1.1
7-0 -    0/0/1     . 0.00 5574 0   0.0  0.00  0.00 127.0.0.1      5.175.142.66 OPTIONS * HTTP/1.0

   --------------------------------------------------------------------------

    Srv  Child Server number - generation
    PID  OS process ID
    Acc  Number of accesses this connection / this child / this slot
     M   Mode of operation
    CPU  CPU usage, number of seconds
    SS   Seconds since the beginning of the most recent request
    Req  Milliseconds required to process most recent request
   Conn  Kilobytes transferred this connection
   Child Megabytes transferred this child
   Slot  Total megabytes transferred this slot
   --------------------------------------------------------------------------

    Apache/2.2.15 (CentOS) Server at localhost Port 80

Konklusyon

Ang mod_status module sa Apache usa ka magamit kaayo nga himan sa pag-monitor alang sa pag-monitor sa pasundayag sa kalihokan sa usa ka web server ug makahimo sa pagpasiugda sa mga problema mismo. Para sa dugang nga impormasyon basaha ang status page nga makatabang kanimo nga mahimong mas malampusong web server administrator.

  1. Apache mod_status Panidlay

Kana lang alang sa mod_status sa pagkakaron, maghimo kami og pipila pa nga mga limbong ug mga tip sa Apache sa umaabot nga mga panudlo. Hangtud unya magpabilin nga Geeky ug tune sa linux-console.net ug ayaw kalimot sa pagdugang sa imong bililhong mga komento.