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

zpool_influxdb: rewire under zpool command #11160

Closed
wants to merge 1 commit into from
Closed
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
1 change: 0 additions & 1 deletion cmd/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
SUBDIRS = zfs zpool zdb zhack zinject zstream zstreamdump ztest
SUBDIRS += fsck_zfs vdev_id raidz_test zfs_ids_to_path
SUBDIRS += zpool_influxdb

if USING_PYTHON
SUBDIRS += arcstat arc_summary dbufstat
Expand Down
1 change: 1 addition & 0 deletions cmd/zpool/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sbin_PROGRAMS = zpool
zpool_SOURCES = \
zpool_iter.c \
zpool_main.c \
zpool_monitor_influxdb.c \
zpool_util.c \
zpool_util.h \
zpool_vdev.c
Expand Down
13 changes: 11 additions & 2 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ static int zpool_do_version(int, char **);

static int zpool_do_wait(int, char **);

extern int zpool_do_monitor_influxdb(int, char **);
extern int zpool_help_monitor_influxdb(char *);
/*
* These libumem hooks provide a reasonable set of defaults for the allocator's
* debugging facilities.
Expand Down Expand Up @@ -175,7 +177,8 @@ typedef enum {
HELP_REGUID,
HELP_REOPEN,
HELP_VERSION,
HELP_WAIT
HELP_WAIT,
HELP_MONITOR_INFLUXDB,
} zpool_help_t;


Expand Down Expand Up @@ -312,6 +315,7 @@ static zpool_command_t command_table[] = {
{ NULL },
{ "history", zpool_do_history, HELP_HISTORY },
{ "events", zpool_do_events, HELP_EVENTS },
{ "monitor-influxdb", zpool_do_monitor_influxdb, HELP_MONITOR_INFLUXDB},
{ NULL },
{ "get", zpool_do_get, HELP_GET },
{ "set", zpool_do_set, HELP_SET },
Expand Down Expand Up @@ -424,6 +428,10 @@ get_usage(zpool_help_t idx)
case HELP_WAIT:
return (gettext("\twait [-Hp] [-T d|u] [-t <activity>[,...]] "
"<pool> [interval]\n"));
case HELP_MONITOR_INFLUXDB:
return (gettext("\tmonitor-influxdb [-e|--execd]\n"
"\t [-n|--no-histograms] [-s|--sum-histogram-buckets]\n"
"\t [-i|--signed-int] [pool] ...\n"));
}

abort();
Expand Down Expand Up @@ -480,12 +488,13 @@ print_prop_cb(int prop, void *cb)
return (ZPROP_CONT);
}

void usage(boolean_t);
/*
* Display usage message. If we're inside a command, display only the usage for
* that command. Otherwise, iterate over the entire command table and display
* a complete usage message.
*/
static void
void
usage(boolean_t requested)
{
FILE *fp = requested ? stdout : stderr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
* collection -- info is printed, KISS
* + broken pools or kernel bugs can cause this process to hang in an
* unkillable state. For this reason, it is best to keep the damage limited
* to a small process like zpool_influxdb rather than a larger collector.
* to a small process like zpool monitor-influxdb rather than a larger
* collector.
*
* Copyright 2018-2020 Richard Elling
*
Expand Down Expand Up @@ -73,6 +74,8 @@
#include <inttypes.h>
#include <libzfs_impl.h>

extern void usage(boolean_t);

#define POOL_MEASUREMENT "zpool_stats"
#define SCAN_MEASUREMENT "zpool_scan_stats"
#define VDEV_MEASUREMENT "zpool_vdev_stats"
Expand Down Expand Up @@ -171,7 +174,7 @@ print_scan_status(nvlist_t *nvroot, const char *pool_name)
ps->pss_func >= POOL_SCAN_FUNCS) {
if (complained_about_sync % 1000 == 0) {
fprintf(stderr, "error: cannot decode scan stats: "
"ZFS is out of sync with compiled zpool_influxdb");
"ZFS is out of sync with compiled zpool command");
complained_about_sync++;
}
return (1);
Expand Down Expand Up @@ -695,13 +698,14 @@ print_recursive_stats(stat_printer_f func, nvlist_t *nvroot,
return (0);
}

int print_stats(zpool_handle_t *, void *);
/*
* call-back to print the stats from the pool config
*
* Note: if the pool is broken, this can hang indefinitely and perhaps in an
* unkillable state.
*/
static int
int
print_stats(zpool_handle_t *zhp, void *data)
{
uint_t c;
Expand Down Expand Up @@ -768,16 +772,10 @@ print_stats(zpool_handle_t *zhp, void *data)
return (err);
}

static void
usage(char *name)
{
fprintf(stderr, "usage: %s [--execd][--no-histograms]"
"[--sum-histogram-buckets] [--signed-int] [poolname]\n", name);
exit(EXIT_FAILURE);
}
int zpool_do_monitor_influxdb(int, char **);

int
main(int argc, char *argv[])
zpool_do_monitor_influxdb(int argc, char *argv[])
{
int opt;
int ret = 8;
Expand Down Expand Up @@ -820,7 +818,7 @@ main(int argc, char *argv[])
(void) snprintf(tags, tagslen, ",%s", optarg);
break;
default:
usage(argv[0]);
usage(B_FALSE);
}
}

Expand Down
1 change: 0 additions & 1 deletion cmd/zpool_influxdb/.gitignore

This file was deleted.

11 changes: 0 additions & 11 deletions cmd/zpool_influxdb/Makefile.am

This file was deleted.

3 changes: 0 additions & 3 deletions cmd/zpool_influxdb/dashboards/README.md

This file was deleted.

3 changes: 1 addition & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ AC_CONFIG_FILES([
cmd/ztest/Makefile
cmd/zvol_id/Makefile
cmd/zvol_wait/Makefile
cmd/zpool_influxdb/Makefile
contrib/Makefile
contrib/bash_completion.d/Makefile
contrib/bpftrace/Makefile
Expand Down Expand Up @@ -302,6 +301,7 @@ AC_CONFIG_FILES([
tests/zfs-tests/tests/functional/cli_root/zpool_import/blockfiles/Makefile
tests/zfs-tests/tests/functional/cli_root/zpool_initialize/Makefile
tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/Makefile
tests/zfs-tests/tests/functional/cli_root/zpool_monitor-influxdb/Makefile
tests/zfs-tests/tests/functional/cli_root/zpool_offline/Makefile
tests/zfs-tests/tests/functional/cli_root/zpool_online/Makefile
tests/zfs-tests/tests/functional/cli_root/zpool_remove/Makefile
Expand Down Expand Up @@ -395,7 +395,6 @@ AC_CONFIG_FILES([
tests/zfs-tests/tests/functional/vdev_zaps/Makefile
tests/zfs-tests/tests/functional/write_dirs/Makefile
tests/zfs-tests/tests/functional/xattr/Makefile
tests/zfs-tests/tests/functional/zpool_influxdb/Makefile
tests/zfs-tests/tests/functional/zvol/Makefile
tests/zfs-tests/tests/functional/zvol/zvol_ENOSPC/Makefile
tests/zfs-tests/tests/functional/zvol/zvol_cli/Makefile
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Influxdb Metrics for ZFS Pools
The _zpool_influxdb_ program produces
The _zpool monitor-influxdb_ program produces
[influxdb](https://github.com/influxdata/influxdb) line protocol
compatible metrics from zpools. In the UNIX tradition, _zpool_influxdb_
compatible metrics from zpools. In the UNIX tradition, _zpool monitor-influxdb_
does one thing: read statistics from a pool and print them to
stdout. In many ways, this is a metrics-friendly output of
statistics normally observed via the `zpool` command.

## Usage
When run without arguments, _zpool_influxdb_ runs once, reading data
When run without arguments, _zpool monitor-influxdb_ runs once, reading data
from all imported pools, and prints to stdout.
```shell
zpool_influxdb [options] [poolname]
zpool monitor-influxdb [options] [poolname]
```
If no poolname is specified, then all pools are sampled.

Expand All @@ -36,7 +36,7 @@ Another method for storing histogram data sums the values for lower-value
buckets. For example, a latency bucket tagged "le=10" includes the values
in the bucket "le=1".
This method is often used for prometheus histograms.
The `zpool_influxdb --sum-histogram-buckets` option presents the data from ZFS
The `zpool monitor-influxdb --sum-histogram-buckets` option presents the data from ZFS
as summed values.

## Measurements
Expand Down Expand Up @@ -219,12 +219,12 @@ accounted in the 16MiB bucket.

#### About unsigned integers
Telegraf v1.6.2 and later support unsigned 64-bit integers which more
closely matches the uint64_t values used by ZFS. By default, zpool_influxdb
closely matches the uint64_t values used by ZFS. By default, zpool monitor-influxdb
uses ZFS' uint64_t values and influxdb line protocol unsigned integer type.
If you are using old telegraf or influxdb where unsigned integers are not
available, use the `--signed-int` option.

## Using _zpool_influxdb_
## Using _zpool monitor-influxdb_

The simplest method is to use the execd input agent in telegraf. For older
versions of telegraf which lack execd, the exec input agent can be used.
Expand All @@ -234,10 +234,10 @@ be restarted to read the config-directory files.

### Example telegraf execd configuration
```toml
# # Read metrics from zpool_influxdb
# # Read metrics from zpool monitor-influxdb
[[inputs.execd]]
# ## default installation location for zpool_influxdb command
command = ["/usr/bin/zpool_influxdb", "--execd"]
# ## default installation location for zpool monitor-influxdb command
command = ["/usr/sbin/zpool", "monitor-influxdb", "--execd"]

## Define how the process is signaled on each collection interval.
## Valid values are:
Expand All @@ -261,25 +261,23 @@ be restarted to read the config-directory files.

### Example telegraf exec configuration
```toml
# # Read metrics from zpool_influxdb
# # Read metrics from zpool monitor-influxdb
[[inputs.exec]]
# ## default installation location for zpool_influxdb command
commands = ["/usr/bin/zpool_influxdb"]
# ## default installation location for zpool monitor-influxdb command
commands = ["/usr/sbin/zpool", "monitor-influxdb"]
data_format = "influx"
```

## Caveat Emptor
* Like the _zpool_ command, _zpool_influxdb_ takes a reader
lock on spa_config for each imported pool. If this lock blocks,
then the command will also block indefinitely and might be
unkillable. This is not a normal condition, but can occur if
there are bugs in the kernel modules.
For this reason, care should be taken:
* The _zpool_ command takes a reader lock on spa_config for each imported pool.
If this lock blocks, then the command will also block indefinitely and might
be unkillable. This is not a normal condition, but can occur if there are bugs
in the kernel modules. For this reason, care should be taken:
* avoid spawning many of these commands hoping that one might
finish
* avoid frequent updates or short sample time
intervals, because the locks can interfere with the performance
of other instances of _zpool_ or _zpool_influxdb_
of other instances of _zpool_ or _zpool monitor-influxdb_

## Other collectors
There are a few other collectors for zpool statistics roaming around
Expand Down
3 changes: 3 additions & 0 deletions contrib/zpool_monitor-influxdb/dashboards/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Dashboards for zpool monitor-influxdb
This directory contains a collection of dashboards related to ZFS with data
collected from the zpool monitor-influxdb collector.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
This directory contains sample telegraf configurations for
adding `zpool_influxdb` as an input plugin. Depending on your
adding `zpool monitor-influxdb` as an input plugin. Depending on your
telegraf configuration, the installation can be as simple as
copying one of these to the `/etc/telegraf/telegraf.d` directory
and restarting `systemctl restart telegraf`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# # Read metrics from zpool_influxdb
# # Read metrics from zpool monitor-influxdb
[[inputs.exec]]
# ## default installation location for zpool_influxdb command
commands = ["/usr/local/bin/zpool_influxdb"]
# ## default installation location for zpool monitor-influxdb command
commands = ["/usr/local/sbin/zpool", "monitor-influxdb"]
# ## Timeout for each command to complete.
# timeout = "5s"
#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# # Read metrics from zpool_influxdb
# # Read metrics from zpool monitor-influxdb
[[inputs.execd]]
# ## default installation location for zpool_influxdb command
command = ["/usr/local/bin/zpool_influxdb", "--execd"]
# ## default installation location for zpool monitor-influxdb command
command = ["/usr/local/bin/zpool", "monitor-influxdb", "--execd"]

## Define how the process is signaled on each collection interval.
## Valid values are:
Expand Down
4 changes: 2 additions & 2 deletions man/man8/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ dist_man_MANS = \
zpool-iostat.8 \
zpool-labelclear.8 \
zpool-list.8 \
zpool_monitor-influxdb.8 \
zpool-offline.8 \
zpool-online.8 \
zpool-reguid.8 \
Expand All @@ -82,8 +83,7 @@ dist_man_MANS = \
zpool-upgrade.8 \
zpool-wait.8 \
zstream.8 \
zstreamdump.8 \
zpool_influxdb.8
zstreamdump.8

nodist_man_MANS = \
zed.8 \
Expand Down
37 changes: 20 additions & 17 deletions man/man8/zpool_influxdb.8 → man/man8/zpool_monitor-influxdb.8
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,45 @@
.\"
.\"
.\" Copyright 2020 Richard Elling
.\" .Dd June 14, 2020
.TH zpool_influxdb 8
.SH NAME
zpool_influxdb \- collect zpool statistics in influxdb line protocol format
.Dd October, 5, 2020
.Dt ZPOOL-MONITOR-INFLUXDB 8
.Os
.Sh NAME
.Nm zpool-monitor-influxdb
.Nd Collect zpool statistics in influxdb line protocol format
.SH SYNOPSIS
.LP
.nf
\fBzpool_influxdb\fR [--execd] [--no-histogram] [--sum-histogram-buckets]
\fBzpool monitor-influxdb\fR [--execd] [--no-histogram] [--sum-histogram-buckets]
[--tags key=value] [pool]
\fBzpool_influxdb\fR --help
\fBzpool monitor-influxdb\fR --help
.fi
.SH DESCRIPTION
The \fBzpool_influxdb\fR command produces influxdb line protocol compatible
metrics from zpools. Like the \fBzpool\fR command, \fBzpool_influxdb\fR
reads the current pool status and statistics. Unlike the \fBzpool\fR
command which is intended for humans, \fBzpool_influxdb\fR formats the
output in influxdb line protocol. The expected use is as a plugin to a
metrics collector or aggregator, such as telegraf.
The \fBzpool monitor-influxdb\fR command produces influxdb line protocol
compatible metrics from zpools. Like the \fBzpool\fR command,
\fBzpool monitor-influxdb\fR reads the current pool status and statistics.
Unlike the \fBzpool\fR command which is intended for humans,
\fBzpool monitor-influxdb\fR formats the output in influxdb line protocol.
The expected use is as a plugin to a metrics collector or aggregator, such
as telegraf.

By default, \fBzpool_influxdb\fR prints pool metrics and status in the
By default, \fBzpool monitor-influxdb\fR prints pool metrics and status in the
influxdb line protocol format. All pools are printed, similar to
the \fBzpool status\fR command. Providing a pool name restricts the
output to the named pool.

Like the \fBzpool\fR command, \fBzpool_influxdb\fR uses internal data
Like the \fBzpool\fR command, \fBzpool monitor-influxdb\fR uses internal data
structures that can change over time as new ZFS releases are made.
Therefore, the \fBzpool_influxdb\fR command must be compiled against the
Therefore, the \fBzpool monitor-influxdb\fR command must be compiled against the
ZFS source. It is expected that later releases of ZFS includes compatible
\fBzpool_influxdb\fR and \fBzpool\fR commands.
\fBzpool monitor-influxdb\fR and \fBzpool\fR commands.

.SH OPTIONS
.TP
\fB\--execd\fR, \fB-e\fR
Run in daemon mode compatible with telegraf`s \fBexecd\fR plugin.
In this mode, the pools are sampled every time there is a [return] on stdin.
Once a sample printed, \fBzpool_influxdb\fR waits for another [return].
Once a sample printed, \fBzpool monitor-influxdb\fR waits for another [return].
When run on a terminal, use [ctrl+C] to exit.
.TP
\fB\--no-histogram\fR, \fB-n\fR
Expand Down
1 change: 0 additions & 1 deletion rpm/generic/zfs.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ systemctl --system daemon-reload >/dev/null || true
%{_bindir}/raidz_test
%{_bindir}/zgenhostid
%{_bindir}/zvol_wait
%{_bindir}/zpool_influxdb
# Optional Python 2/3 scripts
%{_bindir}/arc_summary
%{_bindir}/arcstat
Expand Down
Loading