Showing posts with label prometheues. Show all posts
Showing posts with label prometheues. Show all posts

Thursday, May 23, 2024

Prometheus and Grafana : Monitor MySQL/MariaDB

 1.Install MySQL Exporter
#curl -s https://api.github.com/repos/prometheus/mysqld_exporter/releases/latest   | grep browser_download_url   | grep linux-amd64 | cut -d '"' -f 4   | wget -qi -
#tar xvf mysqld_exporter*.tar.gz
#sudo mv  mysqld_exporter-*.linux-amd64/mysqld_exporter /usr/local/bin/
#sudo chmod +x /usr/local/bin/mysqld_exporter

2.Checking version of mysql exporter

#mysqld_exporter  --version

3.Create a user to collect the matrices of MySQL

#mysql -u root -p

CREATE USER 'mysqld_exporter'@'localhost' IDENTIFIED BY 'StrongPassword';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysqld_exporter'@'localhost';
FLUSH PRIVILEGES;
EXIT

4.Create database credentials file
#sudo vi /etc/.mysqld_exporter.cnf
[client]
user=mysqld_exporter
password=StrongPassword

5.Enable ownership permission
#chown root:prometheus /etc/.mysqld_exporter.cnf

6.Create a service for mysql exporter
#vi /etc/systemd/system/mysql_exporter.servic
[Unit]
Description=Prometheus MySQL Exporter
After=network.target
User=prometheus
Group=prometheus

[Service]
Type=simple
Restart=always
ExecStart=/usr/local/bin/mysqld_exporter \
--config.my-cnf /etc/.mysqld_exporter.cnf \
--collect.global_status \
--collect.info_schema.innodb_metrics \
--collect.auto_increment.columns \
--collect.info_schema.processlist \
--collect.binlog_size \
--collect.info_schema.tablestats \
--collect.global_variables \
--collect.info_schema.query_response_time \
--collect.info_schema.userstats \
--collect.info_schema.tables \
--collect.perf_schema.tablelocks \
--collect.perf_schema.file_events \
--collect.perf_schema.eventswaits \
--collect.perf_schema.indexiowaits \
--collect.perf_schema.tableiowaits \
--collect.slave_status \
--web.listen-address=0.0.0.0:9104

[Install]
WantedBy=multi-user.target

7.Enable and start the mysql exporter service
#systemctl daemon-reload
#systemctl enable mysql_exporter
#systemctl start mysql_exporter
#systemctl status mysql_exporter

8.Configure the endpoint in “Prometheus.yaml” file
# mysql exporter
  - job_name: "mysqld"
    metrics_path: '/metrics'
    scheme: http
    static_configs:
      - targets: ["X.X.X.X:9104"]

9.Import dashboard from Grafana.com with ID:7362


source : https://shrihariharidas73.medium.com/unlocking-database-insights-monitoring-mysql-with-prometheus-and-grafana-ddd2c4f01929

Tuesday, May 21, 2024

Prometheus and Grafana : Monitor NGINX

A: nginx configuration

1.Expose the stub_status page at /stub_status on port 8080

    server {
        listen 8080;
        server_name _;
    
        location /stub_status {
               stub_status;
        }
    }
2. Restart nginx
#systemctl restart nginx

3. Verification
#curl http://localhost:8080/stub_status

B: nginx-prometheus-exporter

1.Install nginx-prometheus-exporter
#git clone https://github.com/nginxinc/nginx-prometheus-exporter.git

2.Building the Binary. Change to nginx-prometheus-exporter folder
#dnf install go
#make

3.Move the nginx-prometheus-exporter binary to /usr/local/binary
#mv nginx-prometheus-exporter /usr/local/bin

4.Modify and create nginx_exporter.socket in /etc/systemd/system
#vi nginx_exporter.socket  (add below parameter)

[Unit]
Description=NGINX Prometheus Exporter

[Socket]
ListenStream=9113

[Install]
WantedBy=sockets.target

4.Modify and create nginx_exporter.service in /etc/systemd/system
#useradd nginx_exporter --shell=/sbin/nologin
#vi nginx_exporter.service  (add below parameter)
[Unit]
Description=NGINX Prometheus Exporter
Requires=nginx_exporter.socket

[Service]
User=nginx_exporter
ExecStart=/usr/local/bin/nginx-prometheus-exporter --nginx.scrape-uri="http://127.0.0.1:8080/stub_status" --web.systemd-socket

[Install]
WantedBy=multi-user.target

5.Run #systemctl daemon-reload
6.Run #systemctl start nginx_prometheus_exporter.service
7.Run #systemctl status nginx_prometheus_exporter.service
8. Verification
#curl http://localhost:9113/metrics

C:Promethues

1.Configure Prometheus to scrape metrics from the server with the exporter.
2.Edit /etc/prometheus/prometheus.yml
3.Add the scrape metric
## NGINX
  - job_name: nginx
    static_configs:
      - targets: ['10.X.X.X:9113']

4.Run systemctl restart prometheus.service
5.Run systemctl status prometheus.service

D:Grafana

1.Use the New Dashboard button and click Import.
2.Upload dashboard.json or copy and paste the contents of the file in the textbox and click Load.
https://github.com/nginxinc/nginx-prometheus-exporter/blob/main/grafana/dashboard.json
3.Set the Prometheus data source and click Import.
4.The dashboard will appear.By default, all instances are selected
5.Access Grafana dashboard

source : https://github.com/nginxinc/nginx-prometheus-exporter/tree/main

Wednesday, November 29, 2023

Prometheus and Grafana : Monitor BIND DNS server

 1.Pre-requisites
- BIND need to have been build with libxml2 support
# named -V | grep libxml2

2.Installed Bind Prometheus Exporter
-
Download the latest release of bind_exporter binary:

# curl -s https://api.github.com/repos/prometheus-community/bind_exporter/releases/latest | grep browser_download_url | grep linux-amd64 |  cut -d '"' -f 4 | wget -qi -
# tar xvf bind_exporter*.tar.gz
# sudo mv bind_exporter-*/bind_exporter /usr/local/bin
# bind_exporter --version

3. Configure BIND to open a statistics channel
- Edit the file /etc/named.conf to add

statistics-channels {
  inet 127.0.0.1 port 8053 allow { 127.0.0.1; };
};

4.Create Bind Exporter systemd service
- Add Prometheus system user account:
#sudo groupadd --system prometheus
#sudo useradd -s /sbin/nologin --system -g prometheus prometheus

- Create a systemd service unit file:
sudo tee /etc/systemd/system/bind_exporter.service<<EOF
[Unit]
Description=Prometheus
Documentation=https://github.com/digitalocean/bind_exporter
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP \$MAINPID
ExecStart=/usr/local/bin/bind_exporter \
  --bind.pid-file=/var/run/named/named.pid \
  --bind.timeout=20s \
  --web.listen-address=0.0.0.0:9153 \
  --web.telemetry-path=/metrics \
  --bind.stats-url=http://localhost:8053/ \
  --bind.stats-groups=server,view,tasks

SyslogIdentifier=prometheus
Restart=always

[Install]
WantedBy=multi-user.target
EOF

- Reload systemd and start bind_exporter service
#sudo systemctl daemon-reload
#sudo systemctl restart bind_exporter.service

- Enable the service to start on boot:
#sudo systemctl enable bind_exporter.service

- Open the port on the firewall
#sudo firewall-cmd --add-port=9153/tcp --permanent
#sudo firewall-cmd --reload

5.Configure Prometheus Server
- Edit file prometheus.yml
#sudo vi /etc/prometheus/prometheus.yml

- Add the jobs definition

- job_name: dns-master
    static_configs:
      - targets: ['10.1.5.3:9153']
        labels:
          alias: dns-master

  - job_name: dns-slave1
    static_configs:
      - targets: ['10.1.5.4:9153']
        labels:
          alias: dns-slave

#sudo systemctl restart prometheus

6. Add Grafana Dashboard
- Use already created Grafana dashboard ID is 1666
- Import Bind Grafana Dashboard by navigating to Dashboard > Import

source : https://computingforgeeks.com/monitor-bind-dns-server-with-prometheus-grafana/?expand_article=1

Tuesday, May 25, 2021

Prometheus and Grafana : Monitor Apache

1. Download apache_exporter
#wget https://github.com/Lusitaniae/apache_exporter/releases/download/v1.0.2/apache_exporter-1.0.2.linux-amd64.tar.gz

2.Install apache_exporter
#tar xvzf apache_exporter-1.0.2.linux-amd64.tar.gz
#cd apache_exporter-1.0.2.linux-amd64
#chown apache:apache apache_exporter
# mv apache_exporter /usr/bin

3.Create apache_exporter services
#vi /etc/systemd/system/apache-exporter.service
- insert script as below

[Unit]
Description=Apache Server Exporter
Documentation=https://github.com/Lusitaniae/apache_exporter
After=network-online.target

[Service]
User=apache
Group=apache
Restart=on-failure
ExecStart=/usr/bin/apache_exporter

[Install]
WantedBy=multi-user.target

4.Enable apache_exporter services

#systemctl daemon-reload
#systemctl enable apache-exporter.servic
# systemctl start apache-exporter.service

5.curl the locahost with port 9117
#curl http://localhost:9117/metrics
#systemctl restart httpd

* makes sure allow port 9117 in firewall

source: