How to use goaccess with heroku rails app - ruby-on-rails

I want to generate goaccess dashboard result from heroku logs of rails application, As I checked there is no production.rb file in heroku
Format of logs in heroku is
2020-07-16T17:18:54.972063+00:00 app[web.1]: I, [2020-07-16T17:18:54.971939 #10] INFO -- : [2712edd9-bca1-4d23-9cfd-399e6dedfbdc] Started GET "/api/v1/articles" for 18.225.35.172 at 2020-07-16 17:18:54 +0000
2020-07-16T17:18:54.973433+00:00 app[web.1]: I, [2020-07-16T17:18:54.973345 #10] INFO -- : [2712edd9-bca1-4d23-9cfd-399e6dedfbdc] Processing by Api::V1::ArticlesController#index as JSON
2020-07-16T17:18:54.973525+00:00 app[web.1]: I, [2020-07-16T17:18:54.973450 #10] INFO -- : [2712edd9-bca1-4d23-9cfd-399e6dedfbdc] Parameters: {"article"=>{}}
2020-07-16T17:18:55.082811+00:00 heroku[router]: at=info method=GET path="/api/v1/article" host=abc-1234.herokuapp.com request_id=2779d556-67fc-4602-a58b-60dbcb209833 fwd="18.225.35.172" dyno=web.1 connect=1ms service=41ms status=200 bytes=539 protocol=https
I tried installing goaccess on my heroku server , but I am not able to do that, and I am not able to get log file also.
I want response time for each request in goaccess dashboard.
Anyone has idea about this ???How I can use goaccess + rails + heroku together

Try this:
cat ./production.log | grep 'Started GET' | goaccess --log-format='I, "%^" "%r" %^ %h %^ %d %t %^' --date-format=%F --time-format=%T
Note: it will work only for line like:
2020-07-16T17:18:54.972063+00:00 app[web.1]: I, [2020-07-16T17:18:54.971939 #10] INFO -- : [2712edd9-bca1-4d23-9cfd-399e6dedfbdc] Started GET "/api/v1/articles" for 18.225.35.172 at 2020-07-16 17:18:54 +0000
other lines were ignored by grep, which were:
2020-07-16T17:18:54.973433+00:00 app[web.1]: I, [2020-07-16T17:18:54.973345 #10] INFO -- : [2712edd9-bca1-4d23-9cfd-399e6dedfbdc] Processing by Api::V1::ArticlesController#index as JSON
2020-07-16T17:18:54.973525+00:00 app[web.1]: I, [2020-07-16T17:18:54.973450 #10] INFO -- : [2712edd9-bca1-4d23-9cfd-399e6dedfbdc] Parameters: {"article"=>{}}
2020-07-16T17:18:55.082811+00:00 heroku[router]: at=info method=GET path="/api/v1/article" host=abc-1234.herokuapp.com request_id=2779d556-67fc-4602-a58b-60dbcb209833 fwd="18.225.35.172" dyno=web.1 connect=1ms service=41ms status=200 bytes=539 protocol=https
My original answer was at goaccess issue, Good luck!

Related

How to handle someone trying to hack my website?

I'm going through my 404 logs and I noticed this:
302 <158>1 2018-10-20T19:12:36.942085+00:00 heroku router - - at=info method=GET path="/wp-login.php" host=www.makerspro.io request_id=f5929aab-8671-433e-92d0-1e779f997d0a fwd="194.99.106.147" dyno=web.1 connect=0ms service=1923ms status=404 bytes=6042 protocol=http
307 <158>1 2018-10-20T19:12:39.076998+00:00 heroku router - - at=info method=GET path="/blog/wp-login.php" host=www.makerspro.io request_id=ce175bfd-6411-48c2-9328-1b6fccb6ae30 fwd="194.99.106.147" dyno=web.1 connect=0ms service=1629ms status=404 bytes=6042 protocol=http
305 <158>1 2018-10-20T19:12:40.699840+00:00 heroku router - - at=info method=GET path="/wp/wp-login.php" host=www.makerspro.io request_id=17bd87b1-3d8f-48bb-8748-ff9d47250dba fwd="194.99.106.147" dyno=web.1 connect=0ms service=1420ms status=404 bytes=6042 protocol=http
312 <158>1 2018-10-20T19:12:42.599811+00:00 heroku router - - at=info method=GET path="/wordpress/wp-login.php"
My website is built on rails, I'm the only developer and it seems like someone is trying to hack my website.
Of course, I don't have wordpress installed or anything like that.
What can I do about this and how can I prevent future attacks?
These are generic attacks that happen constantly, and is done by scripts.
The best course is to make sure you are not vulnerable, then ignore them. If you do not have Wordpress, then you have nothing to worry about regarding requests to /wp-login.php.
If you want to harden your application, make sure you have security measures like described in the RoR documentation (https://guides.rubyonrails.org/security.html).

Heroku devise/facebook oauth glitch with identical source code

I try to solve problems myself, but this one has got the best of me and I'm on the verge of head-butting my desk.
Here's what I do:
I test the production oAuth, all works perfectly as it has for months
I use heroku git:clone -a myapp to get the source code locally
I make no changes whatsoever, I simply re-commit and push back up to Heroku
I test the production oAuth again, it doesn't work
I keep having to use heroku rollback, so that I can go back to the working version. I thought that since the source code is identical, maybe a gem I'm using has updated and broken something. But I checked the oAuth gems and none of them have changed for a while.
Here's my log when it doesn't work:
2015-10-25T15:20:47.802222+00:00 app[web.1]: Started GET "/humans/auth/facebook?ip=123&loc=8&mac=123&var=11" for 162.158.38.218 at 2015-10-25 15:20:47 +0000
2015-10-25T15:20:47.804207+00:00 app[web.1]: I, [2015-10-25T15:20:47.804128 #3] INFO -- omniauth: (facebook) Request phase initiated.
2015-10-25T15:20:47.871762+00:00 heroku[router]: at=info method=GET path="/humans/auth/facebook?ip=123&loc=8&mac=123&var=11" host=yourhotspot.net request_id=9804b0a9-a190-4881-a64f-ff222aa216e3 fwd="82.34.163.154,162.158.38.218" dyno=web.1 connect=0ms service=75ms status=302 bytes=1916
2015-10-25T15:20:48.181538+00:00 app[web.1]: Started GET "/humans/auth/facebook/callback?ip=123&loc=8&mac=123&var=11&code=AQCqfCPHQUM_YzgXPJSUniVKumx6ii2fsQtgEw9Bc3B9MFwNyKmnRtdqZxCRWSl1bDxdZKIAgU_M_-DQGVedt7FRYsm8DxA7gPA8bky86H-jlaCaFQa1Gc2BRLxtuzEUPKtu3UPRmKjUpXBuJI0nHOmG4IF3WWjwRk1jtfvWvgHmEH5Q-h-JjoEgiTC5uqK6XN2E48hKqxYcqBVs-pDMLMp74WRmRCXN_R_R_RuAjyyj_9-GdNHhZ6uajuri_41AN5V8W9UqWPmtPHznL7ztNLzS9dDj7S9e25bINXUMneHVVNHwGpp5PWZULsN_hwJueUU4SFZlNgzrnupacHAXF9kU&state=1e8f5be4b10b96baedd6aab3cd2eb125b150e100c5a2c7bb" for 162.158.38.218 at 2015-10-25 15:20:48 +0000
2015-10-25T15:20:48.183305+00:00 app[web.1]: I, [2015-10-25T15:20:48.183218 #3] INFO -- omniauth: (facebook) Callback phase initiated.
2015-10-25T15:20:48.733053+00:00 app[web.1]: {"error":{"message":"Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request","type":"OAuthException","code":100,"fbtrace_id":"B8bmqcG7i6M"}}
2015-10-25T15:20:48.733049+00:00 app[web.1]: E, [2015-10-25T15:20:48.732948 #3] ERROR -- omniauth: (facebook) Authentication failure! invalid_credentials: OAuth2::Error, :
2015-10-25T15:20:48.735557+00:00 app[web.1]: Parameters: {"ip"=>"123", "loc"=>"8", "mac"=>"123", "var"=>"11", "code"=>"AQCqfCPHQUM_YzgXPJSUniVKumx6ii2fsQtgEw9Bc3B9MFwNyKmnRtdqZxCRWSl1bDxdZKIAgU_M_-DQGVedt7FRYsm8DxA7gPA8bky86H-jlaCaFQa1Gc2BRLxtuzEUPKtu3UPRmKjUpXBuJI0nHOmG4IF3WWjwRk1jtfvWvgHmEH5Q-h-JjoEgiTC5uqK6XN2E48hKqxYcqBVs-pDMLMp74WRmRCXN_R_R_RuAjyyj_9-GdNHhZ6uajuri_41AN5V8W9UqWPmtPHznL7ztNLzS9dDj7S9e25bINXUMneHVVNHwGpp5PWZULsN_hwJueUU4SFZlNgzrnupacHAXF9kU", "state"=>"1e8f5be4b10b96baedd6aab3cd2eb125b150e100c5a2c7bb"}
2015-10-25T15:20:48.735493+00:00 app[web.1]: Processing by Humans::OmniauthCallbacksController#failure as HTML
And when it does:
2015-10-25T15:56:56.726873+00:00 heroku[router]: at=info method=GET path="/humans/auth/facebook?ip=123&loc=8&mac=123&var=11" host=yourhotspot.net request_id=1c01da5f-1bea-4dbb-9a1b-a80dcc442539 fwd="82.34.163.154,162.158.38.211" dyno=web.1 connect=1ms service=18ms status=302 bytes=1828
2015-10-25T15:56:56.714754+00:00 app[web.1]: I, [2015-10-25T15:56:56.714674 #3] INFO -- omniauth: (facebook) Request phase initiated.
2015-10-25T15:56:56.920771+00:00 app[web.1]: I, [2015-10-25T15:56:56.920692 #3] INFO -- omniauth: (facebook) Callback phase initiated.
2015-10-25T15:56:56.712897+00:00 app[web.1]: Started GET "/humans/auth/facebook?ip=123&loc=8&mac=123&var=11" for 162.158.38.211 at 2015-10-25 15:56:56 +0000
2015-10-25T15:56:56.919315+00:00 app[web.1]: Started GET "/humans/auth/facebook/callback?code=AQC7jHL3hk8TSP5F9lsDjzkyXlAIbk-Kf3027g3bU-9x0etBoOxUvHd6ofEIZjEolh-UajkUCS4WZ3z40q7tgrIYi8ZIy6fuhjRJwyqLhXBPfOnmL1LqCDlPFVIdizrHPUomZ5WZ-VLmFc7A1UsEUVpyW907LgoaL8S90Gukh9oGvykIcpc1tmHqpc-WaayJNCkTUPxaRtlEmuD5FTVUDoRAzFnVDYCURhNAZMs9eTk-O40_leapHbTX0Uz6sFC6RHn-qgien_diOJst2DlRvtKWCcfxXuoBZPFPa5BtRYg2_eP4K8zUxRtDeazwYsxJt7o1i9V93np56EABMMrfBmIK&state=952e4d3cbe773056b12f56d76b0a54c5ea841f51e61d5041" for 162.158.38.211 at 2015-10-25 15:56:56 +0000
2015-10-25T15:56:57.897756+00:00 app[web.1]: Processing by Humans::OmniauthCallbacksController#facebook as HTML
I just cannot wrap my head around what's going on here. The fact that my code, environments, config vars and app settings are identical is hurting my head.
If anyone can shed some light on what might be going wrong, I'd be very appreciative.
EDIT: (Commands used)
heroku git:clone -a myapp (At this point of cloning, I had already rolled back to v410, so this clone should be of that working copy)
(cd into new app directory, make a line
change so that I can re-commit)
git add .
git commit . -m "msg"
git push heroku master
(realise it's not working as expected)
heroku
rollback v410
Command logs gave no errors and the commands worked as expected. Yet something is changing oauth.
What definitely could change on deployment is a physical server ('dyno'). I would check following things: 1) does your app cache any authentication tokens issued by facebook, e.g. in configuration? 2) how possible is that such tokens are bound to the server's IP address?

heroku[router] gets old and wrong url

I have a rails app deployed on heroku, and there is an annoying issue: my router heroku gets an url that doesn't exist anymore (I have deleted everything on my WebApp regarding the notifications).
Do you have any idea where it could come from?
Here are what my logs :
2015-06-25T12:22:30.357205+00:00 heroku[router]: at=info method=GET path="/notifications" host=www.krawd.com request_id=6b03fbec-88ee-48bd-8afd-aa6d59a9bf53 fwd="82.237.217.103" dyno=web.1 connect=1ms service=12ms status=500 bytes=377
2015-06-25T12:22:30.334224+00:00 app[web.3]: source=rack-timeout id=8b3b9046-8613-44fb-8274-c0dc976d3472 wait=16ms timeout=25000ms state=ready
2015-06-25T12:22:30.362821+00:00 app[web.3]: source=rack-timeout id=8b3b9046-8613-44fb-8274-c0dc976d3472 wait=16ms timeout=25000ms service=29ms state=active
2015-06-25T12:22:30.406680+00:00 app[web.3]: Completed 500 Internal Server Error in 25ms
2015-06-25T12:22:30.341720+00:00 app[web.1]: source=rack-timeout id=6b03fbec-88ee-48bd-8afd-aa6d59a9bf53 wait=0ms timeout=25000ms service=0ms state=active
2015-06-25T12:22:30.344956+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/notifications"):
Make sure you search your web app folder for "/notifications" and see if you forgot some reference somewhere. Does the request happen when you run on localhost? You could trace it more easily that way.

Heroku Slow Loading Throughout

My Heroku Rails is always loading extremely slowly and not only at first start.
It doesnt load this slowly in production mode.
I have New-Relic Installed, I have two Dynos running and I have PostgreSQL Crane Plan. But when I start my app it will normally take about 30 seconds to load and 60% of the time it'll go straight to Application Error, if I check my logs I get Memory Quota Exceeded. Even if I go to a static page with no Ruby in its source, it'll still load slowly. Sometimes I manage to connect to my app and it will normally take around 10 seconds to load when navigating from page to page.
I've been looking online for ages and all the most common answer I find is to just add an extra dyno, but that doesnt help.
Im also running on Unicorn
These are the logs from a movies#show page which loaded at first and then crashed
Started GET "/movies/61708" for 81.34.154.155 at 2013-08-29 23:08:23 +0000
2013-08-29T23:08:30.093034+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path=/?page=7 host=www.websitename.com fwd="81.34.154.155" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0
2013-08-29T23:08:31Z app[postgres.8916]: [BLUE] duration: 6945.946 ms statement: SELECT "movies".* FROM "movies"
2013-08-29T23:08:41+00:00 app[heroku-postgres]: source=HEROKU_POSTGRESQL_BLUE measure.current_transaction=2844 measure.db_size=60732536bytes measure.tables=23 measure.active-connections=10 measure.waiting-connections=0 measure.index-cache-hit-rate=1 measure.table-cache-hit-rate=1
2013-08-29T23:08:45.401673+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path=/movies/63724 host=www.websitename.com fwd="81.34.154.155" dyno=web.1 connect=2ms service=30001ms status=503 bytes=0
2013-08-29T23:08:45.445116+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path=/movies/63704 host=www.websitename.com fwd="81.34.154.155" dyno=web.2 connect=3ms service=30000ms status=503 bytes=0
2013-08-29T23:08:52.684401+00:00 heroku[web.2]: Process running mem=512M(100.0%)
2013-08-29T23:08:52.684613+00:00 heroku[web.2]: Error R14 (Memory quota exceeded)
2013-08-29T23:08:53.647059+00:00 app[web.1]: E, [2013-08-29T23:08:53.384868 #2] ERROR -- : worker=0 PID:5 timeout (61s > 60s), killing
2013-08-29T23:08:54.375154+00:00 app[web.1]: E, [2013-08-29T23:08:54.374971 #2] ERROR -- : reaped #<Process::Status: pid 5 SIGKILL (signal 9)> worker=0
Does anyone know a solution for this?
You mentioned in the comments you have 60,000 rows in your movies table. From your logs it appears you're doing something like the following:
Movie.all
This will generate an SQL query like what we see in your logs.
SELECT "movies".* FROM "movies"
The memory/storage capacity of Postgres doesn't matter with respect to your issue. Your database could be on a dedicated server with 96G RAM. You'll still end up with the same problem on Heroku's end.
When you do something like Movie.all, you're creating in-memory ruby class instances of Movie for all 60,000 records. This takes time and space.
You're probably also rendering too many (dare I say all?!) of these records to a single webpage at once. This is simply way too much data to render during a single request, whether you're on Heroku or not.
Heroku has a hard 30s time limit for it's request's running time. You're hitting this limit. Try a much smaller subset of data, even just as a test, and see if it solves your issues. I'm betting it will.
Movie.limit(10)

Intermittent timeouts from an app that should never timeout (NOT an "R12 Request Timeout" error)

I've got a simple business Rails 3.2.13 app with a base of only one user, with very small Postgres DB tables, and very simple Active Record DB queries. I'm running it on two dynos, zero workers, on the Unicorn web server. The root page of the app typically loads in about 150 ms in development, and in under 1 s in production at Heroku.
EXCEPT, when it randomly times out. I'm seeing timeouts in the log, but NOT the typical R12 Request Timeout. The timeouts look like this:
2013-05-28T16:04:28.004290+00:00 app[web.2]: Started GET "/" for 72.28.209.197 at 2013-05-28 16:04:28 +0000
2013-05-28T16:04:44.225643+00:00 app[web.2]: E, [2013-05-28T16:04:44.225444 #2] ERROR -- : worker=2 PID:87 timeout (16s > 15s), killing
2013-05-28T16:04:44.238422+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path=/ host=[REDACTED].herokuapp.com fwd="72.28.209.197" dyno=web.2 connect=7ms service=16240ms status=503 bytes=0
2013-05-28T16:04:44.255813+00:00 app[web.2]: E, [2013-05-28T16:04:44.255554 #2] ERROR -- : reaped #<Process::Status: pid 87 SIGKILL (signal 9)> worker=2
2013-05-28T16:04:44.298023+00:00 app[web.2]: I, [2013-05-28T16:04:44.297643 #103] INFO -- : worker=2 ready
When that request works, it looks like this:
2013-05-28T16:03:36.965507+00:00 app[web.1]: sequenceId="102642"] Started GET "/" for 72.28.209.197 at 2013-05-28 16:03:36 +0000
2013-05-28T16:03:37.388261+00:00 app[web.1]: sequenceId="102690"] Processing by OverviewController#index as HTML
2013-05-28T16:03:38.238877+00:00 app[web.1]: sequenceId="102707"] Rendered overview/index.html.erb within layouts/application (315.8ms)
2013-05-28T16:03:38.311974+00:00 app[web.1]: sequenceId="102710"] Completed 200 OK in 924ms (Views: 432.4ms | ActiveRecord: 92.1ms)
2013-05-28T16:03:38.322786+00:00 heroku[router]: at=info method=GET path=/ host=[REDACTED].herokuapp.com fwd="72.28.209.197" dyno=web.1 connect=2ms service=1375ms status=200 bytes=136795
2013-05-28T16:03:42.625787+00:00 app[web.1]: sequenceId="102940"] Started GET "/assets/favicon.ico" for 72.28.209.197 at 2013-05-28 16:03:42 +0000
2013-05-28T16:03:58.753408+00:00 app[web.1]: sequenceId="104359"] E, [2013-05-28T16:03:58.753173 #2] ERROR -- : worker=2 PID:66 timeout (16s > 15s), killing
2013-05-28T16:03:58.801152+00:00 app[web.1]: sequenceId="104362"] E, [2013-05-28T16:03:58.800993 #2] ERROR -- : reaped #<Process::Status: pid 66 SIGKILL (signal 9)> worker=2
2013-05-28T16:03:58.798722+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path=/assets/favicon.ico host=[REDACTED].herokuapp.com fwd="72.28.209.197" dyno=web.1 connect=3ms service=16175ms status=503 bytes=0
2013-05-28T16:03:59.127150+00:00 app[web.1]: sequenceId="104397"] I, [2013-05-28T16:03:59.126795 #84] INFO -- : worker=2 ready
Things to note: The request response time was 924 ms. But then some kind of strange error happened after that.
This is what that request looks like in terms of DB queries. There is nothing exciting happening there, and those DB tables only contain a few hundred rows of data. There is no reason why the response should take 1 second sometimes, and 15+ seconds on other times. Here's the code for the extremely simple controller action:
class OverviewController < ApplicationController
def index
#current_event = Event.recent
#areas = Area.order(:position)
#reservations = Reservation.find(:all,
:conditions => { :event_id => #current_event.id },
:order => 'created_at DESC',
:limit => 5)
end
end
Here's the Event#recent method, just so that you can see that it's not doing anything that could potentially take 15+ seconds:
def self.recent
Event.last || Event.create
end
I'm at a loss for how to get this app stabilized, other than moving it off of Heroku. I don't know of any way to troubleshoot the problem, and I guess Heroku won't help. Am I simply stuck? Do I have any options for troubleshooting the problem other than moving the app to Engine Yard?
Nothing here helped, and this site is Heroku's technical support. Paying $35/mo doesn't buy me any support, so I'm stuck and there is no way forward with Heroku.
So my answer to this problem is to move the app to Engine Yard. I don't see that I have any other options. Heroku is awesome when it works and it's a complete mystery with no technical support when it doesn't work.

Resources