Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Python3 and minor updates #6

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 3 additions & 3 deletions influxdbnagiosplugin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion influxdbnagiosplugin/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion influxdbnagiosplugin/summaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down