
How I built ghit.me, hit count badges for GitHub - benwilber0
https://benwilber.github.io/nginx/syslog-ng/redis/github/hit/counter/2015/12/25/how-i-built-ghit-me.html
======
akerl_
How does this deal with GitHub's caching of images?

[https://github.com/blog/1766-proxying-user-
images](https://github.com/blog/1766-proxying-user-images)

They refer to it as "proxying", but they also call out that it proxies using
their CDN, which seems to imply there isn't a 1:1 relationship between user
requests and hits on the backend server

~~~
benwilber0
Github's proxy[1] respects Cache-Control headers, so it will just pass through
since we use Etags and Cache-Control: no-cache.

[1][https://github.com/atmos/camo](https://github.com/atmos/camo)

~~~
orf
Heh, someone should tell BitDeli[1]. They had to effectively shut down due to
this, but if the fix is a simple as that then they will be hitting themselves.

Edit: Would it not be possible/better to just serve the SVG image direct from
nginx? There is a LUA plugin, or even some direct redis stuff you could use.

1\. [https://bitdeli.com/](https://bitdeli.com/)

~~~
benwilber0
their analytics service still won't work since Github's camo proxy scrubs all
cookies, referers, remote addrs, etc.

edit: and regarding lua or nginx redis2, yes you could certainly do that. I
happen to like the asynchronous nature of incrementing hit counters outside of
the request cycle and just using nginx to serve the static badge files. But
yeah there are a bunch of ways to do this.

------
Khao
Back to geocities websites with hit counters! I like how it was implemented
though, I simply hope I won't start seeing this everywhere from now on because
it doesn't add anything to a repo to have that badge.

~~~
jlarocco
The only thing missing here is some tacky, irritating animation, but I've even
seen that being rediscovered in some recently posted articles...

------
hfaran
For anyone that is unaware, "hit count" functionality has been present in
GitHub for at least several months. If you're the owner of a repository, you
can view it at
[https://github.com/<username>/<repo>/graphs/traffic](https://github.com/<username>/<repo>/graphs/traffic)
which gives you a breakdown of visitors, clones, referring sites, and which
pages within your repository are popular.

~~~
lell
Is there a way to make this cover a period of >2 weeks? I can only see 2 weeks
of traffic for my repos.

------
rb2k_
If you ever wanted to filter by IP so you don't end up with tons of
duplicates, it would be a nice usecase for the native hyperloglog support in
Redis:

[http://antirez.com/news/75](http://antirez.com/news/75)

[http://redis.io/commands/pfadd](http://redis.io/commands/pfadd)

[http://redis.io/commands/pfcount](http://redis.io/commands/pfcount)

~~~
zimbatm
You can't, image urls on github are rewritten to be fetched trough a proxy.

------
jafingi
If people fork/clone the repo, then wouldn't it also update the count on the
main repo?

------
zeeshanm
If anyone's trying to use ghit.me - beware that api rate limit from github is
preventing the tool from working. May be, try again:

    
    
      {
        "message": "API rate limit exceeded for 107.170.25.70. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)",
        "documentation_url": "https://developer.github.com/v3/#rate-limiting"
      }

------
dougifresh94
This got rate limited by github's API...

------
boomeasy
nice. I just added it to my hackernews chrome extension repo:
[https://github.com/boomeasy/hnlinks](https://github.com/boomeasy/hnlinks)
perhaps it will reach double digits by next year :-)

------
btym
Cron? Syslog? Seriously? This could, in real-time and fewer lines of code,
just directly get and increment a counter...

~~~
benwilber0
yep it's a pretty trivial task and there are a lot of ways to do it. i like
just serving static files and incrementing hit counts outside of the request.

