Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test #923

Merged
merged 5 commits into from Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions mackerel-plugin-memcached/rule.txt
@@ -0,0 +1,27 @@
memcached.cmd.cmd_get >=0
memcached.cmd.cmd_set >=0
memcached.cmd.cmd_flush >=0
memcached.cmd.cmd_touch >=0
memcached.hitmiss.get_hits >=0
memcached.hitmiss.get_misses >=0
memcached.hitmiss.delete_hits >=0
memcached.hitmiss.delete_misses >=0
memcached.hitmiss.incr_hits >=0
memcached.hitmiss.incr_misses >=0
memcached.hitmiss.cas_hits >=0
memcached.hitmiss.cas_misses >=0
memcached.hitmiss.touch_hits >=0
memcached.hitmiss.touch_misses >=0
memcached.rusage.rusage_user >=0
memcached.rusage.rusage_system >=0
memcached.cachesize.limit_maxbytes >=0
memcached.cachesize.bytes >=0
memcached.connections.curr_connections >=0
memcached.evictions.evictions >=0
memcached.evictions.reclaimed >=0
memcached.unfetched.expired_unfetched >=0
memcached.unfetched.evicted_unfetched >=0
memcached.bytes.bytes_read >=0
memcached.bytes.bytes_written >=0
memcached.items.curr_items >=0
memcached.items.new_items >=0
35 changes: 35 additions & 0 deletions mackerel-plugin-memcached/test.sh
@@ -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=memcached:1.6
port=21211

docker run --name "test-$plugin" -p $port:11211 -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 1

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

docker stop "test-$plugin"
docker rm "test-$plugin"
exit $status
7 changes: 7 additions & 0 deletions mackerel-plugin-nginx/rule.txt
@@ -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
@@ -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 1

$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
@@ -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;
}
}
}
4 changes: 4 additions & 0 deletions mackerel-plugin-plack/rule.txt
@@ -0,0 +1,4 @@
plack.workers.busy_workers >=0
plack.workers.idle_workers >=0
plack.req.requests >=0
plack.bytes.bytes_sent >=0
37 changes: 37 additions & 0 deletions mackerel-plugin-plack/test.sh
@@ -0,0 +1,37 @@
#!/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=local/test-$plugin
port=5000

docker build -t $image testdata/

docker run --name "test-$plugin" -p $port:5000 -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 1

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

docker stop "test-$plugin"
docker rm "test-$plugin"
exit $status
14 changes: 14 additions & 0 deletions mackerel-plugin-plack/testdata/Dockerfile
@@ -0,0 +1,14 @@
FROM perl:5.36

COPY . /usr/src/myapp
WORKDIR /usr/src/myapp

RUN cpm install -v

EXPOSE 5000

ENV PERL5LIB /usr/src/myapp/local/lib/perl5
ENV PATH $PATH:/usr/src/myapp/local/bin/

CMD [ "plackup", "app.psgi" ]

20 changes: 20 additions & 0 deletions mackerel-plugin-plack/testdata/app.psgi
@@ -0,0 +1,20 @@
#!/usr/bin/env perl

use strict;
use warnings;
use utf8;

use Plack::Builder;

builder {
enable "Plack::Middleware::ServerStatus::Lite",
path => '/server-status',
allow => [ '0.0.0.0/0' ],
counter_file => '/tmp/counter_file',
scoreboard => '/var/run/server';

sub {
[200, ["Content-Type" => "text/plain"], "ok"];
}
};

2 changes: 2 additions & 0 deletions mackerel-plugin-plack/testdata/cpanfile
@@ -0,0 +1,2 @@
requires "Plack", ">= 1.0048";
requires "Plack::Middleware::ServerStatus::Lite", "0.36";
2 changes: 2 additions & 0 deletions mackerel-plugin-snmp/rule.txt
@@ -0,0 +1,2 @@
snmp.hrSystemNumUsers >=0
snmp.hrSystemProcesses >=0
34 changes: 34 additions & 0 deletions mackerel-plugin-snmp/test.sh
@@ -0,0 +1,34 @@
#!/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=local/test-$plugin
# mackerel-plugin-snmp is disallowed --port option.
port=161

docker build -t $image testdata/

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

$plugin '.1.3.6.1.2.1.25.1.5.0:hrSystemNumUsers:0:0' '.1.3.6.1.2.1.25.1.6.0:hrSystemProcesses:0:0' | graphite-metric-test -f rule.txt
status=$?

docker stop "test-$plugin"
docker rm "test-$plugin"
exit $status
8 changes: 8 additions & 0 deletions mackerel-plugin-snmp/testdata/Dockerfile
@@ -0,0 +1,8 @@
FROM alpine:3.16

RUN apk add --update net-snmp net-snmp-tools

EXPOSE 161

CMD ["snmpd", "-V", "-f", "-c", "/etc/snmp/snmpd.conf"]

4 changes: 4 additions & 0 deletions mackerel-plugin-snmp/testdata/snmpd.conf
@@ -0,0 +1,4 @@
view systemonly included .1.3.6.1.2.1.1
view systemonly included .1.3.6.1.2.1.25.1

rocommunity public default -V systemonly
14 changes: 14 additions & 0 deletions mackerel-plugin-squid/rule.txt
@@ -0,0 +1,14 @@
squid.cache_storage_usage.swap_used_ratio >=0
squid.cache_storage_usage.memory_used_ratio >=0
squid.file_descriptor_usage.total_fd >=0
squid.file_descriptor_usage.max_fd >=0
squid.file_descriptor_usage.current_fd >=0
squid.file_descriptor_usage.avail_fd >=0
squid.file_descriptor_usage.reserved_fd >=0
squid.file_descriptor_usage.open_files >=0
squid.file_descriptor_usage.queued_files >=0
squid.memory_account_for.memory_poll_alloc >=0
squid.memory_account_for.memory_poll_free >=0
squid.requests.requests >=0
squid.cache_hit_ratio.5min.request_ratio >=0
squid.cpu_usage_ratio.5min.cpu_usage >=0
35 changes: 35 additions & 0 deletions mackerel-plugin-squid/test.sh
@@ -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=ubuntu/squid:5.2-22.04_beta
port=13128

docker run --name "test-$plugin" -p $port:3128 -v $(pwd)/testdata/squid.conf:/etc/squid/squid.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 1

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

docker stop "test-$plugin"
docker rm "test-$plugin"
exit $status
16 changes: 16 additions & 0 deletions mackerel-plugin-squid/testdata/squid.conf
@@ -0,0 +1,16 @@
acl localnet src 0.0.0.1-0.255.255.255 # RFC 1122 "this" network (LAN)
acl localnet src 10.0.0.0/8 # RFC 1918 local private network (LAN)
acl localnet src 100.64.0.0/10 # RFC 6598 shared address space (CGN)
acl localnet src 169.254.0.0/16 # RFC 3927 link-local (directly plugged) machines
acl localnet src 172.16.0.0/12 # RFC 1918 local private network (LAN)
acl localnet src 192.168.0.0/16 # RFC 1918 local private network (LAN)
acl localnet src fc00::/7 # RFC 4193 local private network range
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines

http_access allow localnet manager
http_access deny manager

http_access allow localnet
http_access deny all

http_port 3128