Friday, 13 August 2021

Dashboard Monitoring Apache Server, php-fpm & MySQL

 mod_status

/etc/apache2/sites-available/status.conf

Listen 8181

<VirtualHost *:8181>

    ServerName my-domain-name.id

    ErrorLog /var/log/apache2/status_error.log

    CustomLog /var/log/apache2/status_access.log common

    <Location /server-status>

        SetHandler server-status

        Require all granted

    </Location>

</VirtualHost>

apache Exporter untuk Prometheus

 /etc/systemd/system/apache_exporter.service


[Unit]

Description=Prometheus

Documentation=https://github.com/Lusitaniae/apache_exporter

Wants=network-online.target

After=network-online.target


[Service]

Type=simple

User=prometheus

Group=prometheus

ExecReload=/bin/kill -HUP $MAINPID

ExecStart=/usr/local/bin/apache_exporter \

  --insecure \

  --scrape_uri=http://localhost:8181/server-status/?auto \

  --telemetry.address=0.0.0.0:9117 \

  --telemetry.endpoint=/metrics


SyslogIdentifier=apache_exporter

Restart=always


[Install]

WantedBy=multi-user.target

php-fpm Exporter untuk Prometheus

/etc/php/7.2/fpm/pool.d/www.conf

pm.status_path = /status-phpfpm72

sudo apt install golang-go

git clone https://github.com/Lusitaniae/phpfpm_exporter.git

cd phpfpm_exporter

make build

/etc/systemd/system/php-fpm_exporter.service

[Unit]

Description = PHP-FPM Prometheus Exporter

Documentation=https://github.com/Lusitaniae/phpfpm_exporter

Wants=network-online.target

After=network-online.target


[Service]

ExecReload=/bin/kill -HUP $MAINPID

SyslogIdentifier = phpfpm_exporter

ExecStart = /opt/phpfpm_exporter/phpfpm_exporter \

   --phpfpm.socket-paths /var/run/php/php7.2-fpm.sock \

   --phpfpm.status-path="/status-phpfpm72"

   --phpfpm.script-collector-paths /usr/local/bin/php_exporter/phpfpm_opcache_exporter.php


[Install]

WantedBy = multi-user.target

systemctl daemon-reload

systemctl enable --now php-fpm_exporter

systemctl status php-fpm_exporter

MySQL

[9][10]. Untuk Grafana dashboard, dapat menggunakan id 6239

Prometheus

Install dan mengamankan prometheus yang secara default dapat diakses tanpa password di port 9090, baca [6].

/etc/prometheus/prometheus.yml

# my global config

global:

  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.

  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.

  # scrape_timeout is set to the global default (10s).


# Alertmanager configuration

alerting:

  alertmanagers:

    - static_configs:

        - targets:

          # - alertmanager:9093


# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.

rule_files:

  # - "first_rules.yml"

  # - "second_rules.yml"


# A scrape configuration containing exactly one endpoint to scrape:

# Here it's Prometheus itself.

scrape_configs:

  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.

  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'

    # scheme defaults to 'http'.

    static_configs:

      - targets: ["localhost:9090"]

  # Apache Servers

  - job_name: "apache"

    static_configs:

      - targets: ["localhost:9117"]

  # php-fpm

  - job_name: "php-fpm7.2"

    static_configs:

      - targets: ["localhost:9253"]

Referensi

  1. Apache Exporter for Prometheus, https://github.com/Lusitaniae/apache_exporter
  2. Install Prometheus on Debian 10, https://kifarunix.com/install-prometheus-on-debian-10/
  3. Monitor Apache Web Server with Prometheus and Grafana in 5 minutes, https://computingforgeeks.com/how-to-monitor-apache-web-server-with-prometheus-and-grafana-in-5-minutes/
  4. Grafana support for prometheus, https://prometheus.io/docs/visualization/grafana/
  5. PHP-FPM Exporter for Prometheus, https://github.com/Lusitaniae/phpfpm_exporter
  6. Securing Prometheus API and UI endpoints using basic auth, https://prometheus.io/docs/guides/basic-auth/
  7. Real-time PHP-FPM Status, https://gist.github.com/Jiab77/a9428050ab9bb3f17c5e33343da94fd8
  8. Prometheus Server and TLS, https://inuits.eu/blog/prometheus-server-tls/
  9. How to Monitor MySQL Deployments with Prometheus & Grafana at ScaleGrid, https://scalegrid.io/blog/how-to-monitor-mysql-deployments-with-prometheus-and-grafana-at-scalegrid/
  10. MySQL Server Exporter, https://github.com/prometheus/mysqld_exporter

Composer : A Dependency Manager for PHP

 ...

Referensi

  1. Composer : A Dependency Manager for PHP, https://getcomposer.org
  2. Introducing graph visualization of composer package dependencies, https://clue.engineering/2020/introducing-graph-composer

Sunday, 28 March 2021

phpDocumentor

Agar classes graph dapat digenerate tambahkan opsi : --setting=graphs.enabled=true lalu jangan lupa install graphviz dan plantuml.

Tuesday, 15 September 2020

php-fpm Tuning

Target 1000 concurrent users untuk TAO

CPU 


CPU 10 core

$ cat /proc/cpuinfo | grep "model name"

model name : Intel(R) Xeon(R) Gold 5115 CPU @ 2.40GHz
model name : Intel(R) Xeon(R) Gold 5115 CPU @ 2.40GHz
model name : Intel(R) Xeon(R) Gold 5115 CPU @ 2.40GHz
model name : Intel(R) Xeon(R) Gold 5115 CPU @ 2.40GHz
model name : Intel(R) Xeon(R) Gold 5115 CPU @ 2.40GHz
model name : Intel(R) Xeon(R) Gold 5115 CPU @ 2.40GHz
model name : Intel(R) Xeon(R) Gold 5115 CPU @ 2.40GHz
model name : Intel(R) Xeon(R) Gold 5115 CPU @ 2.40GHz
model name : Intel(R) Xeon(R) Gold 5115 CPU @ 2.40GHz
model name : Intel(R) Xeon(R) Gold 5115 CPU @ 2.40GHz

Memory 

$free -g
              total        used        free      shared  buff/cache   available
Mem:             16           0          14           0           1          15
Swap:             0           0           0

Tuning

MySQL menggunakan konfigurasi seperti di jelaskan ... disini ..., Ketika concurent user 16 s.d 27, ke website utama, bukan TAO, MySQL memakan memory kurang lebih 800M s.d 900M.

Untuk mengetahui concurrent user, jalankan perintah : 

 $ netstat -plan | grep :80 | wc -l
 $ netstat -plan | grep :443 | wc -l


Terkadang, tiba-tiba server seperti hang tidak bisa menerima request sama sekali, menurut diskusi [7], solusi yg bisa dicoba mengubah kongurasi php-fpm.conf

emergency_restart_threshold=3

emergency_restart_interval=1m

process_control_timeout=5s

Referensi

  1. PHP-FPM Process Calculator, https://spot13.com/pmcalculator/
  2. Optimizing PHP-FPM for High Performance,  https://geekflare.com/php-fpm-optimization/
  3. Performance enhacements for Apache and PHP, https://blog.bitnami.com/2014/06/performance-enhacements-for-apache-and.html
  4. Optimizing PHP Application Concurrency, https://devcenter.heroku.com/articles/php-concurrency
  5. PHP-FPM tuning for high load – The Best practices!, https://bobcares.com/blog/php-fpm-tuning-high-load/
  6. Moodle performance - examples of configurations, https://moodle.org/mod/forum/discuss.php?d=395623
  7. Optimizing NGINX and PHP-fpm for high traffic sites, http://www.softwareprojects.com/resources/programming/t-optimizing-nginx-and-php-fpm-for-high-traffic-sites-2081.html
  8. Constantly have to reload PHP-FPM, https://serverfault.com/questions/575457/constantly-have-to-reload-php-fpm
  9. Apache2 and php fpm performance optimization — Step-by-step guide, https://medium.com/@sbuckpesch/apache2-and-php-fpm-performance-optimization-step-by-step-guide-1bfecf161534
  10. What Are The Best PHP Accelerators?, https://wp-rocket.me/blog/best-php-accelerators/
  11. How to Enable and Monitor PHP-FPM Status in Nginx, https://www.tecmint.com/enable-monitor-php-fpm-status-in-nginx/