~eco-devx/charms/trusty/cassandra/trunk

« back to all changes in this revision

Viewing changes to files/check_cassandra_heap.sh

  • Committer: Marco Ceppi
  • Date: 2015-05-01 04:26:15 UTC
  • Revision ID: marco@ceppi.net-20150501042615-192dlldyt13wdjc3
port from bzr

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
# Copyright (C) 2012 Canonical Ltd.
 
3
# Author: Liam Young
 
4
#
 
5
# Script used to check Cassandra is alive and that it has space left in the heap
 
6
 
 
7
set -u
 
8
 
 
9
if [[ $# -lt 3 ]]; then
 
10
    echo "$0 <jmx-ipadress> <warnpct> <criticalpct>"
 
11
    exit 1
 
12
fi
 
13
WARN_PCT=$2
 
14
CRIT_PCT=$3
 
15
 
 
16
NODE_INF0="$(nodetool -h $1 info 2>/dev/null)"
 
17
if [[ $? -ne 0 ]]; then
 
18
    echo "ERROR: Failed to connect to Cassandra"
 
19
    exit 2
 
20
fi
 
21
PCT_USED=$(echo "$NODE_INF0" | awk 'BEGIN {FS=":"} $1 ~ /Heap Memory/ {print $2}' | awk '{ printf("%i\n", $1*100/$3) }')
 
22
USAGE_INFO="${PCT_USED}% of heap memory used"
 
23
if [[ $PCT_USED -lt $WARN_PCT ]]; then
 
24
    echo "OK: ${USAGE_INFO}"
 
25
    exit 0
 
26
elif [[ $PCT_USED -lt $CRIT_PCT ]]; then
 
27
    echo "WARNING: ${USAGE_INFO}"
 
28
    exit 1
 
29
else
 
30
    echo "CRITICAL: ${USAGE_INFO}"
 
31
    exit 1
 
32
fi