Skip to content

Commit f100a90

Browse files
author
Markus Opolka
authored
Rewrite in Golang (#47)
* Move Ruby implementation to legacy * Initial Commit of Golang Implementation * Add README.md * Add reloads to pipeline perfdata * Update golangci config
1 parent b28a8f6 commit f100a90

34 files changed

+3116
-201
lines changed

.github/dependabot.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: gomod
4+
directory: "/"
5+
schedule:
6+
interval: weekly
7+
time: '10:00'
8+
open-pull-requests-limit: 10

.github/workflows/acceptance.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Go
2+
on:
3+
push:
4+
branches: [ main ]
5+
tags:
6+
- v*
7+
pull_request:
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Check out code into the Go module directory
15+
uses: actions/checkout@v1
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: 1.19
23+
24+
- name: Test
25+
run: go test -v ./...
26+
27+
- name: Build
28+
run: go build -v .
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
branches:
7+
- main
8+
pull_request:
9+
10+
jobs:
11+
golangci:
12+
name: lint
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: golangci-lint
18+
uses: golangci/golangci-lint-action@v2

.github/workflows/rake.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.gitignore

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,6 @@
1-
*.gem
2-
*.rbc
3-
/.config
4-
/coverage/
5-
/InstalledFiles
6-
/pkg/
7-
/spec/reports/
8-
/spec/examples.txt
9-
/test/tmp/
10-
/test/version_tmp/
11-
/tmp/
12-
13-
# Used by dotenv library to load environment variables.
14-
# .env
15-
16-
## Specific to RubyMotion:
17-
.dat*
18-
.repl_history
19-
build/
20-
*.bridgesupport
21-
build-iPhoneOS/
22-
build-iPhoneSimulator/
23-
24-
## Specific to RubyMotion (use of CocoaPods):
25-
#
26-
# We recommend against adding the Pods directory to your .gitignore. However
27-
# you should judge for yourself, the pros and cons are mentioned at:
28-
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29-
#
30-
# vendor/Pods/
31-
32-
## Documentation cache and generated files:
33-
/.yardoc/
34-
/_yardoc/
35-
/doc/
36-
/rdoc/
37-
38-
## Environment normalization:
39-
/.bundle/
40-
/vendor/bundle
41-
/lib/bundler/man/
42-
43-
# for a library or gem, you might want to ignore these files since the code is
44-
# intended to run in multiple environments; otherwise, check them in:
45-
# Gemfile.lock
46-
# .ruby-version
47-
# .ruby-gemset
48-
49-
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50-
.rvmrc
1+
.idea
2+
check_logstash
3+
vendor/
4+
tmp/
5+
coverage.html
6+
coverage.out

.golangci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
run:
2+
timeout: 5m
3+
skip-files:
4+
- '(.+)_test\.go'
5+
- 'internal/config/http_config.go'
6+
- 'internal/config/config.go'
7+
8+
linters:
9+
disable-all: false
10+
enable:
11+
- funlen
12+
- dogsled
13+
- dupl
14+
# - lll
15+
- whitespace
16+
- wsl
17+
- exportloopref
18+
disable:
19+
- scopelint
20+
- bodyclose
21+
- contextcheck
22+
- nilerr
23+
- noctx
24+
- rowserrcheck
25+
- sqlclosecheck
26+
- structcheck
27+
- unparam
28+
presets:
29+
- bugs
30+
- unused
31+
# - style
32+
fast: false

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.PHONY: test coverage lint vet
2+
3+
build:
4+
go build
5+
lint:
6+
go fmt $(go list ./... | grep -v /vendor/)
7+
vet:
8+
go vet $(go list ./... | grep -v /vendor/)
9+
test:
10+
go test -v -cover ./...
11+
coverage:
12+
go test -v -cover -coverprofile=coverage.out ./... &&\
13+
go tool cover -html=coverage.out -o coverage.html

README.md

Lines changed: 77 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,102 @@
1-
# check_logstash #
1+
# check_logstash
22

3-
[![Rake](https://github.com/NETWAYS/check_logstash/workflows/Rake%20Tests/badge.svg)](https://github.com/NETWAYS/check_logstash/actions?query=workflow%3A%22Rake+Tests%22) [![Acceptance Tests](https://github.com/NETWAYS/check_logstash/workflows/Acceptance%20Tests/badge.svg)](https://github.com/NETWAYS/check_logstash/actions?query=workflow%3A%22Acceptance+Tests%22)
3+
An Icinga check plugin to check Logstash.
44

5-
A monitoring plugin for Icinga (2), Nagios, Shinken, Naemon, etc. to check the Logstash API (Logstash v.5+)
5+
## Usage
66

7-
**A word of warning** Be sure to read the configuration check part of this readme since there is a problem with this feature in past releases of Logstash.
7+
```bash
8+
Usage:
9+
check_logstash [flags]
10+
check_logstash [command]
811

9-
## Usage ##
12+
Available Commands:
13+
health Checks the health of the Logstash server
14+
pipeline Checks the status of the Logstash Pipelines
1015

11-
### Options ###
16+
Flags:
17+
-H, --hostname string Hostname of the Logstash server (default "localhost")
18+
-p, --port int Port of the Logstash server (default 9600)
19+
-s, --secure Use a HTTPS connection
20+
-i, --insecure Skip the verification of the server's TLS certificate
21+
-b, --bearer string Specify the Bearer Token for server authentication
22+
-u, --user string Specify the user name and password for server authentication <user:password>
23+
--ca-file string Specify the CA File for TLS authentication
24+
--cert-file string Specify the Certificate File for TLS authentication
25+
--key-file string Specify the Key File for TLS authentication
26+
-t, --timeout int Timeout in seconds for the CheckPlugin (default 30)
27+
-h, --help help for check_logstash
28+
-v, --version version for check_logstash
29+
```
1230
13-
-H HOST Logstash host
14-
-p, --hostname PORT Logstash API port
15-
--file-descriptor-threshold-warn WARN
16-
The percentage relative to the process file descriptor limit on which to be a warning result.
17-
--file-descriptor-threshold-crit CRIT
18-
The percentage relative to the process file descriptor limit on which to be a critical result.
19-
--heap-usage-threshold-warn WARN
20-
The percentage relative to the heap size limit on which to be a warning result.
21-
--heap-usage-threshold-crit CRIT
22-
The percentage relative to the heap size limit on which to be a critical result.
23-
--cpu-usage-threshold-warn WARN
24-
The percentage of CPU usage on which to be a warning result.
25-
--cpu-usage-threshold-crit CRIT
26-
The percentage of CPU usage on which to be a critical result.
27-
--inflight-events-warn WARN Threshold for inflight events to be a warning result. Use min:max for a range.
28-
--inflight-events-crit CRIT Threshold for inflight events to be a critical result. Use min:max for a range.
29-
-h, --help Show this message
31+
### Health
3032
33+
Checks the health status of the Logstash server.
3134
32-
### Using default values ###
35+
```bash
36+
Usage:
37+
check_logstash health [flags]
3338
34-
./check_logstash.rb -H [logstashhost]
35-
36-
### Using your own thresholds ###
39+
Examples:
3740
38-
./check_logstash.rb -H 127.0.0.1 --file-descriptor-threshold-warn 40 --file-descriptor-threshold-crit 50 --heap-usage-threshold-warn 10 --heap-usage-threshold-crit 20
41+
$ check_logstash health --hostname 'localhost' --port 8888 --insecure
42+
OK - Logstash is healthy | status=green process.cpu.percent=0;0.5;3;0;100
43+
\_[OK] Heap usage at 12.00%
44+
\_[OK] Open file descriptors at 12.00%
45+
\_[OK] CPU usage at 5.00%
3946
40-
or
47+
$ check_logstash -p 9600 health --cpu-usage-threshold-warn 50 --cpu-usage-threshold-crit 75
48+
WARNING - CPU usage at 55.00%
49+
\_[OK] Heap usage at 12.00%
50+
\_[OK] Open file descriptors at 12.00%
51+
\_[WARNING] CPU usage at 55.00%
4152
42-
./check_logstash.rb -H 127.0.0.1 --inflight-events-warn 5 --inflight-events-crit 1:10
53+
Flags:
54+
--file-descriptor-threshold-warn string The percentage relative to the process file descriptor limit on which to be a warning result (default "100")
55+
--file-descriptor-threshold-crit string The percentage relative to the process file descriptor limit on which to be a critical result (default "100")
56+
--heap-usage-threshold-warn string The percentage relative to the heap size limit on which to be a warning result (default "70")
57+
--heap-usage-threshold-crit string The percentage relative to the heap size limit on which to be a critical result (default "80")
58+
--cpu-usage-threshold-warn string The percentage of CPU usage on which to be a warning result (default "100")
59+
--cpu-usage-threshold-crit string The percentage of CPU usage on which to be a critical result (default "100")
60+
-h, --help help for health
61+
```
4362
44-
## Sample Output ##
63+
### Pipeline
4564
46-
### With default values ###
65+
Checks the status of Logstash pipelines.
4766
48-
OK - Logstash looking healthy. | process.cpu.percent=0;;;0;100 mem.heap_used_percent=18;70;80;0;100 jvm.threads.count=23;;;0; process.open_file_descriptors=46;3400;3800;0;4096 pipeline.events.out=166c;;;0; inflight_events=0;;;0;
49-
OK: Inflight events: 0
50-
OK: Heap usage at 18.00% (382710568 out of 2077753344 bytes in use)
51-
OK: Open file descriptors at 1.12%. (46 out of 4096 file descriptors are open)
67+
```bash
68+
Usage:
69+
check_logstash pipeline [flags]
5270
53-
### With thresholds set ###
71+
Examples:
5472
55-
CRITICAL - Logstash is unhealthy - CRITICAL: Inflight events: 0 | process.cpu.percent=0;;;0;100 mem.heap_used_percent=16;70;80;0;100 jvm.threads.count=23;;;0; process.open_file_descriptors=46;3400;3800;0;4096 pipeline.events.out=164c;;;0; inflight_events=0;5;10;0;
56-
CRITICAL: Inflight events: 0
57-
OK: Heap usage at 16.00% (352959904 out of 2077753344 bytes in use)
58-
OK: Open file descriptors at 1.12%. (46 out of 4096 file descriptors are open)
73+
$ check_logstash pipeline --inflight-events-warn 5 --inflight-events-crit 10
74+
WARNING - Inflight events
75+
\_[WARNING] inflight_events_example-input:9;
76+
\_[OK] inflight_events_example-default-connector:4
5977
60-
## Finding viable thresholds ##
78+
$ check_logstash pipeline --inflight-events-warn 5 --inflight-events-crit 10 --pipeline example
79+
CRITICAL - Inflight events
80+
\_[CRITICAL] inflight_events_example:15
6181
62-
To set your thresholds for inflight events to a sensible value use baselining. Don't set thresholds from the beginning but let Graphite or other graphers create graphs for inflight events. Just add some percent to what Logstash usually processes and set this as threshold. Or use the `generator` plugin to put as many events through your Elastic stack as possible. Use some percent (e.g. 90%) from this maximum as a threshold. Keep in mind that changing your configuration might change the maximum inflight events.
82+
Flags:
83+
-P, --pipeline string Pipeline Name (default "/")
84+
--inflight-events-warn string Warning threshold for inflight events to be a warning result. Use min:max for a range.
85+
--inflight-events-crit string Critical threshold for inflight events to be a critical result. Use min:max for a range.
86+
-h, --help help for pipeline
87+
```
6388
64-
### Configuration check ###
6589
66-
Logstash 5.0 can automatically reload changed configuration from disk. This plugin checks if the last reload succeeded or failed. Unfortunately the first release of Logstash 5.0 does not provide a way to show that it recovered from an invalid configuration. If you had an error, the plugin will still show that there is a problem with the configuration even when this is already fixed. There is already an issue with Logstash pending to fix this behaviour: https://github.com/elastic/logstash/issues/6149
90+
## License
6791
68-
## Default values ##
92+
Copyright (c) 2022 [NETWAYS GmbH](mailto:[email protected])
6993
70-
There are some default values defined in the plugin. Some values are merely put out as performance data and some are normally used for performance data but can be checked against thresholds.
94+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
95+
License as published by the Free Software Foundation, either version 3 of the License, or
96+
(at your option) any later version.
7197
72-
### Checks with defaults ###
98+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
99+
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
73100
74-
* `-H`: 127.0.0.1
75-
* `-p`: 9600
76-
* `--file-descriptor-threshold-warn` : 85
77-
* `--file-descriptor-threshold-warn` : 95
78-
* `--heap-usage-threshold-warn` : 70
79-
* `--heap-usage-threshold-warn` : 80
80-
81-
### Optionally checked ###
82-
83-
* `--cpu-usage-threshold-warn`
84-
* `--cpu-usage-threshold-crit`
85-
* `--inflight-events-warn`
86-
* `--inflight-events-crit`
87-
88-
## Building ##
89-
90-
While `check_logstash` is the finished plugin you can use, you might want to change something and rebuild the script.
91-
92-
Simply issue the `rake` command (if you have Rake installed) and it will run tests (and rubocop when all cops are pleased) and create the script from the library files. *Don't change the `check_logstash` file since it will be overwritten by Rake, change the files in `lib/` instead.
101+
You should have received a copy of the GNU General Public License along with this program. If not,
102+
see [gnu.org/licenses](https://www.gnu.org/licenses/).

0 commit comments

Comments
 (0)