...
 
Commits (8)
......@@ -28,7 +28,7 @@ AC_ARG_WITH([rst2man],
m4_ifndef([VARNISH_PREREQ], AC_MSG_ERROR([Need varnish.m4 -- see README.rst]))
VARNISH_PREREQ([5.2])
VARNISH_PREREQ([5.1], [5.3])
VARNISH_VMODS([weightadjust])
VMOD_TESTS="$(cd $srcdir/src && echo tests/*.vtc)"
......
<?php
exec('uptime', $output);
// get result
$load = [0 => 0];
if (preg_match('/average: ([0-9]+\.[0-9]{2}), ([0-9]+\.[0-9]{2}), ([0-9]+\.[0-9]{2})$/', $output[0], $result)) {
$load[0] = (float)$result[1];
$load[1] = (float)$result[2];
$load[2] = (float)$result[3];
}
if ($load[0] < 0.5) {
$currentLoad = 100;
}
elseif ($load[0] < 0.7) {
$currentLoad = 95;
}
elseif ($load[0] < 1.0) {
$currentLoad = 90;
}
elseif ($load[0] < 1.5) {
$currentLoad = 80;
}
elseif ($load[0] < 2.0) {
$currentLoad = 70;
}
elseif ($load[0] < 2.5) {
$currentLoad = 60;
}
elseif ($load[0] < 3.5) {
$currentLoad = 50;
}
elseif ($load[0] < 4.5) {
$currentLoad = 50;
}
elseif ($load[0] < 5.0) {
$currentLoad = 40;
}
elseif ($load[0] < 6.0) {
$currentLoad = 30;
}
elseif ($load[0] < 7.0) {
$currentLoad = 20;
}
elseif ($load[0] < 8.0) {
$currentLoad = 10;
}
else {
$currentLoad = 1;
}
header('X-Weight: '.number_format($currentLoad, 2));
echo @php_uname('n') . "\r\n" . 'Weight: '.$currentLoad;
......@@ -17,6 +17,9 @@ nodist_libvmod_weightadjust_la_SOURCES = \
vcc_weightadjust_if.c \
vcc_weightadjust_if.h
vmod_weightadjust.lo: vcc_weightadjust_if.h
random.lo: vcc_weightadjust_if.h
dist_man_MANS = vmod_weightadjust.3
@BUILD_VMOD_WEIGHTADJUST@
......
/*-
* Copyright 2017 UPLEX Nils Goroll Systemoptimierung
*
* code taken from varnish-cache bin/varnishd/cache/cache_backend_probe.c:
* Portions Copyright (c) 2006 Verdens Gang AS
* Portions Copyright (c) 2006-2011 Varnish Software AS
*
* code taken from lib/libvmod_directors/random.c:
* Portions Copyright (c) 2013-2015 Varnish Software AS
*
......@@ -50,15 +46,14 @@
#include "cache/cache.h"
#include "vrt.h"
#include "vcl.h"
#include "vrt.h"
#include "vre.h"
#include "vsa.h"
#include "vtim.h"
#include "vtcp.h"
#include "vsb.h"
#include "waiter/waiter.h"
#include "cache/cache_director.h"
#include "cache/cache_backend.h"
......
#
# Copyright YOU (c) 1900.
#
# (vmodtool requires this format.)
#
#-
# This document is copyright and licensed under the same conditions as
# the libvmod-weightadjust project. See LICENSE for details.
$Module weightadjust 3 Weightadjust VMOD
......
/*-
* Copyright 2017 UPLEX Nils Goroll Systemoptimierung
*
* code taken from varnish-cache bin/varnishd/cache/cache_backend_probe.c:
* Portions Copyright (c) 2006 Verdens Gang AS
* Portions Copyright (c) 2006-2011 Varnish Software AS
*
* All rights reserved.
*
* Author: Nils Goroll <nils.goroll@uplex.de>
......@@ -41,6 +45,7 @@
#include "cache/cache.h"
#include "vcl.h"
#include "vrt.h"
#include "vre.h"
#include "vsa.h"
......@@ -48,7 +53,6 @@
#include "vtcp.h"
#include "vrnd.h"
#include "waiter/waiter.h"
#include "cache/cache_director.h"
#include "cache/cache_backend.h"
......