Horizon: Export metrics / status in prometheus scrape-able format

Created on 21 Dec 2018  路  13Comments  路  Source: laravel/horizon

Bit of a feature request. We're using docker/kubernetes more and more in our environment and Prometheus seems to be the default & recommended stats/health-check system to use. So it would be really nice to be able to scrape the metrics horizon already gathers in a prometheus-friendly format.

I'd be happy to try and work on a PR if it's something people would find useful & might be accepted :-)

Most helpful comment

All 13 comments

I would use that. I don't know about Prometheus but a JSON response of at least the same metrics that are on the Dashboard page would be nice.

Heya, thanks for suggesting this but I don't think we're going to be adding support for any external vendors like this. If we do there's really not telling which one is the next one. You may create your own package for this.

@driesvints ah - ok. Is there any possibility of the keys etc that horizon uses being documented? If not then maintaining a package becomes a bit onerous. I'm happy to do it - but if it means constantly checking the source code of horizon for changes then that gets a bit grim :-/

@ohnotnow I'm not sure if we should document anything outside the public api tbh...

@driesvints ah, ok. Is the public api documented? Or is it just a case of tracking all the source code?

@ohnotnow here are the docs: https://laravel.com/docs/5.7/horizon

@driesvints ah- I was thinking more the public api for getting the metrics rather than how to run Horizon. If it鈥檚 not a goer just let me know and I can use a different solution :-) It鈥檇 be nice to use horizon, but if there鈥檚 no interest in kubernetes/GKE/EKS/AKS etc then I don鈥檛 want to use up your time - I鈥檓 sure you鈥檝e got better things to do :-)

@ohnotnow ah sorry, misunderstood you. No there's no api documentation like the one for laravel/framework.

@driesvints no worries :-) I鈥檒l look elsewhere for queue stuff :-) Have a good Xmas - thanks for all your efforts on the issues :-) Much appreciated :-)

We've simply looked at the keys and how the queues are structured and derived some simple redis commands which can graph each queue.

This is a script, called via collect infrastructure, which reports the size for each listed queue and the total:

#!/usr/bin/env bash

HOSTNAME="${COLLECTD_HOSTNAME:-`hostname -f`}"
INTERVAL="${COLLECTD_INTERVAL:-10}"
REDIS_HOST="${REDIS_HOST:-localhost}"
REDIS_PORT="${REDIS_PORT:-6379}"
REDIS_DB="${REDIS_DB:-0}"

# Given a Laravel queue name, it reports it's total size back on stdout
#
# Based on the Laravel implementation, see https://github.com/laravel/framework/blob/f21e942ae8a4104ffdf42c231601efe8759c4c10/src/Illuminate/Queue/LuaScripts.php#L19
laravel_queue_size() {
  local QUEUE_NAME=$1

  redis-cli \
    -h $REDIS_HOST \
    -p $REDIS_PORT \
    -n $REDIS_DB \
    eval \
    "return redis.call('llen', KEYS[1]) + redis.call('zcard', KEYS[2]) + redis.call('zcard', KEYS[3])" \
    3 \
    "queues:$QUEUE_NAME" "queues:$QUEUE_NAME:delayed" "queues:$QUEUE_NAME:reserved" \
    | sed 's/[^[:alnum:]]\+//g'
}

putval() {
  local NAME=$1
  local SIZE=$2

  if [[ -z "$SIZE" ]]; then
    SIZE=$(laravel_queue_size $NAME)
    TOTAL=$(($TOTAL + $SIZE))
  fi

  echo "PUTVAL $HOSTNAME/laravel_queue-$NAME/gauge-$NAME interval=$INTERVAL N:$SIZE"
}

while sleep "$INTERVAL"; do
  TOTAL=0
  putval queue1
  putval queue2
  putval total $TOTAL
done

HTH

@mfn thanks for that :-) depending how drunk/lazy I am over the holidays I might put something together :-)

@LKaemmerling wow - thanks for that! I got side-tracked this year just getting our container stuff set up - this fell by the wayside :-/ Thanks for stepping up! :-D

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wturrell picture wturrell  路  5Comments

francislavoie picture francislavoie  路  5Comments

etiennellipse picture etiennellipse  路  3Comments

Pustiu picture Pustiu  路  5Comments

crash13override picture crash13override  路  5Comments