How to Install Prometheus in Linux Ubuntu 18.04

Posted on

Introduction

This article will show how to install prometheus in Linux Ubuntu 18.04 in several steps. There are few steps for having the installation of prometheus runs in Linux Ubuntu 18.04 normally. According to the main official website of Prometheus in this link, Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. Since its inception in 2012, many companies and organizations have adopted Prometheus. The project has a very active developer and user community. It is now a standalone open source project and maintained independently of any company. To emphasize this, and to clarify the project’s governance structure, Prometheus joined the Cloud Native Computing Foundation in 2016 as the second hosted project, after Kubernetes. In order to put it simple, Prometheus is an open-source monitoring system with a dimensional data model, flexible query language, efficient time series database and modern alerting approach.

Installation

The easiest way is using the regular ‘apt’ tool exist in Linux Ubuntu distribution. First of all, search the package by executing the following command :

root@hostname:~# apt search prometheus
Sorting... Done
Full Text Search... Done
cadvisor/bionic 0.27.1+dfsg-1 amd64
  analyze resource usage and performance characteristics of running containers

collectd-core/bionic-updates 5.7.2-2ubuntu1.1 amd64
  statistics collection and monitoring daemon (core system)

golang-github-docker-go-metrics-dev/bionic 0.0~git20161110.0.0f35294-1 all
  Package for metrics collection in Docker projects

golang-github-google-cadvisor-dev/bionic 0.27.1+dfsg-1 all
  analyze resource usage and performance of running containers

golang-github-grpc-ecosystem-go-grpc-prometheus-dev/bionic 1.1+git20170826.0dafe0d-1 all
  Prometheus monitoring for gRPC Go servers

golang-github-mwitkow-go-conntrack-dev/bionic 0.0~git20161129.cc309e4-1 all
  Go middleware for net.Conn tracking

golang-github-prometheus-alertmanager-dev/bionic 0.6.2+ds-3 amd64
  Handle and deliver alerts created by Prometheus -- source

golang-github-prometheus-client-golang-dev/bionic 0.8.0-2 all
  Prometheus instrumentation library for Go applications

golang-github-prometheus-client-model-dev/bionic 0.0.2+git20150212.12.fa8ad6f-2 all
  data model artifacts for Prometheus

golang-github-prometheus-common-dev/bionic 0+git20180110.89604d1-1 all
  Common libraries for Prometheus components

golang-github-prometheus-tsdb-dev/bionic 0.0~git20180118.467948f-1 all
  Prometheus storage layer library

golang-prometheus-client-dev/bionic 0.8.0-2 all
  Transitional package for golang-github-prometheus-client-golang-dev

libnet-prometheus-perl/bionic 0.05-1 all
  module to export monitoring metrics for Prometheus

prometheus/bionic 2.1.0+ds-1 amd64
  Monitoring system and time series database

prometheus-alertmanager/bionic 0.6.2+ds-3 amd64
  Handle and deliver alerts created by Prometheus

prometheus-apache-exporter/bionic 0.5.0+ds-1 amd64
  Prometheus exporter for Apache server metrics

prometheus-bind-exporter/bionic 0.2~git20161221+dfsg-1 amd64
  Prometheus exporter for Bind server metrics

prometheus-blackbox-exporter/bionic 0.11.0+ds-4 amd64
  Blackbox prober for Prometheus

prometheus-mailexporter/bionic 1.0-2 amd64
  exports prometheus-style metrics about mail server functionality

prometheus-mongodb-exporter/bionic 1.0.0-2 amd64
  Prometheus exporter for MongoDB

prometheus-mysqld-exporter/bionic 0.9.0+ds-3 amd64
  Prometheus exporter for MySQL server.

prometheus-node-exporter/bionic 0.15.2+ds-1 amd64
  Prometheus exporter for machine metrics

prometheus-pgbouncer-exporter/bionic 1.7-1 all
  Export metrics from pgbouncer to Prometheus

prometheus-postgres-exporter/bionic 0.4.1+ds-2 amd64
  Prometheus exporter for PostgreSQL server metrics

prometheus-pushgateway/bionic 0.4.0+ds-1ubuntu1 amd64
  Prometheus exporter for ephemereal jobs

prometheus-sql-exporter/bionic 0.2.0.ds-3 amd64
  Flexible SQL Exporter for Prometheus

prometheus-varnish-exporter/bionic 1.2-1 amd64
  Prometheus exporter for Varnish

python-django-prometheus/bionic 1.0.6-1 all
  Django middlewares to enable monitoring with Prometheus (Python 2)

python-prometheus-client/bionic 0.1.1-1 all
  Python 2 client for the Prometheus monitoring system

python3-django-prometheus/bionic 1.0.6-1 all
  Django middlewares to enable monitoring with Prometheus (Python 3)

python3-prometheus-client/bionic 0.1.1-1 all
  Python 3 client for the Prometheus monitoring system

ruby-mmap2/bionic 2.2.7-1build2 amd64
  Mmap class implement memory-mapped file objects for Ruby 2.x

ruby-prometheus-client-mmap/bionic 0.9.1-1 amd64
  suite of instrumentation metric primitives

root@hostname:~# 

Apparently, according to the search output, the prometheus package is availabe. So, continue on by executing the following command to use ‘apt’ tool to install prometheus. Execute it as follows :

root@hostname:/etc/apt/sources.list.d# sudo apt-get install prometheus prometheus-node-exporter prometheus-pushgateway prometheus-alertmanager -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  daemon libjs-angularjs libjs-bootstrap libjs-d3 libjs-eonasdan-bootstrap-datetimepicker libjs-jquery-hotkeys libjs-moment libjs-mustache libjs-rickshaw
The following NEW packages will be installed:
  daemon libjs-angularjs libjs-bootstrap libjs-d3 libjs-eonasdan-bootstrap-datetimepicker libjs-jquery-hotkeys libjs-moment libjs-mustache libjs-rickshaw prometheus prometheus-alertmanager
  prometheus-node-exporter prometheus-pushgateway
0 upgraded, 13 newly installed, 0 to remove and 38 not upgraded.
Need to get 7,147 kB/16.2 MB of archives.
After this operation, 67.3 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic/universe amd64 prometheus amd64 2.1.0+ds-1 [7,147 kB]
Fetched 2,719 kB in 5s (569 kB/s)       
Preconfiguring packages ...
Selecting previously unselected package libjs-jquery-hotkeys.
(Reading database ... 326004 files and directories currently installed.)
Preparing to unpack .../00-libjs-jquery-hotkeys_0~20130707+git2d51e3a9+dfsg-2ubuntu1_all.deb ...
Unpacking libjs-jquery-hotkeys (0~20130707+git2d51e3a9+dfsg-2ubuntu1) ...
Selecting previously unselected package daemon.
Preparing to unpack .../01-daemon_0.6.4-1build1_amd64.deb ...
Unpacking daemon (0.6.4-1build1) ...
Selecting previously unselected package libjs-angularjs.
Preparing to unpack .../02-libjs-angularjs_1.5.10-1_all.deb ...
Unpacking libjs-angularjs (1.5.10-1) ...
Selecting previously unselected package libjs-bootstrap.
Preparing to unpack .../03-libjs-bootstrap_3.3.7+dfsg-2_all.deb ...
Unpacking libjs-bootstrap (3.3.7+dfsg-2) ...
Selecting previously unselected package libjs-d3.
Preparing to unpack .../04-libjs-d3_3.5.17-2_all.deb ...
Unpacking libjs-d3 (3.5.17-2) ...
Selecting previously unselected package libjs-moment.
Preparing to unpack .../05-libjs-moment_2.20.1+ds-1_all.deb ...
Unpacking libjs-moment (2.20.1+ds-1) ...
Selecting previously unselected package libjs-rickshaw.
Preparing to unpack .../06-libjs-rickshaw_1.5.1.dfsg-2_all.deb ...
Unpacking libjs-rickshaw (1.5.1.dfsg-2) ...
Selecting previously unselected package libjs-eonasdan-bootstrap-datetimepicker.
Preparing to unpack .../07-libjs-eonasdan-bootstrap-datetimepicker_4.17.47-3_all.deb ...
Unpacking libjs-eonasdan-bootstrap-datetimepicker (4.17.47-3) ...
Selecting previously unselected package libjs-mustache.
Preparing to unpack .../08-libjs-mustache_2.3.0-2_all.deb ...
Unpacking libjs-mustache (2.3.0-2) ...
Selecting previously unselected package prometheus.
Preparing to unpack .../09-prometheus_2.1.0+ds-1_amd64.deb ...
Unpacking prometheus (2.1.0+ds-1) ...
Selecting previously unselected package prometheus-alertmanager.
Preparing to unpack .../10-prometheus-alertmanager_0.6.2+ds-3_amd64.deb ...
Unpacking prometheus-alertmanager (0.6.2+ds-3) ...
Selecting previously unselected package prometheus-node-exporter.
Preparing to unpack .../11-prometheus-node-exporter_0.15.2+ds-1_amd64.deb ...
Unpacking prometheus-node-exporter (0.15.2+ds-1) ...
Selecting previously unselected package prometheus-pushgateway.
Preparing to unpack .../12-prometheus-pushgateway_0.4.0+ds-1ubuntu1_amd64.deb ...
Unpacking prometheus-pushgateway (0.4.0+ds-1ubuntu1) ...
Setting up libjs-moment (2.20.1+ds-1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Setting up prometheus-node-exporter (0.15.2+ds-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/prometheus-node-exporter.service → /lib/systemd/system/prometheus-node-exporter.service.
Setting up libjs-d3 (3.5.17-2) ...
Setting up libjs-angularjs (1.5.10-1) ...
Setting up libjs-jquery-hotkeys (0~20130707+git2d51e3a9+dfsg-2ubuntu1) ...
Setting up libjs-rickshaw (1.5.1.dfsg-2) ...
Processing triggers for systemd (237-3ubuntu10.24) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up libjs-bootstrap (3.3.7+dfsg-2) ...
Setting up daemon (0.6.4-1build1) ...
Setting up libjs-mustache (2.3.0-2) ...
Setting up prometheus-pushgateway (0.4.0+ds-1ubuntu1) ...
Setting up prometheus-alertmanager (0.6.2+ds-3) ...
Setting up libjs-eonasdan-bootstrap-datetimepicker (4.17.47-3) ...
Setting up prometheus (2.1.0+ds-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/prometheus.service → /lib/systemd/system/prometheus.service.
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for systemd (237-3ubuntu10.24) ...
root@hostname:/etc/apt/sources.list.d# 

Starting the Prometheus service

After successfully install prometheus, start the service.  Execute the following command  as in the following output below :

root@hostname:~# systemctl start prometheus
root@hostname:~#

Don’t forget to check the status of the prometheus service. Type the command ‘systemctl status prometheus’ to be able to check the status of the service as follows :

root@hostname:~# systemctl status prometheus
● prometheus.service - Monitoring system and time series database
Loaded: loaded (/lib/systemd/system/prometheus.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2019-07-24 09:57:07 WIB; 35min ago
Docs: https://prometheus.io/docs/introduction/overview/
Main PID: 1793 (prometheus)
Tasks: 16 (limit: 4915)
CGroup: /system.slice/prometheus.service
└─1793 /usr/bin/prometheus

Jul 24 09:57:19 hostname prometheus[1793]: level=info ts=2019-07-24T02:57:18.869532169Z caller=web.go:359 component=web msg="Start listening for connections" address=0.0.0.0:9090
Jul 24 09:57:19 hostname prometheus[1793]: level=info ts=2019-07-24T02:57:18.869519583Z caller=main.go:492 msg="Starting TSDB ..."
Jul 24 09:57:41 hostname prometheus[1793]: level=warn ts=2019-07-24T02:57:41.121695275Z caller=head.go:320 component=tsdb msg="unknown series references in WAL samples" count=3987
Jul 24 09:57:41 hostname prometheus[1793]: level=info ts=2019-07-24T02:57:41.122743246Z caller=main.go:502 msg="TSDB started"
Jul 24 09:57:41 hostname prometheus[1793]: level=info ts=2019-07-24T02:57:41.122812309Z caller=main.go:578 msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
Jul 24 09:57:41 hostname prometheus[1793]: level=info ts=2019-07-24T02:57:41.625069683Z caller=main.go:479 msg="Server is ready to receive web requests."
Jul 24 09:57:41 hostname prometheus[1793]: level=info ts=2019-07-24T02:57:41.625105932Z caller=manager.go:59 component="scrape manager" msg="Starting scrape manager..."
Jul 24 10:00:01 hostname prometheus[1793]: level=info ts=2019-07-24T03:00:01.070444333Z caller=compact.go:387 component=tsdb msg="compact blocks" count=1 mint=1563926400000 maxt=1563933600000
Jul 24 10:00:02 hostname prometheus[1793]: level=info ts=2019-07-24T03:00:02.920449512Z caller=head.go:348 component=tsdb msg="head GC completed" duration=2.530086ms
Jul 24 10:00:02 hostname prometheus[1793]: level=info ts=2019-07-24T03:00:02.92049808Z caller=head.go:357 component=tsdb msg="WAL truncation completed" duration=1.825µs
root@hostname:~#

Finally, in order for prometheus service is automatically start and running every time the machine is rebooting, do the following command :

root@hostname:~# systemctl enable prometheus
Synchronizing state of prometheus.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable prometheus
root@hostname:~#

If all the above steps are successfully executed, all of the overall process for installing Prometheus has done.

Leave a Reply