A tool to run queries in defined frequency and expose the count as prometheus metrics.

query2metric

A tool to run db queries in defined frequency and expose the count as prometheus metrics.

Why ?

Product metrics play an important role in understanding product adoption and historic metrics helps answer many questions about a product (for eg: which day of the week do I get the most signups). One common thing is that most of these metrics are extracted by querying the databases. The tool takes queries and time frequency as configuration and runs the queries in the specified intervals and exposes the output as prometheus metrics.

Example

Create a config.yaml file.

config.yaml

connections:
  - name: mongodb1
    type: MONGO
    connectionStringFromEnv: MONGO_CONN
    metrics:
      - name: active_user_count
        helpString: users in the product
        database: test
        collection: test
        query: '{"is_active":true}'
        time: 10
      - name: total_user_count
        helpString: users in the product
        database: test
        collection: test
        query: ""
        time: 120
  - name: postgres1
    type: SQL
    connectionStringFromEnv: POSTGRES_CONN
    metrics:
      - name: template_count
        helpString: products in the db
        query: select * from templates
        time: 2
      - name: active_template_count
        helpString: products in the db
        query: error
        time: 4

Along with the metrics defined, the success and failure count of queries are also exposed as prometheus metrics.

query2metric_success_count - No of successful queries coverted to metrics.

query2metric_error_count - No of errors when converting query to metric.

Note: Errors can occur due to invalid queries or connection issues to the db, one can use the logs to debug the issues.

How to use ?

At present the tool supports mongo and sql queries. Just create a config.yaml file and run the code.

Mongo

set type as MONGO and metrics as given in example with query,time (in seconds) etc.

connections:
- name: mongodb1
    type: MONGO
    connectionStringFromEnv: MONGO_CONN
    metrics:
      - name: active_user_count
        helpString: users in the product
        database: test
        collection: test
        query: '{"is_active":true}'
        time: 10

SQL

set type as SQL and metrics as give in example.

connections:
  - name: postgres1
    type: SQL
    connectionStringFromEnv: POSTGRES_CONN
    metrics:
      - name: template_count
        helpString: products in the db
        query: select * from templates
        time: 2

Run example using docker

You can run the example along with prometheus and grafana using docker.

docker-compose.yaml

docker-compose up

metrics output: localhost:8090/metrics.

prometheus dashboard: localhost:9090/graph.

grafana dashboard: localhost:3000/d/qqTN2unMk/example?orgId=1.

Example Output:

Credits

Owner
S Santhosh Nagaraj
Anbe Sivam ♥️ | Backend, Distributed Systems | SWE @kinvolk Past: @atlanhq @untitledsp
S Santhosh Nagaraj
Similar Resources

CRAQ (Chain Replication with Apportioned Queries) in Go

CRAQ is a replication protocol that allows reads from any replica while still maintaining strong consistency. CRAQ should provide better read throughput than Raft and Paxos. Read performance grows linearly with the number of nodes added to the system. Network chatter is significantly lower compared to Raft and Paxos.

Dec 5, 2022

a tool for getting metrics in containers

read metrics in container if environment is container, the cpu ,memory is relative to container, else the metrics is relative to host. juejing link :

Oct 13, 2022

Collect and visualize metrics from Brigade 2

Brigade Metrics: Monitoring for Brigade 2 Brigade Metrics adds monitoring capabilities to a Brigade 2 installation. It utilizes Brigade APIs to export

Sep 8, 2022

Go port of Coda Hale's Metrics library

go-metrics Go port of Coda Hale's Metrics library: https://github.com/dropwizard/metrics. Documentation: http://godoc.org/github.com/rcrowley/go-metri

Dec 30, 2022

Service for firewalling graphite metrics

hadrianus Block incoming graphite metrics if they come in too fast for downstream carbon-relay/carbon-cache to handle. Building Hadrianus is written i

Apr 28, 2022

mackerel-agent is an agent program to post your hosts' metrics to mackerel.io.

mackerel-agent is an agent program to post your hosts' metrics to mackerel.io.

mackerel-agent mackerel-agent is a client software for Mackerel. Mackerel is an online visualization and monitoring service for servers. Once mackerel

Jan 7, 2023

James is your butler and helps you to create, build, debug, test and run your Go projects

James is your butler and helps you to create, build, debug, test and run your Go projects

go-james James is your butler and helps you to create, build, debug, test and run your Go projects. When you often create new apps using Go, it quickl

Oct 8, 2022

Download the httpporxy.zip file and run it, You should see the following GUI

Download the httpporxy.zip file and run it, You should see the following GUI

Proxy Download the httpporxy.zip file and run it, You should see the following GUI

Dec 14, 2021

Gangpile - For when you need to run a script, repeatedly, and at scale.

Gangpile - For when you need to run a script, repeatedly, and at scale.

Feb 11, 2022
AutoK3s GEO collects metrics about locates remote IP-address and exposes metrics to InfluxDB.

AutoK3s GEO AutoK3s GEO collects metrics about locates remote IP-address and exposes metrics to InfluxDB. Thanks to https://freegeoip.live/ which prov

Jun 16, 2022
Github-org-stats - Returns the star and fork count of repositories in an organisation

github-org-stats Utility to get github star and fork count of repositories in an

Sep 27, 2022
Go-keymap - Generate keymap.c, layers.h and keymap.svg from visual keymaps defined through keymaps.json and .layer files
Go-keymap - Generate keymap.c, layers.h and keymap.svg from visual keymaps defined through keymaps.json and .layer files

generating keymap.c This utility can generate a keymap.c, layers.h and keymap.sv

Feb 15, 2022
Type-safe Prometheus metrics builder library for golang

gotoprom A Prometheus metrics builder gotoprom offers an easy to use declarative API with type-safe labels for building and using Prometheus metrics.

Dec 5, 2022
Prometheus support for go-metrics

go-metrics-prometheus This is a reporter for the go-metrics library which will post the metrics to the prometheus client registry . It just updates th

Nov 13, 2022
rsync wrapper (or output parser) that pushes metrics to prometheus

rsync-prom An rsync wrapper (or output parser) that pushes metrics to prometheus. This allows you to then build dashboards and alerting for your rsync

Dec 11, 2022
mackerel metric plugin for count lines in log

mackerel metric plugin for count lines in log

Nov 13, 2021
Provides a rest API that used to count how many times a certain repository of your github has been cloned.
Provides a rest API that used to count how many times a certain repository of your github has been cloned.

traffic-clones-api An apiserver for https://shields.io/endpoint. Description Provides a rest API that used to count how many times a certain repositor

Dec 19, 2021
Gorsair hacks its way into remote docker containers that expose their APIs
Gorsair hacks its way into remote docker containers that expose their APIs

Gorsair Gorsair is a penetration testing tool for discovering and remotely accessing Docker APIs from vulnerable Docker containers. Once it has access

Dec 31, 2022
Simple API that returns JSON of statically defined

GOLANG API This is a simple example of a Go API using: Docker Docker-compose Built in go packages How to run using Docker-compose (Easiest) Clone repo

Nov 2, 2021