{"id":2814,"date":"2015-12-23T00:46:57","date_gmt":"2015-12-23T00:46:57","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=2814"},"modified":"2015-12-23T00:46:57","modified_gmt":"2015-12-23T00:46:57","slug":"monitoring-a-wordpress-site-with-filebeat","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/monitoring-a-wordpress-site-with-filebeat\/","title":{"rendered":"Monitoring a WordPress site with Filebeat"},"content":{"rendered":"<p>In a previous post, I discuss <a href=\"\/\/www.garysieling.com\/blog\/installing-the-elk-stack-on-azure \">setting up the ELK stack on Azure<\/a>, which is a prerequisite for using Logbat.<\/p>\n<p>To pump logs from a linux server to , we can use a tool called Filebeat<sup><a href=\"#footnote_0_2814\" id=\"identifier_0_2814\" class=\"footnote-link footnote-identifier-link\" title=\"https:\/\/www.elastic.co\/guide\/en\/beats\/filebeat\/current\/filebeat-getting-started.html\">1<\/a><\/sup> (not sure where that fits in &#8220;ELK&#8221;?)<\/p>\n<p>On the server you want monitored, you&#8217;ll need to download the appropriate distribution<sup><a href=\"#footnote_1_2814\" id=\"identifier_1_2814\" class=\"footnote-link footnote-identifier-link\" title=\"https:\/\/www.elastic.co\/downloads\/beats\/filebeat\">2<\/a><\/sup> for your server version (Supports Windows or Linux)<\/p>\n<p>For instance, for me this was:<\/p>\n<pre lang=\"bash\">\ncurl -L -O https:\/\/download.elastic.co\/beats\/filebeat\/filebeat_1.0.1_i386.deb\n\nsudo dpkg -i filebeat_1.0.1_i386.deb\n<\/pre>\n<p>Then, we need to change a couple settings in the filebeat configuration: the host name we&#8217;re shipping logs to, and the index name &#8211; depending on what you set the pattern to when you installed Kibana. For me, this meant adding this setting: &#8216;index: &#8220;logstash&#8221;&#8216;<\/p>\n<pre lang=\"bash\">\nsudo vi \/etc\/filebeat\/filebeat.yml\n<\/pre>\n<p>Then, you can start the service:<\/p>\n<pre lang=\"bash\">\nsudo \/etc\/init.d\/filebeat start\n<\/pre>\n<p>If you want to see logs for this, by default they go to syslogd:<\/p>\n<pre lang=\"bash\">\nsudo tail -f \/var\/log\/syslog\n<\/pre>\n<p>However, up to this point, Filebeat still can&#8217;t connect, because it writes directly to Elastic Search, so you&#8217;ll have to open up another port through the Azure firewall &#8211; lets make this 8080. The Azure UI lets you filter by CIDR ranges, but only down to a \/32- in other words, you can&#8217;t filter only to the specific IPs of your other servers (a \/256), which adds an additional problem we&#8217;ll solve below.<\/p>\n<p>Fronting these servers with Nginx seems to be quite popular, so we&#8217;ll do that, back on our Elastic Search Server:<\/p>\n<pre lang=\"bash\">\napt-get install nginx\n<\/pre>\n<p>Edit the nginx config file:<\/p>\n<pre lang=\"bash\">\nvi \/etc\/nginx\/nginx.conf\n<\/pre>\n<p>In the &#8220;http&#8221; block, add a proxy server:<\/p>\n<pre lang=\"javascript\">\nserver {\n  listen 8080;\n  allow 173.255.224.150;\n  location \/ {\n    proxy_pass http:\/\/localhost:9200;\n  }\n}\n<\/pre>\n<p>Obviously you should change the IP &#8211; this lets you restrict who can write logs. Filebeat also claims to support Basic Auth, although I haven&#8217;t tried it. I notice in the forums, that there is discussion about adding more robust security options (e.g. Kerberos), but for now, most people are using whatever Nginx offers.<\/p>\n<p>You should also set up SSL, but this is sufficient for testing purposes.<\/p>\n<p>From the remote server, you should be able to test connectivity:<\/p>\n<pre lang=\"bash\">\ncurl http:\/\/elk-me3u257f.cloudapp.net:8080\n<\/pre>\n<p>Which will give you this:<\/p>\n<pre lang=\"Javascript\">\n{\n  \"name\" : \"Phantom Eagle\",\n  \"cluster_name\" : \"elasticsearch\",\n  \"version\" : {\n    \"number\" : \"2.1.1\",\n    \"build_hash\" : \"40e2c53a6b6c2972b3d13846e450e66f4375bd71\",\n    \"build_timestamp\" : \"2015-12-15T13:05:55Z\",\n    \"build_snapshot\" : false,\n    \"lucene_version\" : \"5.3.1\"\n  },\n  \"tagline\" : \"You Know, for Search\"\n}\n<\/pre>\n<p>In order for Filebeat to continue, it will also need to upload some information about the structure of it&#8217;s logs in advance- run this from the server to be logged:<\/p>\n<pre lang=\"bash\">\ncurl -XPUT 'http:\/\/elk-me3u257f.cloudapp.net:8080\/_template\/filebeat?pretty' \\\n  -d@\/etc\/filebeat\/filebeat.template.json\n<\/pre>\n<p>Which gives this:<\/p>\n<pre lang=\"javascript\">\n{\n  \"acknowledged\" : true\n}\n<\/pre>\n<p>Then restart logbeat, and everything should start working:<\/p>\n<pre lang=\"bash\">\n\/etc\/init.d\/logbeat restart\n<\/pre>\n<ol class=\"footnotes\"><li id=\"footnote_0_2814\" class=\"footnote\">https:\/\/www.elastic.co\/guide\/en\/beats\/filebeat\/current\/filebeat-getting-started.html<span class=\"footnote-back-link-wrapper\"> [<a href=\"#identifier_0_2814\" class=\"footnote-link footnote-back-link\">&#8617;<\/a>]<\/span><\/li><li id=\"footnote_1_2814\" class=\"footnote\">https:\/\/www.elastic.co\/downloads\/beats\/filebeat<span class=\"footnote-back-link-wrapper\"> [<a href=\"#identifier_1_2814\" class=\"footnote-link footnote-back-link\">&#8617;<\/a>]<\/span><\/li><\/ol>","protected":false},"excerpt":{"rendered":"<p>In a previous post, I discuss setting up the ELK stack on Azure, which is a prerequisite for using Logbat. To pump logs from a linux server to , we can use a tool called Filebeat1 (not sure where that fits in &#8220;ELK&#8221;?) On the server you want monitored, you&#8217;ll need to download the appropriate &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/monitoring-a-wordpress-site-with-filebeat\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Monitoring a WordPress site with Filebeat&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[22],"tags":[74,169,338,345,370,522],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/2814"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=2814"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/2814\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=2814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=2814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=2814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}