This is how I graph, and monitor the number of login failures on a Linux server using Grafana with a MySQL data source.
Ultimately, that graph will look something like this. or this:
You'll need to have a basic understanding of Linux System Administration, a MySQL Database, and Grafana to make any sense of what I'm doing here.
There are just a few steps needed to make this all work.
- Creating the MySQL database, and creating a user tha has read and write privileges to that database.
- Importing the table schema for the database, which will contain all of our recorded failed logins.
- Setting up a cronjob to regularly update that DB (I run my cronjob hourly.)
- Defining a datasource in Grafana that uses this MySQL DB
- Creatng a new Graph in Grafana, which will display the number of failed login attempts.
MYSQL:
- Create the database:
mysql> CREATE DATABASE LoginFailures;
- Switch to the database:
mysql> USE LoginFailures;
- Create the database table:
mysql> CREATE TABLE Fails ( id int auto_increment, FailDate datetime, FailCount int, primary key(id) );
- Create the DB user that will both populate and read data from the DB:
mysql> GRANT ALL PRIVILEGES ON LoginFailures.* TO 'FailUser'@'localhost' IDENTIFIED BY 'create_a_complex_password_here'
Grafana:
- Create a new DataSource using that MySQL DB.
- Login to Grafana, select Data Sources, click "
+ Add data source
" - Complete the details for adding a data source, see the image below for an example.
- After the data source has been created, add a graph, call it whatever you'd like.
- Edit the graph, select the Data source you just created in step 4.
- After selecting the Data source, your query should look something like:
SELECT UNIX_TIMESTAMP(FailDate) as time_sec, FailCount as value, 'Failed Logins' as metric FROM Fails WHERE $__timeFilter(FailDate) ORDER BY FailDate ASC
- Click on the
Display
tab, and check 'Lines` (or bars, if you'd prefer vertical bars, see examples above.)
Shell Script:
- Copy the
loginfailures.sh
shell script from this repo to some directory on your server. - Update the contents of the shell script to connect to the correct db, table, and username/pass.
- Change the permissions on the script to allow execution (ex: chmod 755 loginfailures.sh)
- Update the root user's cron to regularly execute the loginfailures.sh script, or execute the script as a user that has sudo access.
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
- Doug Dobies - Initial work - deetoo
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details
- PurpleBooth for the excellent README template!