Skip to main content

2 posts tagged with "prometheus"

View All Tags

· One min read
Hreniuc Cristian-Alexandru

First, download the prometheus collector from their webpage: https://github.com/prometheus/mysqld_exporter or use docker.

Next you need to add an new user in the database:

CREATE USER 'mysqld_exporter'@'%' IDENTIFIED BY 'password' WITH MAX_USER_CONNECTIONS 3;

GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysqld_exporter'@'%';

I used % for host of the user, to allow logging in from everywhere. I did this because I encountered some errors when I used localhost: ERRO[0026] Error pinging mysqld: dial tcp :0: connect: connection refused source="exporter.go:119"

export DATA_SOURCE_NAME='mysqld_exporter:password@(127.0.0.1:3306)/' && \
nohup ./mysqld_exporter --no-collect.info_schema.tables --no-collect.slave_status > nohup.out 2>&1 &

Use this dashboard from grafana: https://grafana.com/dashboards/7362

· 2 min read
Hreniuc Cristian-Alexandru

Prometheus

To run a container with prometheus, we need two things:

  • prometheus.yml file
  • Docker volume

The prometheus.yml file should contain something like this:

# my global config
global:
scrape_interval: 5s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 5s # Evaluate rules every 15 seconds. The default is every 1 minute.

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']

- job_name: 'docker'
static_configs:
- targets: ['localhost:9999']

- job_name: 'other_collector'
scrape_interval: 1s
static_configs:
- targets: ['192.168.1.28:8000']

To create a docker volume, run:

docker create volume prometheus_data

This way, your collected data won\'t be lost on restarts.

docker run -d --restart=always --name=prometheus --network=host -v /path/to/prometheus.yml:/etc/prometheus/prometheus.yml -v prometheus_data:/prometheus prom/prometheus

You should open the browser and check if everything works, by default it is 9090 port.

Grafana

For grafana we will also use a docker volume:

docker create volume grafana_data

This way we will save all data from grafana(panels, users, etc...).

To run the grafana container, simply run:

docker run -d --name=grafana --restart=always --network=host -e GF_SERVER_ROOT_URL=http://grafana.server.name -e GF_SECURITY_ADMIN_PASSWORD=secret -v grafana_data:/var/lib/grafana grafana/grafana

You can check it on port 3000.

Now you should add the Prometheus server as a data source. You can do this by going to Configuration -> Datasources -> Select Prometheus