Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Stats - Numbers don't compute

Started by Shane 1 year ago · 18 replies · 233 views
1 year ago

I logged into my site today, and was just looking at the Page View Statistics that automatically show up on my dashboard. Check them out:
Screenshot 2025-04-02 at 11.12.39 AM|609x330
The numbers just don't seem to add up. The Month number 1977, and today only being 863, yesterday's numbers would have to be over 1000, but they are less than 800. This week's numbers may be more on par, but the month is off! I'm not sure where these stats come from, or how accurate they are. I do like them, but now I'm thinking they are unreliable. It is April 2, so this is not a fools joke, unless Grav joked me yesterday. 😃 Is this a bug?

1 year ago

Screenshot 2025-04-02 at 1.48.33 PM|608x330
There is probably a logical explication to this, because they are consistently off. Clearly I'm missing something.

1 year ago

You're not the first complaining about it.... https://github.com/getgrav/grav-plugin-admin/issues/2440

The data is collected in files /logs/popularity/daily.json and /logs/popularity/montly.json. For example:

TXT
// daily.json
{
    "27-03-2025":1,
    "28-03-2025":2,
    "29-03-2025":3
    "30-03-2025":4,
    "31-03-2025":5,
    "01-04-2025":6,
    "02-04-2025":7
}

// montly.json
{"04-2025":13}

The weekly statistics is calculated by adding the last 7 days from daily.json.
The result should then be:
{EA93C35D-7704-44EB-A860-ACE2B14DAFD9}|690x365

Let's have a look at your data. Would you mind sharing from the log files, the month April from montly.json and the last 7 days from daily.json.

1 year ago

Well, that is kind of neat.

TXT
//daily.json
{"01-04-2025":552,
"02-04-2025":1096}
TXT
//monthly.json
{"03-2025":25208,
"04-2025":2212}
1 year ago

@shane, And where are the remaining 5 days making up "the last 7 days" in daily.json?

1 year ago

They are not in the file. 🤔

1 year ago

@shane, Smells fishy...

  • There is a value for the previous month, but you have no records for days in March.
    By default, Grav keeps the last 30 days (or more exact: records) in daily.json and purges the rest.
    And Grav keeps the last 12 records for montly.json
  • The value for April, cannot be larger then the sum of hits for 01/04 + 02/04
last edited 04/02/25 by pamtbaau
1 year ago

@pamtbaau:
The value for April, cannot be larger then the sum of hits for 01/04 + 02/04

This is why I was scratching my head when I read the stats. I really don't know, I had no idea even where to find the data before you told me. 😃 I just used
cat daily.json
and copy and pasted what was there. Same for monthly.
I did move all the pages from my test site over in March, but only moved the user/pages stuff. Perhaps that messed with the stats? I'm not sure how they are tied in. I think it was early March though....

1 year ago

@shane, I'm pretty sure you have been visiting your site in March, so daily.json and montly.json should have data for that period.

With the info given so far, I cannot draw any conclusion that explains the issue.

Suggestion:

  • Delete the files and see what happens.
1 year ago

So, I wanted to see from my test/staging site it's stats.

TXT
cat daily.json 
{"03-03-2025":119,"04-03-2025":149,"05-03-2025":357,"06-03-2025":763,"07-03-2025":972,"08-03-2025":695,"09-03-2025":9,"10-03-2025":93,"11-03-2025":165,"13-03-2025":3592,"14-03-2025":5317,"15-03-2025":436,"16-03-2025":567,"17-03-2025":488,"18-03-2025":628,"19-03-2025":462,"20-03-2025":315,"21-03-2025":217,"22-03-2025":234,"23-03-2025":210,"24-03-2025":158,"25-03-2025":101,"26-03-2025":84,"27-03-2025":63,"28-03-2025":42,"29-03-2025":36,"30-03-2025":44,"31-03-2025":52,"01-04-2025":63,"02-04-2025":55}
TXT
cat monthly.json 
{"03-2025":14135,"04-2025":118

I had to do some serious cleaning of my site, because it had a lot of old outdated plugins. I did a clean install of my site in a subdomain and moved all the pages over. All worked like a charm. I cleaned it all up, and then moved it back, but I don't remember how I did all that. Even if I did the stats would have been goofy in early March, but not now. It was a couple of weeks ago or more that I did all that. I checked my logs, and I have no errors since March 7th.

1 year ago

@pamtbaau:
Suggestion:

  • Delete the files and see what happens.

So, I came back after a few days, and only two days are kept in the log.... so clearly there is a problem besides that of addition. I moved the logs to daily.json.old and monthly.json.old and they immediately repopulated. If that doesn't work, there is clearly a problem, what should be my next fix? I have no errors in the log. Here are the old stat logs that I moved:

TXT
cat monthly.json.old 
{"04-2025":1816}
cat daily.json.old
{"03-04-2025":1347,"04-04-2025":467}

Can I re-install a plugin? Is this a core feature? My staging site doesn't have this issue. Thank you for your help.

1 year ago

@shane,

I moved the logs to daily.json.old and monthly.json.old and they immediately repopulated.

Are you using fastCGI? When Grav is kept in memory, the arrays created from the popularity files will be kept in memory.

PHP
if (!$this->daily_data) {
    $this->daily_data = $this->getData($this->daily_file);
}

On each request, the existing array in memory will be updated with the new hit and written again to disk. Hence they are immediately repopulated when you move the popularity files.

If Grav is not kept in memory, the popularity files will be read from disk on each request and written back to disk.

Disclaimer: I know nothing about the internals of webservers, but this is how I guess it works...

To comment further on the issue:
I've gone over the code again and again, but I fail to see how Grav can be the cause of truncated popularity files.

Could there be an interference with a plugin?

1 year ago

When I say, "They immediately repopulated" I should clarify, they didn't continue with the numbers, the files were auto-created immediately, but the stats were all restarted. I don't know even how to tell if I have fastCGI. I'm on shared hosting.

On a side note, I did install the Page Stats plugin. I did this just for comparative purposes.

1 year ago

I was letting this work for a while, but according to my records, I reset the daily.json file on April 4th, and only have 7 days of records. So that is odd. Not a super big deal, just odd.

TXT
ls -lsh
total 88K
8.0K -rw-r--r-- 1 username username  125 Apr 16 09:25 daily.json
8.0K -rw-r--r-- 1 username username   36 Apr  4 09:29 daily.json.old
8.0K -rw-r--r-- 1 username username   17 Apr 16 09:25 monthly.json
8.0K -rw-r--r-- 1 username username   16 Apr  4 09:29 monthly.json.old
 40K -rw-r--r-- 1 username username  33K Apr 16 09:25 totals.json
8.0K -rw-r--r-- 1 username username 1.1K Apr 16 09:25 visitors.json
TXT
cat daily.json
{
"10-04-2025":311,
"11-04-2025":1063,
"12-04-2025":2822,
"13-04-2025":2452,
"14-04-2025":7716,
"15-04-2025":3196,
"16-04-2025":537}

 cat monthly.json
{"04-2025":26347}
1 year ago

@shane,

What's the value of popularity.history.daily in the following files (if existing):

  • user/config/plugins/admin.yaml
  • user/env/yourdomain/config/plugins/admin.yaml
  • user/env/localhost/config/plugins/admin.yaml
  • user/yourdomain/config/plugins/admin.yaml
  • user/localhost/config/plugins/admin.yaml
1 year ago

So here is what I have in the admin.yaml

YAML
popularity:
  enabled: true
  ignore:
    - '/test*'
    - /modular
  history:
    daily: '30'
    monthly: '12'
    visitors: '20'

same document, different section:

YAML
dashboard:
  days_of_stats: 7
1 year ago

Also, oddly, I have a admin.yaml file in these directories:

TXT
/user/plugins/admin/
/user/config/plugins/

I have a folder: /user/domainname/config/plugins but there isn't an admin.yaml file there.

1 year ago

Also, oddly, I have a admin.yaml file in these directories:

These are as expected...

JS
/user/plugins/admin/   <=== Comes with the Admin plugin as default values
/user/config/plugins/  <=== Where Admin saves its own config, 
                            unless running in some domain
👍 1

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 76 7 hours ago
General · by pamtbaau, 13 hours ago
1 47 12 hours ago
General · by Andy Miller, 1 day ago
0 44 1 day ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 40 5 days ago