User Tools

Site Tools


watchdogs:creating_a_new_metric

Creating a New Metric on Prometheus

Author: Máté Domonics on 06/03/2023

SQL Exporter

SQL Exporter is used to test your SQL queries before deploying them. Use this link to download it. (I downloaded the darwin-amd64 version)

Usage of SQL Exporter

  1. Open up the folder in your preferred IDE for ease of access and change the sql_exporter.yml file to accommodate for the collector that you will be using. Also make sure to have the correct data source.
  2. Inside the [collector_name].collector.yml file, create your desired metrics.
    1. Make sure to double check the correct syntax for the yaml file, as it is indentation sensitive.
    2. Highly recommend using a database querying workbench such as DBeaver or MySQL Workbench to quickly test your SQL queries, as this will also allow you to preview what data you can expect to receive.
  3. When your desired query is made, run the sql_exporter file in a terminal and observe any errors that may occur. If it runs successfully, a port will be displayed on screen.
    1. Note that the values field is mandatory. Structure your SQL query around this.
  4. Use this port number and go to http://localhost:[PortNumber]. Here, you can review whether your metrics got picked up correctly, and if they didn't, an error will be printed to the terminal where you have sql_exporter running. Analyse and fix this error if needed.
  5. Once your metric has been checked and it works correctly when using sql_exporter, you can move on to the next step.

Deploying into the codebase

  1. Clone the prometheus-monitoring-config repo to your local machine and find the collection that you want to make changes to.
    1. This is found at: prometheus-monitoring-config/files/collectors
  2. Once found, place your SQL queries into the correct collector at the correct position.
    1. Some collections are grouped together by multiple customers, so placement can be important!
  3. Save your changes locally, and move on to creating a new alert.
watchdogs/creating_a_new_metric.txt · Last modified: 2023/03/06 16:16 by 10.91.110.100