I recently wrote an
article where I installed Prometheus on Ubuntu 20.04 http://www.whiteboardcoder.com/2021/01/installing-prometheus-on-ubuntu-2004.html
[1]
Now I want to start
getting some real data into it to have something to graph!
One good first step is
to use Prometheus Node Exporter https://prometheus.io/docs/guides/node-exporter/
[2]
https://github.com/prometheus/node_exporter
[3]
There are two good
reasons to start with node exporter.
One, it will provide tons on Unix information about your server… Memory
usage, disk usage, kernel info etc.
Two, you can use it to suck up other data you create with your own cron
jobs that create prometheus formatted data and put it in the correct folder.
Download and setup
Using https://www.digitalocean.com/community/tutorials/how-to-install-prometheus-on-ubuntu-16-04
[4]
> lsb_release -a |
On this particular server I have set up a second drive
located at /prometheus and that is where I put prometheus data
Create new user for node exporter
|
Head over to https://github.com/prometheus/node_exporter
Go find the latest (click on latest)
Right click on this guy and get the copy the link in my case
its https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.darwin-amd64.tar.gz
|
Untar it and install
|
Create a folder to use for extra metrics
|
SystemD setup
Create the systemD file
> sudo vi
/lib/systemd/system/node_exporter.service |
[Unit] [Service] [Install]
|
Enable the service so it will auto start on reboot
> sudo systemctl
enable node_exporter |
> sudo
systemctl status node_exporter |
Wahoo
Test it out
> sudo
systemctl start node_exporter |
Now pull ports and test.
> ssh
prometheus -L 9090:localhost:9090 –L 9100:localhost:9100 |
Wahoo data.
Now to scrape it
The data is available now but we still need to tell prometheus to scrape the data.
So let’s tweak the prometheus settings. (Prometheus is running on the same server)
> sudo vi
/prometheus/pheus/prometheus.yml |
Now add another thing to scrape on this same server.
- job_name:
'node_exporter' |
Restart Prometheus
> sudo
systemctl restart prometheus |
Now let’s check prometheus and see if its getting the data.
Open Targets
Looks like its scraping it.
Go to Graph
Search for
node_cpu{mode="system"} |
There is data!
Custom Data
If I look at /lib/systemd/system/node_exporter.service
> sudo vi
/lib/systemd/system/node_exporter.service |
I have set the variable collector.textfile.directory to look at
the folder /prometheus/metrics for “extra” prometheus formatted data to ingest
and have node exporter show at :9100/metrics
So let me make a simple python program and create a cron job to
run it.
> sudo mkdir
/prometheus/code |
#!/usr/bin/env
python3 import
sys base_dir="/prometheus/metrics/" ########################## #Test if base folder exist try: prom_data += "# HELP
my_test_data_02 just some test data\n" prom_data += "# HELP my_test_data_03
just some test data\n" f = open(base_dir +
"/my_data.prom", 'w') except Exception as e: |
> sudo chown
node_exporter:node_exporter /prometheus/code/prometheus_random.py |
Let me switch to the node_exporter user and run the python code.
> sudo su
node_exporter -s /bin/bash |
Now check the output
> cat
/prometheus/metrics/my_data.prom |
Now let me run a curl to prove that node_exporter is getting
this extra data
> curl -s
localhost:9100/metrics | egrep
my_test_data |
Wahoo now let me set up a curl to make up new random data
every 5 minutes
Exit out of the node_exporter user
> sudo vi
/etc/cron.d/my_fake_data |
And place the following into it
*/5
* * * * node_exporter /prometheus/code/prometheus_random.py |
Now the file should update every 5 minutes
Now to go look at the data
my_test_data_01
Sweet it is working J
References
[1] Installing Prometheus on
Ubuntu 20.04
http://www.whiteboardcoder.com/2021/01/installing-prometheus-on-ubuntu-2004.html
Accessed 1/2020
[2] MONITORING LINUX HOST METRICS
WITH THE NODE EXPORTER
https://prometheus.io/docs/guides/node-exporter/
Accessed 1/2020
[3] Node Exporeter’s Github page
http://www.whiteboardcoder.com/2021/01/installing-prometheus-on-ubuntu-2004.html
Accessed 1/2020
[4] How To Install Prometheus on
Ubuntu 16.04
https://www.digitalocean.com/community/tutorials/how-to-install-prometheus-on-ubuntu-16-04
Accessed 1/2020
Nice Post thank you very much for sharing such a useful information and will definitely saved and revisit your site and i have bookmarked to check out new things frm your post.
ReplyDeleteData Science Course
This is an informative and knowledgeable article. therefore, I would like to thank you for your effort in writing this article.
ReplyDeleteBest Digital Marketing Courses in Bangalore
I was browsing the internet for information and found your blog. I am impressed with the information you have on this blog.
ReplyDeleteMLOps Course
Informative Post. The information you have posted is very useful and sites you have referred was good. Thanks for sharing.
ReplyDeleteData Science Course with Placement
We are really grateful for your blog post. You will find a lot of approaches after visiting your post. Great work thank you.
ReplyDeleteCloud Computing Training in Bangalore
Actually I read it yesterday but I had some ideas about it and today I wanted to read it again because it is so well written.
ReplyDeleteIoT Training
Very nice job... Thanks for sharing this amazing and educative blog post!
ReplyDeleteData Science Course in Chandigarh
This is an informative and knowledgeable article. therefore, I would like to thank you for your effort in writing this article.
ReplyDeleteData Scientist Course in Chandigarh
Very informative Blog! There is so much information here that can help thank you for sharing.
ReplyDeleteData Analytics Course in Bangalore
We are really grateful for your blog post. You will find a lot of approaches after visiting your post. Great work thank you.
ReplyDeleteData Analytics Course in Chandigarh
I am excited about this blog. It is an informative subject. It helped me a lot in solving some problems. Your opportunity is so fantastic and the style of work so fast.
ReplyDeleteData Science Training in Ernakulam
Excellent effort to make this blog more wonderful and informative. The information shared was very useful.
ReplyDeleteData Analytics Course in Chandigarh
I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. Keep up the good work. Waiting for your next article
ReplyDeleteBusiness Analytics Course in Jabalpur