Skip to content

Commit

Permalink
added test for nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
yseto committed Aug 26, 2022
1 parent a7a9a17 commit f547b09
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mackerel-plugin-nginx/rule.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
nginx.connections.connections >=0
nginx.requests.accepts >=0
nginx.requests.handled >=0
nginx.requests.requests >=0
nginx.queue.reading >=0
nginx.queue.writing >=0
nginx.queue.waiting >=0
35 changes: 35 additions & 0 deletions mackerel-plugin-nginx/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh

prog=$(basename "$0")
if ! [ -S /var/run/docker.sock ]
then
echo "$prog: there are no running docker" >&2
exit 2
fi

cd "$(dirname "$0")" || exit
PATH=$(pwd):$PATH
plugin=$(basename "$(pwd)")
if ! which "$plugin" >/dev/null
then
echo "$prog: $plugin is not installed" >&2
exit 2
fi

image=nginx:1.23
port=20080

docker run --name "test-$plugin" -p $port:80 -v $(pwd)/testdata/nginx.conf:/etc/nginx/nginx.conf:ro -d $image
trap 'docker stop test-$plugin; docker rm test-$plugin; exit 1' 1 2 3 15
sleep 10

# to store previous value to calculate a diff of metrics
$plugin -port $port >/dev/null 2>&1
sleep 3

$plugin -port $port | graphite-metric-test -f rule.txt
status=$?

docker stop "test-$plugin"
docker rm "test-$plugin"
exit $status
44 changes: 44 additions & 0 deletions mackerel-plugin-nginx/testdata/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

server {
listen 80;
server_name localhost;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

location = /nginx_status {
stub_status;
}
}
}

0 comments on commit f547b09

Please sign in to comment.