diff --git a/README.md b/README.md index bf29c99..f6d0ffb 100644 --- a/README.md +++ b/README.md @@ -37,46 +37,68 @@ Use pip: ## Usage - Usage: check-measurement [OPTIONS] COMMAND1 [ARGS]... - + Usage: check-measurement [OPTIONS1] COMMAND [OPTIONS2|OPTIONS3]... + Command line entry point. Defines common arguments. - - Options: - -v, --verbose + + Options 1: + -v, --verbose Can be specified multiple times for increasing verbosity --hostname TEXT InfluxDB hostname --port INTEGER InfluxDB port --username TEXT InfluxDB usernanme --password TEXT InfluxDB password - --database TEXT InfluxDB database name + --database TEXT InfluxDB database name, default 'telegraf' --count-error-range TEXT Range of measurement counts that are NOT considered an error --count-warning-range TEXT Range of measurement counts that are NOT considered a warning --mean-error-range TEXT Range of measurement means that are NOT considered an error - --mean-warning-range TEXT Range of measurement counts that are NOT + --mean-warning-range TEXT Range of measurement means that are NOT considered a warning --timeout INTEGER Timeout in seconds for connecting to InfluxDB --help Show this message and exit. - + Commands: query Run an explicit query. single Run a query for a single measurement. - - check-measurement [OPTIONS] single [OPTIONS] MEASUREMENT HOSTNAME - + + Usage1: check-measurement [OPTIONS1] single [OPTIONS2] MEASUREMENT HOSTNAME + Run a query for a single measurement. - - Options: + + Options 2: --age TEXT --where TEXT Extra where conditions to include. --field TEXT --help Show this message and exit. + + Usage2 : check-measurement [OPTIONS1] query [OPTIONS3] QUERY + + Run an explicit query. + + Options 3: + --help Show this message and exit. +## Examples - Usage: check-measurement query [OPTIONS] QUERY +### Run a query for a single measurement +Run a query for a `cpu` measurement `cpu-total` the field value `usage_iowait` filtered for host `yourhost`.The options used before the `single` command and after the `single` command can not be switched. - Run an explicit query. + $./check-measurement --mean-error-range 10 --mean-warning-range 5 single \ + --field usage_iowait --where cpu='cpu-total' --age 2m cpu yourhost + +Output: + + MEASUREMENTS OK - cpu is [0.2507941815741449, 0.21819402484046085, 0.19283977530009686, 0.3185247275776435] | count=4;2:;1: mean=0.24508817732308652;5;10 + +### Run an explicit query +Run an explicit query `SELECT time, usage_iowait FROM cpu WHERE time > now() - 2m AND host = 'mo4' AND cpu = 'cpu-total'` + + $./check-measurement --mean-error-range 10 --mean-warning-range 5 query \ + "SELECT time, usage_iowait FROM cpu WHERE time > now() - 2m AND host = 'yourhost' AND cpu = 'cpu-total'" + +Output: + + MEASUREMENTS OK - cpu is [0.2507941815741449, 0.21819402484046085, 0.19283977530009686, 0.3185247275776435] | count=4;2:;1: mean=0.24508817732308652;5;10 - Options: - --help Show this message and exit. diff --git a/influxdbnagiosplugin/main.py b/influxdbnagiosplugin/main.py index 78bbabb..a1264aa 100644 --- a/influxdbnagiosplugin/main.py +++ b/influxdbnagiosplugin/main.py @@ -15,16 +15,16 @@ @group(chain=True) -@option("-v", "--verbose", count=True) +@option("-v", "--verbose", count=True, help="Can be specified multiple times for increasing verbosity") @option("--hostname", default="localhost", help="InfluxDB hostname") @option("--port", default=8086, help="InfluxDB port") @option("--username", default="influxdb", help="InfluxDB usernanme") @option("--password", default="secret", help="InfluxDB password") -@option("--database", default="telegraf", help="InfluxDB database name") +@option("--database", default="telegraf", help="InfluxDB database name, default \'telegraf\'") @option("--count-error-range", default="1:", help="Range of measurement counts that are NOT considered an error") # noqa @option("--count-warning-range", default="2:", help="Range of measurement counts that are NOT considered a warning") # noqa @option("--mean-error-range", default="", help="Range of measurement means that are NOT considered an error") # noqa -@option("--mean-warning-range", default="", help="Range of measurement counts that are NOT considered a warning") # noqa +@option("--mean-warning-range", default="", help="Range of measurement means that are NOT considered a warning") # noqa @option("--timeout", default=5, help="Timeout in seconds for connecting to InfluxDB") def main(**kwargs): """ diff --git a/influxdbnagiosplugin/resources.py b/influxdbnagiosplugin/resources.py index 593af9b..3e2babc 100644 --- a/influxdbnagiosplugin/resources.py +++ b/influxdbnagiosplugin/resources.py @@ -43,7 +43,7 @@ def probe(self): Query InfluxDB; yield the count and mean of the measurements. """ def get_value(result): - for key, value in result.iteritems(): + for key, value in result.items(): if key != "time": return value diff --git a/influxdbnagiosplugin/summaries.py b/influxdbnagiosplugin/summaries.py index 3d19ca9..dc10f8e 100644 --- a/influxdbnagiosplugin/summaries.py +++ b/influxdbnagiosplugin/summaries.py @@ -18,7 +18,7 @@ def __init__(self, query): self.query = query def ok(self, results): - result = filter(is_values, results)[0] + result = next(filter(is_values, results)) return "{} is {}".format( self.query.measurements[0] if self.query.measurements else "result", result.metric.value, diff --git a/setup.py b/setup.py index d24d483..a5f8a3e 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,8 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 from setuptools import setup, find_packages -__version__ = "1.4" +__version__ = "1.5" setup( name="influxdbnagiosplugin",