Skip to content

Instantly share code, notes, and snippets.

@rubenwardy
Last active December 3, 2015 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubenwardy/496c9236e459d8b180f4 to your computer and use it in GitHub Desktop.
Save rubenwardy/496c9236e459d8b180f4 to your computer and use it in GitHub Desktop.
Plotting Minetest players etc

License: WTFPL

You may need to replace ~/ with /home/username/ in some places. You should set update_stats.sh as a cronjob. This relies on nginx running as a remote_media_url supplier.

local function log_players()
local red, blue = 0, 0
for name, player in pairs(ctf.players) do
if player.team == "red" then
red = red + 1
elseif player.team == "blue" then
blue = blue + 1
end
end
local line = "\"" .. os.date("%Y-%m-%d %H:%M:%S") .. "\"\t" .. (red+blue) .. "\t" .. blue
local f = io.open("~/scripts/data_users.txt", "a")
if f then
f:write(line .. "\n")
f:close()
else
print("Failed to log to ~/scripts/data_users.txt")
end
minetest.after(10 * 60, log_players)
end
minetest.after(1, log_players)
set title "Client Platforms"
set ylabel "Players"
set terminal pngcairo
unset key
set xtics nomirror
set boxwidth 0.5
set style fill solid
set output "~/public_http/stats/graph_ctf_platforms.png"
plot "~/scripts/data_platforms.txt" using 1:3:xtic(2) with boxes
set title "Players Online (Stacked)"
set terminal pngcairo
set timefmt '"%Y-%m-%d %H:%M:%S"'
set xdata time
set style data lines
set format x "%d/%m\n%H:%M"
set xlabel "Datetime"
set xtics nomirror
set ylabel "Players"
set ytics 5
set mytics 5
set output "~/public_http/stats/graph_ctf_players.png"
set arrow from "2015-12-02 14:00:00",2 to "2015-12-02 14:00:00",20 nohead lc rgb 'red'
plot "~/data_users.txt" using 1:2 t "Team red" w filledcurves y1=0, "~/data_users.txt" u 1:3 t "Team blue" w filledcurves y1=0 linecolor rgb "#0000F$
set title "Client Versions"
set ylabel "Players"
set terminal pngcairo
unset key
set xtics nomirror
set boxwidth 0.5
set style fill solid
set output "~/public_http/stats/graph_ctf_versions.png"
plot "~/scripts/data_versions.txt" using 1:3:xtic(2) with boxes
gnuplot < ~/scripts/plot_players.plot
v13=$(grep "index.mth" /var/log/nginx/access.log | grep "0.4.13" | wc -l)
v12=$(grep "index.mth" /var/log/nginx/access.log | grep "0.4.12" | wc -l)
v11=$(grep "index.mth" /var/log/nginx/access.log | grep "0.4.11" | wc -l)
v10=$(grep "index.mth" /var/log/nginx/access.log | grep "0.4.10" | wc -l)
vOld=$(grep "index.mth" /var/log/nginx/access.log | grep "gUnknown" | wc -l)
vAll=$(grep "index.mth" /var/log/nginx/access.log | wc -l)
vCovered=`expr $v13 + $v12 + $v11 + $v10 + $vOld`
vOther=`expr $vAll - $vCovered`
echo "0 \"0.4.13\" $v13" > ~/scripts/data_versions.txt
echo "1 \"0.4.12\" $v12" >> ~/scripts/data_versions.txt
echo "2 \"0.4.11\" $v11" >> ~/scripts/data_versions.txt
echo "3 \"0.4.10\" $v10" >> ~/scripts/data_versions.txt
echo "4 \"Older\" $vOld" >> ~/scripts/data_versions.txt
echo "5 \"Other/Unknown\" $vOther" >> ~/scripts/data_versions.txt
gnuplot < ~/scripts/plot_versions.plot
pWin=$(grep "index.mth" /var/log/nginx/access.log | grep "Windows" | wc -l)
pAndroid=$(grep "index.mth" /var/log/nginx/access.log | grep "Linux" | grep "armv7l\|Android" | wc -l)
pLinux=$(expr $(grep "index.mth" /var/log/nginx/access.log | grep "Linux" | wc -l) - $pAndroid)
pDarwin=$(grep "index.mth" /var/log/nginx/access.log | grep "Darwin" | wc -l)
pIOS=$(grep "index.mth" /var/log/nginx/access.log | grep "Darwin" | grep "iOS\|iPad\|iPod\|iPhone" | grep -v "OSX" | wc -l)
pOSX=`expr $pDarwin - $pIOS`
pOther=`expr $vAll - $pWin - $pAndroid - $pLinux - $pIOS - $pOSX`
echo "0 \"Linux\" $pLinux" > ~/scripts/data_platforms.txt
echo "1 \"Windows\" $pWin" >> ~/scripts/data_platforms.txt
echo "2 \"OSX\" $pOSX" >> ~/scripts/data_platforms.txt
echo "3 \"Android\" $pAndroid" >> ~/scripts/data_platforms.txt
echo "4 \"Illegal iOS\" $pIOS" >> ~/scripts/data_platforms.txt
echo "5 \"Others\" $pOther" >> ~/scripts/data_platforms.txt
gnuplot < ~/scripts/plot_platforms.plot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment