Add guide: LAMP stack monitoring (#10698)
* Start work on LAMP guide * Init guide * Finish initial draft * Add one more key metric * A few copyedits * Update GA url * Additions for Odysseas * Add mention of response option
Joel Hans committed
Mar 5, 2021 at 09:04 UTC
18412574fadb6e52d8819da2b797a66b79395d3d
2 files changed
+252
-2
docs/get/README.md
+3
-2
@@ -38,7 +38,8 @@ from its source code.
38
39
Copy the script, paste it into your node's terminal, and hit `Enter`.
40
41
-Open your favorite browser and navigate to `http://localhost:19999` or `http://REMOTE-HOST:19999` to open the dashboard.
41
+Open your favorite browser and navigate to `http://localhost:19999` or `http://NODE:19999`, replacing `NODE` with the
42
+hostname or IP address of your system, to open the local Agent dashboard.
43
44
<details>
45
<summary>Watch how the one-line installer works</summary>
@@ -91,7 +92,7 @@ platform to see specific instructions.
92
93
Even more options available in our [packaging documentation](/packaging/installer/README.md#alternative-methods).
94
94
-## Claim your node on Netdata Cloud
95
+## Claim your node to Netdata Cloud
96
97
You need to [claim](/claim/README.md) your nodes to see them in Netdata Cloud. Claiming establishes a secure TLS
98
connection to Netdata Cloud using the [Agent-Cloud link](/aclk/README.md), and proves you have write and administrative
docs/guides/monitor/lamp-stack.md
new
+249
@@ -0,0 +1,249 @@
1
+<!--
2
+title: "LAMP stack monitoring (Linux, Apache, MySQL, PHP) with Netdata"
3
+description: "Set up robust LAMP stack monitoring (Linux, Apache, MySQL, PHP) in just a few minutes using a free, open-source monitoring tool that collects metrics every second."
4
+image: /img/seo/guides/monitor/lamp-stack.png
5
+author: "Joel Hans"
6
+author_title: "Editorial Director, Technical & Educational Resources"
7
+author_img: "/img/authors/joel-hans.jpg"
8
+custom_edit_url: https://github.com/netdata/netdata/edit/master/docs/guides/monitor/lamp-stack.md
9
+-->
10
+
11
+# LAMP stack monitoring (Linux, Apache, MySQL, PHP) with Netdata
12
+
13
+The LAMP stack is the "hello world" for deploying dynamic web applications. It's fast, flexible, and reliable, which
14
+means a developer or sysadmin won't go far in their career without interacting with the stack and its services.
15
+
16
+_LAMP_ is an acronym of the core services that make up the web application: **L**inux, **A**pache, **M**ySQL, and
17
+**P**HP.
18
+
19
+- [Linux](https://en.wikipedia.org/wiki/Linux) is the operating system running the whole stack.
20
+- [Apache](https://httpd.apache.org/) is a web server that responds to HTTP requests from users and returns web pages.
21
+- [MySQL](https://www.mysql.com/) is a database that stores and returns information based on queries from the web
22
+ application.
23
+- [PHP](https://www.php.net/) is a scripting language used to query the MySQL database and build new pages.
24
+
25
+LAMP stacks are the foundation for tons of end-user applications, with [Wordpress](https://wordpress.org/) being the
26
+most popular.
27
+
28
+## Challenge
29
+
30
+You've already deployed a LAMP stack, either in testing or production. You want to monitor every service's performance
31
+and availability to ensure the best possible experience for your end-users. You might also be particularly interested in
32
+using a free, open-source monitoring tool.
33
+
34
+Depending on your monitoring experience, you may not even know what metrics you're looking for, much less how to build
35
+dashboards using a query language. You need a robust monitoring experience that has the metrics you need without a ton
36
+of required setup.
37
+
38
+## Solution
39
+
40
+In this tutorial, you'll set up robust LAMP stack monitoring with Netdata in just a few minutes. When you're done,
41
+you'll have one dashboard to monitor every part of your web application, including each essential LAMP stack service.
42
+
43
+This dashboard updates every second with new metrics, and pairs those metrics up with preconfigured alarms to keep you
44
+informed of any errors or odd behavior.
45
+
46
+## What you need to get started
47
+
48
+To follow this tutorial, you need:
49
+
50
+- A physical or virtual Linux system, which we'll call a _node_.
51
+- A functional LAMP stack. There's plenty of tutorials for installing a LAMP stack, like [this
52
+ one](https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-ubuntu-18-04)
53
+ from Digital Ocean.
54
+- Optionally, a [Netdata Cloud](https://app.netdata.cloud/sign-up?cloudRoute=/spaces) account, which you can use to view
55
+ metrics from multiple nodes in one dashboard, and a whole lot more, for free.
56
+
57
+## Install the Netdata Agent
58
+
59
+If you don't have the free, open-source [Netdata Agent](/docs/get/README.md) installed on your node yet, get started
60
+with a [single kickstart command](/packaging/installer/methods/kickstart.md):
61
+
62
+```bash
63
+bash <(curl -Ss https://my-netdata.io/kickstart.sh)
64
+```
65
+
66
+The Netdata Agent is now collecting metrics from your node every second. You don't need to jump into the dashboard yet,
67
+but if you're curious, open your favorite browser and navigate to `http://localhost:19999` or `http://NODE:19999`,
68
+replacing `NODE` with the hostname or IP address of your system.
69
+
70
+## Enable hardware and Linux system monitoring
71
+
72
+There's nothing you need to do to enable [system monitoring](/docs/collect/system-metrics.md) and Linux monitoring with
73
+the Netdata Agent, which autodetects metrics from CPUs, memory, disks, networking devices, and Linux processes like
74
+systemd without any configuration. If you're using containers, Netdata automatically collects resource utilization
75
+metrics from each using the [cgroups data collector](/collectors/cgroups.plugin/README.md).
76
+
77
+## Enable Apache monitoring
78
+
79
+Let's begin by configuring Apache to work with Netdata's [Apache data
80
+collector](https://learn.netdata.cloud/docs/agent/collectors/go.d.plugin/modules/apache).
81
+
82
+Actually, there's nothing for you to do to enable Apache monitoring with Netdata.
83
+
84
+Apache comes with `mod_status` enabled by default these days, and Netdata is smart enough to look for metrics at that
85
+endpoint without you configuring it. Netdata is already collecting [`mod_status`
86
+metrics](https://httpd.apache.org/docs/2.4/mod/mod_status.html), which is just _part_ of your web server monitoring.
87
+
88
+## Enable web log monitoring
89
+
90
+The Netdata Agent also comes with a [web log
91
+collector](https://learn.netdata.cloud/docs/agent/collectors/go.d.plugin/modules/weblog), which reads Apache's access
92
+log file, procesess each line, and converts them into per-second metrics. On Debian systems, it reads the file at
93
+`/var/log/apache2/access.log`.
94
+
95
+At installation, the Netdata Agent adds itself to the [`adm`
96
+group](https://wiki.debian.org/SystemGroups#Groups_without_an_associated_user), which gives the `netdata` process the
97
+right privileges to read Apache's log files. In other words, you don't need to do anything to enable Apache web log
98
+monitoring.
99
+
100
+## Enable MySQL monitoring
101
+
102
+Because your MySQL database is password-protected, you do need to tell MySQL to allow the `netdata` user to connect to
103
+without a password. Netdata's [MySQL data
104
+collector](https://learn.netdata.cloud/docs/agent/collectors/go.d.plugin/modules/mysql) collects metrics in _read-only_
105
+mode, without being able to alter or affect operations in any way.
106
+
107
+First, log into the MySQL shell. Then, run the following three commands, one at a time:
108
+
109
+```mysql
110
+CREATE USER 'netdata'@'localhost';
111
+GRANT USAGE, REPLICATION CLIENT, PROCESS ON *.* TO 'netdata'@'localhost';
112
+FLUSH PRIVILEGES;
113
+```
114
+
115
+Run `sudo systemctl restart netdata`, or the [appropriate alternative for your
116
+system](/docs/configure/start-stop-restart.md), to collect dozens of metrics every second for robust MySQL monitoring.
117
+
118
+## Enable PHP monitoring
119
+
120
+Unlike Apache or MySQL, PHP isn't a service that you can monitor directly, unless you instrument a PHP-based application
121
+with [StatsD](/collectors/statsd.plugin/README.md).
122
+
123
+However, if you use [PHP-FPM](https://php-fpm.org/) in your LAMP stack, you can monitor that process with our [PHP-FPM
124
+data collector](https://learn.netdata.cloud/docs/agent/collectors/go.d.plugin/modules/phpfpm).
125
+
126
+Open your PHP-FPM configuration for editing, replacing `7.4` with your version of PHP:
127
+
128
+```bash
129
+sudo nano /etc/php/7.4/fpm/pool.d/www.conf
130
+```
131
+
132
+> Not sure what version of PHP you're using? Run `php -v`.
133
+
134
+Find the line that reads `;pm.status_path = /status` and remove the `;` so it looks like this:
135
+
136
+```conf
137
+pm.status_path = /status
138
+```
139
+
140
+Next, add a new `/status` endpoint to Apache. Open the Apache configuration file you're using for your LAMP stack.
141
+
142
+```bash
143
+sudo nano /etc/apache2/sites-available/your_lamp_stack.conf
144
+```
145
+
146
+Add the following to the end of the file, again replacing `7.4` with your version of PHP:
147
+
148
+```apache
149
+ProxyPass "/status" "unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
150
+```
151
+
152
+Save and close the file. Finally, restart the PHP-FPM, Apache, and Netdata processes.
153
+
154
+```bash
155
+sudo systemctl restart php7.4-fpm.service
156
+sudo systemctl restart apache2
157
+sudo systemctl restart netdata
158
+```
159
+
160
+As the Netdata Agent starts up again, it automatically connects to the new `127.0.0.1/status` page and collects
161
+per-second PHP-FPM metrics to get you started with PHP monitoring.
162
+
163
+## View LAMP stack metrics
164
+
165
+If the Netdata Agent isn't already open in your browser, open a new tab and navigate to `http://localhost:19999` or
166
+`http://NODE:19999`, replacing `NODE` with the hostname or IP address of your system.
167
+
168
+> If you [signed up](https://app.netdata.cloud/sign-up?cloudRoute=/spaces) for Netdata Cloud earlier, you can also view
169
+> the exact same LAMP stack metrics there, plus additional features, like drag-and-drop custom dashboards. Be sure to
170
+> [claim your node](/docs/get/README.md#claim-your-node-to-netdata-cloud) to start streaming metrics to your browser
171
+> through Netdata Cloud.
172
+
173
+Netdata automatically organizes all metrics and charts onto a single page for easy navigation. Peek at gauges to see
174
+overall system performance, then scroll down to see more. Click-and-drag with your mouse to pan _all_ charts back and
175
+forth through different time intervals, or hold `SHIFT` and use the scrollwheel (or two-finger scroll) to zoom in and
176
+out. Check out our doc on [interacting with charts](/docs/visualize/interact-dashboards-charts.md) for all the details.
177
+
178
+
180
+
181
+The **System Overview** section, which you can also see in the right-hand menu, contains key hardware monitoring charts,
182
+including CPU utilization, memory page faults, network monitoring, and much more. The **Applications** section shows you
183
+exactly which Linux processes are using the most system resources.
184
+
185
+Next, let's check out LAMP-specific metrics. You should see four relevant sections: **Apache local**, **MySQL local**,
186
+**PHP-FPM local**, and **web log apache**. Click on any of these to see metrics from each service in your LAMP stack.
187
+
188
+
190
+
191
+### Key LAMP stack monitoring charts
192
+
193
+Here's a quick reference for what charts you might want to focus on after setting up Netdata.
194
+
195
+| Chart name / context | Type | Why? |
196
+|-------------------------------------------------------|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
197
+| System Load Average (`system.load`) | Hardware monitoring | A good baseline load average is `0.7`, while `1` (on a 1-core system, `2` on a 2-core system, and so on) means resources are "perfectly" utilized. Higher load indicates a bottleneck somewhere in your system. |
198
+| System RAM (`system.ram`) | Hardware monitoring | Look at the `free` dimension. If that drops to `0`, your system will use swap memory and slow down. |
199
+| Uptime (`apache_local.uptime`) | Apache monitoring | This chart should always be "climbing," indicating a continuous uptime. Investigate any drops back to `0`. |
200
+| Requests By Type (`web_log_apache.requests_by_type`) | Apache monitoring | Check for increases in the `error` or `bad` dimensions, which could indicate users arriving at broken pages or PHP returning errors. |
201
+| Queries (`mysql_local.queries`) | MySQL monitoring | Queries is the total number of queries (queries per second, QPS). Check this chart for sudden spikes or drops, which indicate either increases in traffic/demand or bottlenecks in hardware performance. |
202
+| Active Connections (`mysql_local.connections_active`) | MySQL monitoring | If the `active` dimension nears the `limit`, your MySQL database will bottleneck responses. |
203
+| Performance (phpfpm_local.performance) | PHP monitoring | The `slow requests` dimension lets you know if any requests exceed the configured `request_slowlog_timeout`. If so, users might be having a less-than-ideal experience. |
204
+
205
+## Get alarms for LAMP stack errors
206
+
207
+The Netdata Agent comes with hundreds of pre-configured alarms to help you keep tabs on your system, including 19 alarms
208
+designed for smarter LAMP stack monitoring.
209
+
210
+Click the 🔔 icon in the top navigation to [see active alarms](/docs/monitor/view-active-alarms.md). The **Active** tabs
211
+shows any alarms currently triggered, while the **All** tab displays a list of _every_ pre-configured alarm. The
212
+
213
+
215
+
216
+[Tweak alarms](/docs/monitor/configure-alarms.md) based on your infrastructure monitoring needs, and to see these alarms
217
+in other places, like your inbox or a Slack channel, [enable a notification
218
+method](/docs/monitor/enable-notifications.md).
219
+
220
+## What's next?
221
+
222
+You've now set up robust monitoring for your entire LAMP stack: Linux, Apache, MySQL, and PHP (-FPM, to be exact). These
223
+metrics will help you keep tabs on the performance and availability of your web application and all its essential
224
+services. The per-second metrics granularity means you have the most accurate information possible for troubleshooting
225
+any LAMP-related issues.
226
+
227
+Another powerful way to monitor the availability of a LAMP stack is the [`httpcheck`
228
+collector](https://learn.netdata.cloud/docs/agent/collectors/go.d.plugin/modules/httpcheck), which pings a web server at
229
+a regular interval and tells you whether if and how quickly it's responding. The `response_match` option also lets you
230
+monitor when the web server's response isn't what you expect it to be, which might happen if PHP-FPM crashes, for
231
+example.
232
+
233
+The best way to use the `httpcheck` collector is from a separate node from the one running your LAMP stack, which is why
234
+we're not covering it here, but it _does_ work in a single-node setup. Just don't expect it to tell you if your whole
235
+node crashed.
236
+
237
+If you're planning on managing more than one node, or want to take advantage of advanced features, like finding the
238
+source of issues faster with [Metric Correlations](https://learn.netdata.cloud/docs/cloud/insights/metric-correlations),
239
+[sign up](https://app.netdata.cloud/sign-up?cloudRoute=/spaces) for a free Netdata Cloud account.
240
+
241
+### Related reference documentation
242
+
243
+- [Netdata Agent · Get Netdata](/docs/get/README.md)
244
+- [Netdata Agent · Apache data collector](https://learn.netdata.cloud/docs/agent/collectors/go.d.plugin/modules/apache)
245
+- [Netdata Agent · Web log collector](https://learn.netdata.cloud/docs/agent/collectors/go.d.plugin/modules/weblog)
246
+- [Netdata Agent · MySQL data collector](https://learn.netdata.cloud/docs/agent/collectors/go.d.plugin/modules/mysql)
247
+- [Netdata Agent · PHP-FPM data collector](https://learn.netdata.cloud/docs/agent/collectors/go.d.plugin/modules/phpfpm)
248
+
249
+[](<>)
\ No newline at end of file