Skip to content

Commit

Permalink
doc: added comments and guides
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Vriesman <[email protected]>
  • Loading branch information
glvr182 committed Jun 5, 2020
1 parent 2946c8f commit 5680843
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
71 changes: 69 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,70 @@
### F2B-Exporter
# F2B-Exporter

This is a simple Fail2Ban prometheus exporter
[![GoDoc](https://godoc.org/github.com/glvr182/f2b-exporter?status.svg)](https://godoc.org/github.com/glvr182/f2b-exporter)
[![GitHub tag](https://img.shields.io/github/tag/glvr182/f2b-exporter.svg)]()
![Docker Image Size (latest by date)](https://img.shields.io/docker/image-size/glvr182/f2b-exporter)
![Docker Image Version (latest by date)](https://img.shields.io/docker/v/glvr182/f2b-exporter)

This is a simple Fail2Ban prometheus exporter

## Installation

### From source
You can clone this repository from git `https://github.com/glvr182/f2b-exporter.git`.
Then all you have to do is run `go build` and you're done!

### Docker
Using the following command you can run this program with docker.
NOTE: When running the docker image you might want to mount the certificates since some remotes use TLS.
```
docker run \
-d \
--name f2b-exporter \
-v /var/lib/fail2ban/fail2ban.sqlite3:/var/lib/fail2ban/fail2ban.sqlite3 \
-v /etc/ssl/certs:/etc/ssl/certs \
glvr182/f2b-exporter
```
Depending on your deployment you might want to expose the configured port (default 8080) like this:
```
docker run \
-d \
-p 8080:8080 \
--name f2b-exporter \
-v /var/lib/fail2ban/fail2ban.sqlite3:/var/lib/fail2ban/fail2ban.sqlite3 \
-v /etc/ssl/certs:/etc/ssl/certs \
glvr182/f2b-exporter
```

## Configuration
The exporter has a few settings that you can tweak using the cli or using env variables:
| cli | env | default |
|------------|--------------|------------------------------------|
| --port | F2B_PORT | 8080 |
| --database | F2B_DATABASE | /var/lib/fail2ban/fail2ban.sqlite3 |
| --remote | F2B_REMOTE | freeGeoIP |

To add the exporter to prometheus a simple config like this would do the trick:
NOTE: this is from prometheus, NOT for this exporter.
```
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'f2b-exporter'
scrape_interval: 5s
static_configs:
- targets: ['localhost:8080']
```
Or using docker and a dedicated network:
```
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'f2b-exporter'
scrape_interval: 5s
static_configs:
- targets: ['f2b-exporter:8080']
```
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func main() {
}
}

// update refreshes the prometheus metrics
func update() error {
db, err := sqlittle.Open(viper.GetString("database"))
if err != nil {
Expand All @@ -95,6 +96,7 @@ func update() error {
return nil
}

// jailed is a helper function which fetches all the prisoners in the given database
func jailed(db *sqlittle.DB, provider provider.Provider) ([]prisoner, error) {
var (
prisoners []prisoner
Expand Down

0 comments on commit 5680843

Please sign in to comment.