SlideShare une entreprise Scribd logo
1  sur  17
How-To Go
The Extra Mile
on Monitoring
Grafana + Prometheus + JMX
+ PushGateway
Introduction
With this presentation, you will be able get even more metrics from your
Cluster/Applications.
Pre-Assumptions
1. Grafana Installed
2. Prometheus Installed
JMX
Create and Download JMX Exporter Directory
sudo mkdir -p /opt/jmx-exporter;
sudo cd /opt/jmx-exporter;
sudo wget
https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.15.0/jmx_prometheus_javaagent-
0.15.0.jar;
Note: just need to change the highlighted values for your own values.
JMX - Use Case Kafka
Download Kafka YML
sudo cd /opt/jmx-exporter;
wget https://github.com/prometheus/jmx_exporter/blob/master/example_configs/kafka-2_0_0.yml;
mv kafka-2_0_0.yml kafka_broker.yml;
[Cloudera] CM - Kafka Configuration (broker_java_opts)
-Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -
javaagent:/opt/prometheus/jmx_prometheus_javaagent-0.15.0.jar=7072:/opt/prometheus/kafka_broker.yml
Restart Service and Check HTTP Metrics
Note: just need to change the highlighted values for your own values.
JMX - Use Case Kafka
Add Job to Prometheus Config YML
sudo nano /etc/prometheus/prometheus.yml;
- job_name: 'kafka_jmx'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'
scrape_interval: 5s
static_configs:
- targets: ['10.111.22.33:7072']
Restart Prometheus Service
sudo systemctl restart prometheus;
Note: just need to change the highlighted values for your own values.
JMX - Use Case NiFi
Create NiFi Metrics Config YML
sudo nano /usr/hdp/nifi/conf/nifi.yml;
lowercaseOutputLabelNames: true
lowercaseOutputName: true
rules:- pattern: ".*"
Add to Nifi Bootstrap Config File
sudo nano /usr/hdp/nifi/conf/bootstrap.conf; java.arg.18=-javaagent:/opt/jmx-exporter/jmx_prometheus_javaagent-
0.15.0.jar=7474:/usr/hdp/nifi/conf/nifi.yml
Note: java.arg.XX the XX value should be unique!
Restart Prometheus Service
sudo systemctl restart prometheus;
Note: just need to change the highlighted values for your own values.
Add Job to Prometheus Config YML
sudo nano /etc/prometheus/prometheus.yml;
- job_name: 'nifi_jmx'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'
scrape_interval: 5s
static_configs:
- targets: ['10.111.22.44:7474']
PushGateway
Download PushGateway
sudo cd /u01/downloads;
sudo wget https://github.com/prometheus/pushgateway/releases/download/v1.4.0/pushgateway-1.4.0.linux-amd64.tar.gz;
sudo tar xvzf pushgateway-1.4.0.linux-amd64.tar.gz && mv pushgateway-1.4.0.linux-amd64/pushgateway
/usr/local/bin/pushgateway;
PushGateway
Create User
sudo useradd -m -s /bin/false pushgateway && id pushgateway;
sudo chown pushgateway:pushgateway /usr/local/bin/pushgateway;
Create User
sudo nano /etc/prometheus/prometheus.yml;
global:
scrape_interval: 1s
scrape_configs:
- job_name: 'pushgateway'
honor_labels: true
Static_configs:
- targets: ['10.111.22.33:9091']
Adjust the firewall
sudo firewall-cmd --add-port=9091/tcp --permanent && firewall-cmd --reload;
Note: just need to change the highlighted values for your own values.
PushGateway
Creating a Systemd service file for Prometheus Server
sudo nano /etc/systemd/system/pushgateway.service;
[Unit]
Description=Custom Metrics on PushGateway
Wants=network-online.target
After=network-online.target
[Service]
User=pushgateway
Group=pushgateway
Type=simple
ExecStart=/usr/local/bin/pushgateway 
--web.listen-address=:9091 
--web.enable-admin-api 
--web.telemetry-path=/metrics 
--persistence.file=/tmp/metric.store 
--persistence.interval=5m
[Install]
WantedBy=multi-user.target
Note: just need to change the highlighted values for your own values.
PushGateway
Reload the Systemctl
sudo systemctl daemon-reload;
Now start and enable Prometheus to run on boot
sudo systemctl start pushgateway && sudo systemctl enable pushgateway;
Confirm Pushgateway is UP
sudo netstat -tunlp | grep pushgateway;
Note: just need to change the highlighted values for your own values.
PushGateway
Create Top Custom Metrics Script
sudo nano metricsTOP;
#!/bin/bash
# CPU Usage %
z=$(ps aux | grep -v '[' )
while read -r z
do
var=$var$(awk 'NR>1 {print "cpu_usage{user=""$1"" , pid=""$2"" , process=""$11"", arg=""$12" "$13" "$14" "$15"" }", $3z}');
done <<< "$z"
curl -X POST -H "Content-Type: text/plain" --data "$var
" http://localhost:9091/metrics/job/top/instance/hostname01
# Memory Usage Bytes
x=$(ps aux | grep -v '[' )
while read -r x
do
var2=$var2$(awk 'NR>1 {print "memory_usage{user=""$1"" , pid=""$2"" , process=""$11"", arg=""$12" "$13" "$14" "$15"" }", $6x}');
done <<< "$x"
curl -X POST -H "Content-Type: text/plain" --data "$var2
" http://localhost:9091/metrics/job/top/instance/hostname01
sudo chmod u+x metricsTOP && ./metricsTOP;
PushGateway
Create Crontab Job
sudo contrab -e;
* * * * * for i in {1..60}; do /path/metricsTOP & sleep 1; done
Create IOTop Custom Metrics Script
sudo nano metricsTOP;
* * * * * for i in {1..60}; do /path/metricsTOP & sleep 1; done
PushGateway
Create IOTop Custom Metrics Script
# IO Usage %
t=$(iotop -Pkqbn 1 | grep -v '[' )
while read -r t
do
var3=$var3$(awk 'NR>2 {print "iotop_usage{user=""$3"" , pid=""$1"" , stream="%" ,process=""$12"", arg=""$13" "$14" "$15" "$16"" }", $10}');
done <<< "$t"
curl -X POST -H "Content-Type: text/plain" --data "$var3
" http://localhost:9091/metrics/job/iotop/instance/hostname01
# IO Read Kbs
u=$(iotop -Pkqbn 1 | grep -v '[' )
while read -r u
do
var4=$var4$(awk 'NR>2 {print "iotop_read{user=""$3"" , pid=""$1"" , stream="read" ,process=""$12"", arg=""$13" "$14" "$15" "$16"" }", $4}');
done <<< "$u"
curl -X POST -H "Content-Type: text/plain" --data "$var4
" http://localhost:9091/metrics/job/iotop/instance/hostname01
# IO Write Kbs
v=$(iotop -Pkqbn 1 | grep -v '[' )
while read -r v
do
var5=$var5$(awk 'NR>2 {print "iotop_write{user=""$3"" , pid=""$1"" , stream="write" ,process=""$12"", arg=""$13" "$14" "$15" "$16"" }", $6}');
done <<< "$v"
curl -X POST -H "Content-Type: text/plain" --data "$var5
" http://localhost:9091/metrics/job/iotop/instance/hostname01
Note: just need to change the highlighted values for your own values.
Grafana
Grafana
Thanks
Big Data Engineer
Tiago Simões

Contenu connexe

Tendances

Set up Hadoop Cluster on Amazon EC2
Set up Hadoop Cluster on Amazon EC2Set up Hadoop Cluster on Amazon EC2
Set up Hadoop Cluster on Amazon EC2
IMC Institute
 
Running hadoop on ubuntu linux
Running hadoop on ubuntu linuxRunning hadoop on ubuntu linux
Running hadoop on ubuntu linux
TRCK
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
Carlos Sanchez
 

Tendances (20)

An example Hadoop Install
An example Hadoop InstallAn example Hadoop Install
An example Hadoop Install
 
Hadoop installation
Hadoop installationHadoop installation
Hadoop installation
 
Set up Hadoop Cluster on Amazon EC2
Set up Hadoop Cluster on Amazon EC2Set up Hadoop Cluster on Amazon EC2
Set up Hadoop Cluster on Amazon EC2
 
Hadoop on ec2
Hadoop on ec2Hadoop on ec2
Hadoop on ec2
 
Running hadoop on ubuntu linux
Running hadoop on ubuntu linuxRunning hadoop on ubuntu linux
Running hadoop on ubuntu linux
 
Install and Configure Ubuntu for Hadoop Installation for beginners
Install and Configure Ubuntu for Hadoop Installation for beginners Install and Configure Ubuntu for Hadoop Installation for beginners
Install and Configure Ubuntu for Hadoop Installation for beginners
 
Hadoop single node setup
Hadoop single node setupHadoop single node setup
Hadoop single node setup
 
Automated infrastructure is on the menu
Automated infrastructure is on the menuAutomated infrastructure is on the menu
Automated infrastructure is on the menu
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)
 
Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點
 
Automated Java Deployments With Rpm
Automated Java Deployments With RpmAutomated Java Deployments With Rpm
Automated Java Deployments With Rpm
 
Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptop
 
DevOps(3) : Ansible - (MOSG)
DevOps(3) : Ansible - (MOSG)DevOps(3) : Ansible - (MOSG)
DevOps(3) : Ansible - (MOSG)
 
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
 
From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
 
How to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero ClicksHow to Develop Puppet Modules: From Source to the Forge With Zero Clicks
How to Develop Puppet Modules: From Source to the Forge With Zero Clicks
 
Making Your Capistrano Recipe Book
Making Your Capistrano Recipe BookMaking Your Capistrano Recipe Book
Making Your Capistrano Recipe Book
 
Multinode kubernetes-cluster
Multinode kubernetes-clusterMultinode kubernetes-cluster
Multinode kubernetes-cluster
 
Hadoop completereference
Hadoop completereferenceHadoop completereference
Hadoop completereference
 
Preparation study of_docker - (MOSG)
Preparation study of_docker  - (MOSG)Preparation study of_docker  - (MOSG)
Preparation study of_docker - (MOSG)
 

Similaire à How to go the extra mile on monitoring

Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
Omar Reygaert
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 new
Yiwei Ma
 
Nginx 0.8.x 安装手册
Nginx 0.8.x 安装手册Nginx 0.8.x 安装手册
Nginx 0.8.x 安装手册
Yiwei Ma
 

Similaire à How to go the extra mile on monitoring (20)

Control your deployments with Capistrano
Control your deployments with CapistranoControl your deployments with Capistrano
Control your deployments with Capistrano
 
Continuous delivery with docker
Continuous delivery with dockerContinuous delivery with docker
Continuous delivery with docker
 
Web Applications with Eclipse RT and Docker in the Cloud
Web Applications with Eclipse RT and Docker in the CloudWeb Applications with Eclipse RT and Docker in the Cloud
Web Applications with Eclipse RT and Docker in the Cloud
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next Frontier
 
Plone deployment made easy
Plone deployment made easyPlone deployment made easy
Plone deployment made easy
 
9 creating cent_os 7_mages_for_dpdk_training
9 creating cent_os 7_mages_for_dpdk_training9 creating cent_os 7_mages_for_dpdk_training
9 creating cent_os 7_mages_for_dpdk_training
 
Docker
DockerDocker
Docker
 
Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
 
Nodejs in Production
Nodejs in ProductionNodejs in Production
Nodejs in Production
 
Capistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient wayCapistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient way
 
Docker practice
Docker practiceDocker practice
Docker practice
 
Tensorflow in Docker
Tensorflow in DockerTensorflow in Docker
Tensorflow in Docker
 
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
 
X64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 newX64服务器 lnmp服务器部署标准 new
X64服务器 lnmp服务器部署标准 new
 
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
PuppetConf 2016: The Challenges with Container Configuration – David Lutterko...
 
Challenges of container configuration
Challenges of container configurationChallenges of container configuration
Challenges of container configuration
 
Nginx 0.8.x 安装手册
Nginx 0.8.x 安装手册Nginx 0.8.x 安装手册
Nginx 0.8.x 安装手册
 
Magento 2 Development
Magento 2 DevelopmentMagento 2 Development
Magento 2 Development
 
Free radius billing server with practical vpn exmaple
Free radius billing server with practical vpn exmapleFree radius billing server with practical vpn exmaple
Free radius billing server with practical vpn exmaple
 
DCEU 18: Tips and Tricks of the Docker Captains
DCEU 18: Tips and Tricks of the Docker CaptainsDCEU 18: Tips and Tricks of the Docker Captains
DCEU 18: Tips and Tricks of the Docker Captains
 

Dernier

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Dernier (20)

Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 

How to go the extra mile on monitoring

  • 1. How-To Go The Extra Mile on Monitoring Grafana + Prometheus + JMX + PushGateway
  • 2. Introduction With this presentation, you will be able get even more metrics from your Cluster/Applications.
  • 4. JMX Create and Download JMX Exporter Directory sudo mkdir -p /opt/jmx-exporter; sudo cd /opt/jmx-exporter; sudo wget https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.15.0/jmx_prometheus_javaagent- 0.15.0.jar; Note: just need to change the highlighted values for your own values.
  • 5. JMX - Use Case Kafka Download Kafka YML sudo cd /opt/jmx-exporter; wget https://github.com/prometheus/jmx_exporter/blob/master/example_configs/kafka-2_0_0.yml; mv kafka-2_0_0.yml kafka_broker.yml; [Cloudera] CM - Kafka Configuration (broker_java_opts) -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false - javaagent:/opt/prometheus/jmx_prometheus_javaagent-0.15.0.jar=7072:/opt/prometheus/kafka_broker.yml Restart Service and Check HTTP Metrics Note: just need to change the highlighted values for your own values.
  • 6. JMX - Use Case Kafka Add Job to Prometheus Config YML sudo nano /etc/prometheus/prometheus.yml; - job_name: 'kafka_jmx' # metrics_path defaults to '/metrics' # scheme defaults to 'http' scrape_interval: 5s static_configs: - targets: ['10.111.22.33:7072'] Restart Prometheus Service sudo systemctl restart prometheus; Note: just need to change the highlighted values for your own values.
  • 7. JMX - Use Case NiFi Create NiFi Metrics Config YML sudo nano /usr/hdp/nifi/conf/nifi.yml; lowercaseOutputLabelNames: true lowercaseOutputName: true rules:- pattern: ".*" Add to Nifi Bootstrap Config File sudo nano /usr/hdp/nifi/conf/bootstrap.conf; java.arg.18=-javaagent:/opt/jmx-exporter/jmx_prometheus_javaagent- 0.15.0.jar=7474:/usr/hdp/nifi/conf/nifi.yml Note: java.arg.XX the XX value should be unique! Restart Prometheus Service sudo systemctl restart prometheus; Note: just need to change the highlighted values for your own values. Add Job to Prometheus Config YML sudo nano /etc/prometheus/prometheus.yml; - job_name: 'nifi_jmx' # metrics_path defaults to '/metrics' # scheme defaults to 'http' scrape_interval: 5s static_configs: - targets: ['10.111.22.44:7474']
  • 8. PushGateway Download PushGateway sudo cd /u01/downloads; sudo wget https://github.com/prometheus/pushgateway/releases/download/v1.4.0/pushgateway-1.4.0.linux-amd64.tar.gz; sudo tar xvzf pushgateway-1.4.0.linux-amd64.tar.gz && mv pushgateway-1.4.0.linux-amd64/pushgateway /usr/local/bin/pushgateway;
  • 9. PushGateway Create User sudo useradd -m -s /bin/false pushgateway && id pushgateway; sudo chown pushgateway:pushgateway /usr/local/bin/pushgateway; Create User sudo nano /etc/prometheus/prometheus.yml; global: scrape_interval: 1s scrape_configs: - job_name: 'pushgateway' honor_labels: true Static_configs: - targets: ['10.111.22.33:9091'] Adjust the firewall sudo firewall-cmd --add-port=9091/tcp --permanent && firewall-cmd --reload; Note: just need to change the highlighted values for your own values.
  • 10. PushGateway Creating a Systemd service file for Prometheus Server sudo nano /etc/systemd/system/pushgateway.service; [Unit] Description=Custom Metrics on PushGateway Wants=network-online.target After=network-online.target [Service] User=pushgateway Group=pushgateway Type=simple ExecStart=/usr/local/bin/pushgateway --web.listen-address=:9091 --web.enable-admin-api --web.telemetry-path=/metrics --persistence.file=/tmp/metric.store --persistence.interval=5m [Install] WantedBy=multi-user.target Note: just need to change the highlighted values for your own values.
  • 11. PushGateway Reload the Systemctl sudo systemctl daemon-reload; Now start and enable Prometheus to run on boot sudo systemctl start pushgateway && sudo systemctl enable pushgateway; Confirm Pushgateway is UP sudo netstat -tunlp | grep pushgateway; Note: just need to change the highlighted values for your own values.
  • 12. PushGateway Create Top Custom Metrics Script sudo nano metricsTOP; #!/bin/bash # CPU Usage % z=$(ps aux | grep -v '[' ) while read -r z do var=$var$(awk 'NR>1 {print "cpu_usage{user=""$1"" , pid=""$2"" , process=""$11"", arg=""$12" "$13" "$14" "$15"" }", $3z}'); done <<< "$z" curl -X POST -H "Content-Type: text/plain" --data "$var " http://localhost:9091/metrics/job/top/instance/hostname01 # Memory Usage Bytes x=$(ps aux | grep -v '[' ) while read -r x do var2=$var2$(awk 'NR>1 {print "memory_usage{user=""$1"" , pid=""$2"" , process=""$11"", arg=""$12" "$13" "$14" "$15"" }", $6x}'); done <<< "$x" curl -X POST -H "Content-Type: text/plain" --data "$var2 " http://localhost:9091/metrics/job/top/instance/hostname01 sudo chmod u+x metricsTOP && ./metricsTOP;
  • 13. PushGateway Create Crontab Job sudo contrab -e; * * * * * for i in {1..60}; do /path/metricsTOP & sleep 1; done Create IOTop Custom Metrics Script sudo nano metricsTOP; * * * * * for i in {1..60}; do /path/metricsTOP & sleep 1; done
  • 14. PushGateway Create IOTop Custom Metrics Script # IO Usage % t=$(iotop -Pkqbn 1 | grep -v '[' ) while read -r t do var3=$var3$(awk 'NR>2 {print "iotop_usage{user=""$3"" , pid=""$1"" , stream="%" ,process=""$12"", arg=""$13" "$14" "$15" "$16"" }", $10}'); done <<< "$t" curl -X POST -H "Content-Type: text/plain" --data "$var3 " http://localhost:9091/metrics/job/iotop/instance/hostname01 # IO Read Kbs u=$(iotop -Pkqbn 1 | grep -v '[' ) while read -r u do var4=$var4$(awk 'NR>2 {print "iotop_read{user=""$3"" , pid=""$1"" , stream="read" ,process=""$12"", arg=""$13" "$14" "$15" "$16"" }", $4}'); done <<< "$u" curl -X POST -H "Content-Type: text/plain" --data "$var4 " http://localhost:9091/metrics/job/iotop/instance/hostname01 # IO Write Kbs v=$(iotop -Pkqbn 1 | grep -v '[' ) while read -r v do var5=$var5$(awk 'NR>2 {print "iotop_write{user=""$3"" , pid=""$1"" , stream="write" ,process=""$12"", arg=""$13" "$14" "$15" "$16"" }", $6}'); done <<< "$v" curl -X POST -H "Content-Type: text/plain" --data "$var5 " http://localhost:9091/metrics/job/iotop/instance/hostname01 Note: just need to change the highlighted values for your own values.