-
Notifications
You must be signed in to change notification settings - Fork 0
examples
These examples use a MySQL database setup as that is what I currently use on my own webserver.
You can use the data gathered by the plugin to generate graphs to display the average amount of players on your website. This is done by using the group and average functions in MySQL. The following query is an example you could use to give you the average number of users online every hour for the last 24 hours.
select DATE_FORMAT(FROM_UNIXTIME(created_at / 1000), '%d %m %h %p') as formatted_date,
COUNT(created_at),
FROM_UNIXTIME(created_at / 1000) as mysql_date,
ROUND(AVG(player_count)) as average_players,
ROUND(MAX(player_count)) as max_players,
ROUND(MIN(player_count)) as min_players,
created_at from simplestats_players
GROUP BY formatted_date
ORDER BY created_at
DESC LIMIT 24
This gives effectively groups the results into hours, limits the result to the last 24 hours and then gives you the minimum, maximum and average amount of players online during those hours. It is important to divide the timestamp by 1000 as Java timestamps are in milliseconds while Unix ones are in seconds. You could then use this to create a graph that looks like this:

You can do the same to create memory usage graphs. This is done is a very similar way to the previous query in MySQL. You also need to ensure to ROUND the memory totals as they might not be whole numbers but are already converted into Megabytes. The following example gets the max, average memory used, average memory free and the average memory total for the last 24 hours broken down by hour.
select DATE_FORMAT(FROM_UNIXTIME(created_at / 1000), '%m %d %h %p') as formatted_date,
FROM_UNIXTIME(created_at / 1000) as mysql_date,
MAX(memory_max),
ROUND(AVG(memory_total)),
ROUND(AVG(memory_used)),
ROUND(AVG(memory_free))
FROM simplestats_memory
GROUP BY formatted_date
ORDER BY created_at
DESC LIMIT 24
You can use the same techniques as before to change the number of hours you want or change the grouping by altering the date format at the start. Using this data you can create a graph like this:
