Code Monkey home page Code Monkey logo

prometheus-bigquery-exporter's Introduction

prometheus-bigquery-exporter

Version Build Status Coverage Status GoDoc Go Report Card

An exporter for converting BigQuery results into Prometheus metrics.

Limitations: No historical values

Prometheus collects the current status of a system as reported by an exporter. Prometheus then associates the values collected with a timestamp of the time of collection.

NOTE: there is no way to associate historical values with timestamps in the the past with this exporter!

So, the results of queries run by prometheus-bigquery-exporter should represent a meaningful value at a fixed point in time relative to the time the query is made, e.g. total number of tests in a 5 minute window 1 hour ago.

Query Formatting

The prometheus-bigquery-exporter accepts arbitrary BQ queries. However, the query results must be structured in a predictable way for the exporter to successfully interpret and convert it into prometheus metrics.

Metric names and values

Metric names are derived from the query file name and query value columns. The bigquery-exporter identifies value columns by looking for column names that match the pattern: value([.+]). All characters in the matching group ([.+]) are appended to the metric prefix taken from the query file name. For example:

  • Filename: bq_ndt_test.sql
  • Metric prefix: bq_ndt_test
  • Column name: value_count
  • Final metric: bq_ndt_test_count

Value columns are required (at least one):

  • value([.+]) - every query must define a result "value". Values must be integers or floats. For a query to return multiple values, prefix each with "value" and define unique suffixes.

Label columns are optional:

  • If there is more than one result row, then the query must also define labels to distinguish each value. Every column name that is not "value" will create a label on the resulting metric. For example, results with two columns, "machine" and "value" would create metrics with labels named "machine" and values from the results for that row.

Labels must be strings:

  • There is no limit on the number of labels, but you should respect the prometheus best practices by limiting label value cardinality.

Duplicate metrics are an error:

  • If the query returns multiple rows that are not distinguished by the set of labels for each row.

Example Query

The following query creates a label and groups by each label.

-- Example data in place of an actual table of values.
WITH example_data as (
    SELECT "a" as label, 5 as widgets
    UNION ALL
    SELECT "b" as label, 2 as widgets
    UNION ALL
    SELECT "b" as label, 3 as widgets
)

SELECT
   label, SUM(widgets) as value
FROM
   example_data
GROUP BY
   label
  • Save the sample query to a file named "bq_example.sql".

  • Start the exporter:

    prometheus-bigquery-exporter -gauge-query bq_example.sql
  • Visit http://localhost:9348/metrics and you will find metrics like:

      bq_example{label="a"} 5
      bq_example{label="b"} 5
      ...

Example Configuration

Typical deployments will be in Kubernetes environment, like GKE.

# Change to the example directory.
cd example
# Deploy the example query as a configmap and example k8s deployment.
./deploy.sh

Testing

To run the bigquery exporter locally (e.g. with a new query) you can build and run locally.

Use the following steps:

  1. Build the docker image.
docker build -t bqx-local -f Dockerfile .
  1. Authenticate using your Google account. Both steps are necessary, the first to run gcloud commands (which uses user credentials), the second to run the bigquery exporter (which uses application default credentials).
gcloud auth login
gcloud auth application-default login
  1. Run the image, with fowarded ports and access to gcloud credentials.
docker run -p 9348:9348 --rm \
  -v $HOME/.config/gcloud:/root/.config/gcloud \
  -v $PWD:/queries -it bqx-local \
    -project=$GCLOUD_PROJECT \
    -gauge-query=/queries/example/config/bq_example.sql

prometheus-bigquery-exporter's People

Contributors

aeronotix avatar cristinaleonr avatar dependabot[bot] avatar guerremdq avatar pboothe avatar robertodauria avatar stephen-soltesz avatar tylerlubeck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prometheus-bigquery-exporter's Issues

Export query costs as metrics

Bigquery job stats include query costs. The bigquery-exporter should report the costs of queries run along with other metrics.

Make refresh interval a per-query parameter

Some queries are more expensive than others. It should be possible to specify the refresh interval per-query.

e.g.

--refresh=1h --type=gauge --query=/queries/bq_ndt_tests.sql

Support query 'reload'

In a k8s environment, updated SQL queries are deployed without recreating the bq-exporter container. However, currently, the bq-exporter only loads sql files at start time, so file changes are never read.

Like other prometheus exporters, bq-exporter should support some mechanism for 'reload' so that file changes can be discovered and re-read automatically.

Latest versioned docker hub release is 3 years old

Please could a new release be tagged? I'd like to use this in a project but prefer hard-coding the version tag, but there's been work done on the project in the last 3 years, and the latest tag is way more up to date.

Would it be possible to tag a 1.1.2(?) release with the current changes?

Support a --refresh and --step parameters

Queries can be expensive. It may be helpful in some cases to run a query that adds a timestamp column. The interval of timestamps would be smaller than the --refresh interval.

For example:

timestamp, site, value
2017-11-10 10:00:00, foo01, 100
2017-11-10 11:00:00, foo01, 100

The query would run every --refresh interval, (say 24hrs), and bqe would iterate through the timestamps at --step intervals of an hour. Arguably the step could be determined automatically...

This feature could help work around behavior we've observed from bqe with small refresh intervals where bigquery apparently stops returning updates around midnight (though that symptom could have other causes, such as time-to-availability of bq streaming inserts).

Support multiple values

Currently bqe only supports exporting a single value.

Since queries can be expensive, it should be possible to export multiple values. For example, column names <prefix>_value could be translated into metric_<prefix>{labels} <value>

For now, all should share the common labels from the other column names.

Support "cumulative" counts

While the current "COUNTER" type is possible it requires using very expensive queries. In particular, the number of new records since the last query is relatively small.

Instead of requiring a re-query of an entire table, a "cumulative" option could report "counter" metrics by summing past results with current results. In this way, each query could be for a small window of time and added to the totals from all past queries on every refresh period.

/lib/libpthread.so.0: undefined symbol: __libc_vfork, version GLIBC_PRIVATE

Having
/bin/prometheus-bigquery-exporter: symbol lookup error: /lib/libpthread.so.0: undefined symbol: __libc_vfork, version GLIBC_PRIVATE issue when try to start exporter locally via Docker

Steps to reproduce:

  1. download repo

  2. build Docker-image
    docker build -t bqx-local -f Dockerfile .

  3. run with default arguments

docker run -p 9348:9348 --rm \ -v $HOME/.config/gcloud:/root/.config/gcloud \ -v $PWD:/queries -it bqx-local \ -project $GCLOUD_PROJECT \ -guage-query /queries/example/config/bq_example.sql

Support BQ job children

BigQuery supports complex "scripting" queries that include multiple results.

For example:

BEGIN
    SELECT 10 AS value_example1;
    SELECT 100 as value_example2;
END

The bigquery-exporter could support this type of query by finding value_* columns from each result set. This could also support complex steps, e.g. write to a table, run query on derived table.

See also: #27

Make sure bigquery exporter doesn't crash when a query fails

When a query fails, fails if one of its queries errors out.

A recent example of this issue came up when the queries for the scamper1 data type were released, but the table did not exist yet, which cause a query error, and subsequently bigquery exporter to crash.

2021/10/27 21:55:55 main.go:88: Failed to register collector: aborting (error: googleapi: Error 404: Not found: Table mlab-oti:ndt.scamper1 was not found in location US, notFound)

Execute multiple select

I want to ask what I should do if I have multiple select statements that need to be executed and exported into multiple indicators. It seems that it doesn't work to append multiple SQL files after the command parameter gauge query

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.