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

File-controlled scrapers that can run arbitrary queries #1

Merged
merged 2 commits into from
Jul 15, 2024
Merged

Conversation

rcrowley
Copy link
Collaborator

This patch adds --extras.file and --extras.refresh-interval to mysqld_exporter in order to allow easy addition of arbitrary metric-gathering queries without restarting mysqld or worse.

Usage:

cat >extras.yaml <<EOF
---
- metric: foobar
  query: SELECT 47 AS foo, 48879 AS bar;
- metric: bazquux
  query: SELECT 3.14159 AS baz, 2.71828 AS quux;
...
EOF
mysqld_exporter \
    --extras.file /path/to/mounted/config/map/extras.yaml \
    --extras.refresh-interval 1m

When scraped, these metrics will be among the output:

# HELP mysql_extra_bazquux Extra metrics from SELECT 3.14159 AS baz, 2.71828 AS quux;
# TYPE mysql_extra_bazquux gauge
mysql_extra_bazquux{column="baz"} 3.14159
mysql_extra_bazquux{column="quux"} 2.71828
# HELP mysql_extra_foobar Extra metrics from SELECT 47 AS foo, 48879 AS bar;
# TYPE mysql_extra_foobar gauge
mysql_extra_foobar{column="bar"} 48879
mysql_extra_foobar{column="foo"} 47

The YAML file is not intended to be stuffed in the filesystem and forgotten about. Instead, it should be served via a Kubernetes config map. To update the metrics and queries that it scrapes, update the config map and wait longer than about the --extras.refresh-interval plus one minute (empirically how long config map updates take to become visible).

ENOENT and EOF on the --extras.file are not considered errors. It might exist next time! This also means that deleting or emptying the file is a valid way to stop collecting these metrics.

Post merge, here's what comes next:

  1. Figure out how to build this container image.
  2. Test this patch on my pet turtle.
  3. Make a release plan and do it.

rcrowley added 2 commits July 15, 2024 13:42
This patch adds `--extras.file` and `--extras.refresh-interval` to
`mysqld_exporter` in order to allow easy addition of arbitrary
metric-gathering queries without restarting `mysqld` or worse.

Usage:

    cat >extras.yaml <<EOF
    ---
    - metric: foobar
      query: SELECT 47 AS foo, 48879 AS bar;
    - metric: bazquux
      query: SELECT 3.14159 AS baz, 2.71828 AS quux;
    ...
    EOF
    mysqld_exporter \
        --extras.file /path/to/mounted/config/map/extras.yaml \
        --extras.refresh-interval 1m

When scraped, these metrics will be among the output:

    # HELP mysql_extra_bazquux Extra metrics from SELECT 3.14159 AS baz, 2.71828 AS quux;
    # TYPE mysql_extra_bazquux gauge
    mysql_extra_bazquux{column="baz"} 3.14159
    mysql_extra_bazquux{column="quux"} 2.71828
    # HELP mysql_extra_foobar Extra metrics from SELECT 47 AS foo, 48879 AS bar;
    # TYPE mysql_extra_foobar gauge
    mysql_extra_foobar{column="bar"} 48879
    mysql_extra_foobar{column="foo"} 47

The YAML file is not intended to be stuffed in the filesystem and
forgotten about. Instead, it should be served via a Kubernetes config
map. To update the metrics and queries that it scrapes, update the
config map and wait longer than about the `--extras.refresh-interval`
plus one minute (empirically how long config map updates take to become
visible).

ENOENT and EOF on the `--extras.file` are not considered errors. It
might exist next time! This also means that deleting or emptying the
file is a valid way to _stop_ collecting these metrics.

Post merge, here's what comes next:

1. Figure out how to build this container image.
2. Test this patch on my pet turtle.
3. Make a release plan and do it.
@rcrowley rcrowley merged commit 914cd9f into main Jul 15, 2024
1 check passed
@rcrowley rcrowley deleted the extras branch July 15, 2024 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant