@@ -1,6 +1,5 @@
/*-
* Copyright (c) 2007-2009 Linpro AS
- * Copyright (c) 2010 Varnish Software AS
* All rights reserved.
*
* Author: Cecilie Fritzvold <cecilihf@linpro.no>
@@ -26,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: check_varnish.c 5159 2010-08-30 12:54:07Z tfheen $
+ * $Id: check_varnish.c 4026 2009-04-03 21:54:25Z des $
*
* Nagios plugin for Varnish
*/
@@ -40,9 +39,8 @@
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
-#include <locale.h>
-#include "vsc.h"
+#include "shmlog.h"
#include "varnishapi.h"
static int verbose = 0;
@@ -165,7 +163,7 @@
* Check the statistics for the requested parameter.
*/
static void
-check_stats(const struct vsc_main *stats, char *param)
+check_stats(struct varnish_stats *VSL_stats, char *param)
{
const char *info;
struct timeval tv;
@@ -173,30 +171,36 @@
intmax_t value;
int status;
- if (strcmp(param, "ratio") == 0) {
- intmax_t total = stats->cache_hit + stats->cache_miss;
+ gettimeofday(&tv, NULL);
+ up = tv.tv_sec - VSL_stats->start_time;
+ if (strcmp(param, "uptime") == 0) {
+ value = up;
+ info = "Uptime";
+ }
+ else if (strcmp(param, "ratio") == 0) {
+ intmax_t total = VSL_stats->cache_hit + VSL_stats->cache_miss;
- value = total ? (100 * stats->cache_hit / total) : 0;
+ value = total ? (100 * VSL_stats->cache_hit / total) : 0;
info = "Cache hit ratio";
}
else if (strcmp(param, "usage") == 0) {
- intmax_t total = stats->sm_balloc + stats->sm_bfree;
+ intmax_t total = VSL_stats->sm_balloc + VSL_stats->sm_bfree;
- value = total ? (100 * stats->sm_balloc / total) : 0;
+ value = total ? (100 * VSL_stats->sm_balloc / total) : 0;
info = "Cache file usage";
}
-#define VSC_F_MAIN(n, t, l, f, e) \
+#define MAC_STAT(n, t, f, i, d) \
else if (strcmp(param, #n) == 0) { \
- value = stats->n; \
- info = e; \
+ value = VSL_stats->n; \
+ info = d; \
}
-#include "vsc_fields.h"
-#undef VSC_F_MAIN
+#include "stat_field.h"
+#undef MAC_STAT
else
printf("Unknown parameter '%s'\n", param);
status = check_thresholds(value);
- printf("VARNISH %s: %s (%'jd)|%s=%jd\n", status_text[status], info, value, param, value);
+ printf("VARNISH %s: %s|%s=%jd\n", status_text[status], info, param, value);
exit(status);
}
@@ -241,17 +245,11 @@
int
main(int argc, char **argv)
{
- struct VSM_data *vd;
+ struct varnish_stats *VSL_stats;
const char *n_arg = NULL;
- const struct vsc_main *VSC_main;
char *param = NULL;
int opt;
- setlocale(LC_ALL, "");
-
- vd = VSM_New();
- VSC_Setup(vd);
-
while ((opt = getopt(argc, argv, "c:hn:p:vw:")) != -1) {
switch (opt) {
case 'c':
@@ -262,7 +260,7 @@
help();
break;
case 'n':
- VSC_Arg(vd, opt, optarg);
+ n_arg = optarg;
break;
case 'p':
param = strdup(optarg);
@@ -279,11 +277,9 @@
}
}
- if (VSC_Open(vd, 1))
+ if ((VSL_stats = VSL_OpenStats(n_arg)) == NULL)
exit(1);
- VSC_main = VSC_Main(vd);
-
/* Default: if no param specified, check hit ratio. If no warning
* and critical values are specified either, set these to default.
*/
@@ -298,7 +294,7 @@
if (!param)
usage();
- check_stats(VSC_main, param);
+ check_stats(VSL_stats, param);
exit(0);
}
|