Conky en Piwik

Please keep in mind that this post is about 10 years old.
Technology may have changed in the meantime.

Weer even een nerd-dingetje.
Als je niet begrijpt waar het over gaat, heb je het niet nodig. 🙂

Conky is een systeemmonitor voor op de Linux- of BSD-desktop.
Piwik is een open source tool voor de analyse van website-verkeer; zoiets als Google Analytics, maar dan zonder dat je je eigen gegevens en die van je bezoekers aan Google hoeft te geven.
Het zou natuurlijk erg cool zijn om je webstatistieken op je bureaublad te tonen…

Sla dit script op als ~/bin/conky-piwik.sh:

#!/bin/sh

# ~/bin/conky-piwik.sh

# Copyright (c) 2014 Rob la Lau <rob@ohreally.nl>
# This software is in the public domain.

# Retrieve Piwik stats for Conky.

# In ~/.conkyrc:
#
#   TEXT
#   Web stats (uniq/visit/action)
#   example.com: ${execi 3600 ~/bin/conky-piwik.sh 1}

# Vars.
token="0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d"
url="http://stats.example.org/index.php"

# Get site id from command line.
idSite=$1

# Get XML, parse, and print.
curl \
  -s \
  -d "module=API" \
  -d "method=VisitsSummary.get" \
  -d "idSite=${idSite}" \
  -d "period=day" \
  -d "format=xml" \
  -d "token_auth=${token}" \
  -d "date=`date +%Y-%m-%d`" \
  -G "${url}" \
    | awk \
      -F '[<>]' \
      '/<nb_uniq_visitors>/{u=$3}; /<nb_visits>/{v=$3}; /<nb_actions>/{a=$3}; END{print u,"/",v,"/",a}'

Log in op je Piwik-site, klik bovenin het scherm op API, kopieer je authenticatie token, en vul dat in het script in bij token. Kopieer van die zelfde pagina de URL (alles tot aan het vraagteken), en vul die in het script in bij url.

Uiteraard moet dat script executable zijn, en omdat je authenticatie token er in staat, zorg je dat alleen jijzelf het kunt lezen:

$ chmod 700 ~/bin/conky-piwik.sh

Voeg nu deze regels toe aan ~/.conkyrc, onder TEXT:

Web stats (uniq/visit/action)
example.org: ${execi 3600 ~/bin/conky-piwik.sh 1}
example.com: ${execi 3600 ~/bin/conky-piwik.sh 2}
example.net: ${execi 3600 ~/bin/conky-piwik.sh 3}

Het laatste getal tussen de accolades is het ID van de site; dat kun je terugvinden in Piwik. Die 3600 zorgt dat de statistieken elk uur (3600 seconden) ververst worden.

Sample output:

Web stats (uniq/visit/action)
example.org: 25 / 34 / 48
example.com: 31 / 32 / 50
example.net: 12 / 14 / 20

Als je wilt dat een andere periode dan ‘vandaag’ getoond wordt, wijzig je de date in het script.

Have fun!

REPUBLISHING TERMS

You may republish this article online or in print under our Creative Commons license. You may not edit or shorten the text, you must attribute the article to OhReally.nl and you must include the author’s name in your republication.

If you have any questions, please email rob@ohreally.nl

License

Creative Commons License AttributionCreative Commons Attribution
Conky en Piwik