Skip to content

Instantly share code, notes, and snippets.

@Jo-Hue
Jo-Hue / define our queries
Created September 16, 2019 11:57
define our queries
cat << 'EOF' > /etc/zabbix/zabbix_agentd.conf.d/percentiles-discovery.json
cat percentiles-discovery.json
{"data":[
{
"{#PCTQUERY}": "nginx.access.url:*_count*", "{#PCTFIELD}":"nginx.access.request_time", "{#PCTRANGE}":"-1hour","{#PCTINDEX}":"filebeat-*",
"{#PCTNAME}": "ES _count query latencies last 1hour"},
{
"{#PCTQUERY}": "nginx.access.url:*_count*", "{#PCTFIELD}":"nginx.access.request_time", "{#PCTRANGE}":"-5mins","{#PCTINDEX}":"filebeat-*",
"{#PCTNAME}": "ES _count query latencies last 5 minutes"},
{
@Jo-Hue
Jo-Hue / new UserParameter
Created September 16, 2019 11:56
new UserParameter
cat << 'EOF' >> /etc/zabbix/zabbix_agentd.conf.d/elasticsearch.conf
UserParameter=elastic.discovery.percentiles, cat /etc/zabbix/zabbix_agentd.conf.d/percentiles-discovery.json
EOF
@Jo-Hue
Jo-Hue / create a user parameter file
Created September 16, 2019 11:31
create a user parameter file
cat << 'EOF' > /etc/zabbix/zabbix_agentd.conf.d/elasticsearch.conf
UserParameter=elastic.percentiles[*], /etc/zabbix/zabbix_agentd.conf.d/es-percentiles.sh "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
EOF
@Jo-Hue
Jo-Hue / test query
Created September 16, 2019 11:27
test query
./es-percentiles.sh "*" nginx.access.request_time -1hours
#=>
{
"1.0": 0,
"5.0": 0.0010000000474974513,
"25.0": 0.0010000000474974513,
"50.0": 0.0020000000949949026,
"75.0": 0.013000000268220901,
"95.0": 0.024000000208616257,
"99.0": 0.027000000700354576
@Jo-Hue
Jo-Hue / specify a query, the field, time range and index.
Created September 16, 2019 11:26
specify a query, the field, time range and index.
cd /etc/zabbix/zabbix_agentd.conf.d
curl https://raw.githubusercontent.com/FreekPaans/zabbix-configs/master/es-percentiles.sh > es-percentiles.sh
chmod +x es-percentiles.sh
@Jo-Hue
Jo-Hue / curl, e.g.
Created September 16, 2019 11:23
curl, e.g.
curl -s -d '{"size":0,"aggs":{"zabbix_aggregate":{"percentiles":{'\
'"field":"nginx.access.request_time",'\
'"percents":[50,99]}}}}' \
localhost:9200/*/_search -H "Content-type: application/json" | jq .
#=>
{
"took": 272,
"timed_out": false,
"num_reduce_phases": 3,
"_shards": {
@Jo-Hue
Jo-Hue / log data should now be getting indexed
Created September 11, 2019 15:38
log data should now be getting indexed
curl -s 'localhost:9200/filebeat-*/_search?size=1' | jq '.hits.hits[0]._source.nginx.access'
#=>
{
"response_code": "200",
"upstream": {
"connect_time": 0,
"response_time": 0.004,
"header_time": 0.004
},
"method": "GET",
@Jo-Hue
Jo-Hue / The complete filebeat.inputs section
Created September 11, 2019 15:27
The complete filebeat.inputs section
filebeat.inputs:
- type: log
enabled: false
paths:
- /var/log/*.log
- type: log
enabled: true
paths:
- /var/log/nginx/*upstream_time.log*
exclude_files: ['.gz$']
@Jo-Hue
Jo-Hue / add an input to the config
Created September 11, 2019 15:26
add an input to the config
- type: log
enabled: true
paths:
- /var/log/nginx/*upstream_time.log*
exclude_files: ['.gz$']
pipeline: nginx-response-time
@Jo-Hue
Jo-Hue / upstream_time log format
Created September 11, 2019 15:24
upstream_time log format
cat << EOF > pipeline.json
{
"description": "pipeline for parsing nginx response times",
"processors": [
{
"set": {
"field": "log_line",
"value": "{{message}}"
}
},