Skip to content

Commit

Permalink
[v20.1] Database statistics, background backups and script fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wrxck committed Apr 7, 2017
1 parent b95fb2d commit 04e1849
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
7 changes: 3 additions & 4 deletions backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ redisquery="-u $redishost:$redisport -d $redisdb"
if [ ! $redispassword == "nil" ]; then
redisquery="-u :$redispassword@$redishost:$redisport -d $redisdb"
fi
redisbackup="$(date).json"
redis-dump $redisquery > $redisbackup
printf "mattata's database has been saved to \"$(pwd)/$redisbackup\"!"
cd ../
redis-dump $redisquery > "$(date).json"
printf "mattata's database has been saved!"
cd ..
5 changes: 3 additions & 2 deletions mattata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
| | | | | | (_| | |_| || (_| | || (_| |
|_| |_| |_|\__,_|\__|\__\__,_|\__\__,_|
v20.0.1
v20.1
Copyright (c) 2017 Matthew Hesketh
Expand Down Expand Up @@ -68,7 +68,7 @@ function mattata:init()
end
print('Connected to the Telegram bot API!')
print('\n\tUsername: @' .. self.info.username .. '\n\tName: ' .. self.info.name .. '\n\tID: ' .. self.info.id .. '\n')
self.version = 'v20.0.1'
self.version = 'v20.1'
if not redis:get('mattata:version')
or redis:get('mattata:version') ~= self.version
then -- Make necessary database changes if the version has changed.
Expand Down Expand Up @@ -318,6 +318,7 @@ argument when using the mattata.init() function!]]
else
plugin = nil
end
redis:bgsave() -- Perform a background save of the redis database.
end
end
collectgarbage()
Expand Down
63 changes: 63 additions & 0 deletions plugins/redisstats.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
--[[
Copyright 2017 wrxck <[email protected]>
This code is licensed under the MIT. See LICENSE for details.
]]

local redisstats = {}
local mattata = require('mattata')
local redis = require('mattata-redis')

function redisstats:init()
redisstats.commands = mattata.commands(self.info.username):command('redisstats').table
redisstats.help = '/redisstats - View statistics about the bot\'s database.'
end

function redisstats:on_message(message, configuration)
local info = redis:info()
if not info
then
return mattata.send_reply(
message,
'An error occured!'
)
end
return mattata.send_message(
message.chat.id,
string.format(
[[
```
OS: %s
Config File: %s
Mode: %s
TCP Port: %s
Version: %s
Uptime: %s days
Process ID: %s
GCC Version: %s
Expired Keys: %s
Users: %s
Groups: %s
```
]],
info.server.os,
info.server.config_file,
info.server.redis_mode,
info.server.tcp_port,
info.server.redis_version,
info.server.uptime_in_days,
info.server.process_id,
info.server.gcc_version,
mattata.comma_value(info.stats.expired_keys),
mattata.comma_value(
mattata.get_user_count()
),
mattata.comma_value(
mattata.get_group_count()
)
),
'markdown'
)
end

return redisstats

0 comments on commit 04e1849

Please sign in to comment.