{"id":3155,"date":"2019-05-29T21:43:09","date_gmt":"2019-05-29T18:43:09","guid":{"rendered":"https:\/\/kifarunix.com\/?p=3155"},"modified":"2020-02-08T20:26:09","modified_gmt":"2020-02-08T17:26:09","slug":"install-prometheus-on-ubuntu-18-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-prometheus-on-ubuntu-18-04\/","title":{"rendered":"Install Prometheus on Ubuntu 18.04"},"content":{"rendered":"\n<p>In this guide, we are going to learn how to install Prometheus on Ubuntu 18.04. <a href=\"https:\/\/github.com\/prometheus\" target=\"_blank\" rel=\"noopener\">Prometheus<\/a>&nbsp;is an open-source systems and service monitoring system. It collects metrics from configured targets via HTTP calls at given intervals, evaluates rule expressions, displays the results, and can trigger alerts if some conditions are met.<\/p>\n\n\n\n<p>We have covered the installation of Prometheus on Debian 9 and Fedora 29\/28 in our previous guides;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-configure-prometheus-on-fedora-29-fedora-28\/\">Install and Configure Prometheus on Fedora 29\/Fedora 28<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-and-configure-prometheus-on-debian-9\/\" target=\"_blank\">Install and Configure Prometheus on Debian 9<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install Prometheus on Ubuntu 18.04<\/h2>\n\n\n\n<p>Prometheus is made up various components;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The main&nbsp;<a href=\"https:\/\/github.com\/prometheus\/prometheus\" target=\"_blank\" rel=\"noopener\">Prometheus server<\/a>&nbsp;which scrapes and stores time series data<\/li><li><a href=\"https:\/\/prometheus.io\/docs\/instrumenting\/clientlibs\/\" target=\"_blank\" rel=\"noopener\">Client libraries<\/a>&nbsp;for instrumenting application code<\/li><li><a href=\"https:\/\/github.com\/prometheus\/pushgateway\" target=\"_blank\" rel=\"noopener\">Push gateway<\/a>&nbsp;for supporting short-lived jobs<\/li><li><a href=\"https:\/\/prometheus.io\/docs\/instrumenting\/exporters\/\" target=\"_blank\" rel=\"noopener\">Exporters<\/a>&nbsp;for exporting existing metrics from third-party systems as Prometheus metrics in cases where it is not feasible to instrument a given system with Prometheus metrics directly for example in services like HAProxy, StatsD, Graphite, etc.<\/li><li><a href=\"https:\/\/github.com\/prometheus\/alertmanager\" target=\"_blank\" rel=\"noopener\">Alertmanager<\/a>&nbsp;to handle alerts.<\/li><\/ul>\n\n\n\n<p>Prometheus and its other components are available on the default Ubuntu 18.04 repositories. However, the available versions may not be up-to-date. You can verify the available versions by running the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt-cache policy prometheus\nprometheus:\n  Installed: (none)\n  Candidate: 2.1.0+ds-1\n  Version table:\n     2.1.0+ds-1 500\n        500 http:\/\/ke.archive.ubuntu.com\/ubuntu bionic\/universe amd64 Packages<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Install Prometheus Using Pre-compiled Binaries<\/h3>\n\n\n\n<p>To ensure that you got the latest versions of Prometheus installed, you can use the pre-compiled binaries which can be downloaded directly from Prometheus <a rel=\"noreferrer noopener\" aria-label=\"downloads section (opens in a new tab)\" href=\"https:\/\/prometheus.io\/download\/\" target=\"_blank\">downloads section<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Create Prometheus System User and Group<\/h4>\n\n\n\n<p>Before you can begin the installation, you have to create Prometheus system user and group as shown below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>useradd -M -r -s \/bin\/false prometheus<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Create Prometheus Directories<\/h4>\n\n\n\n<p>Next, you need to create the directories that will be used to store Prometheus configurations files and other data.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mkdir \/etc\/prometheus \/var\/lib\/prometheus<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Download Prometheus Binary<\/h4>\n\n\n\n<p>Next, navigate to the downloads section and grab the latest version of Prometheus. You simply use wget to download it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>wget https:\/\/github.com\/prometheus\/prometheus\/releases\/download\/v2.10.0\/prometheus-2.10.0.linux-amd64.tar.gz<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Install Prometheus on Ubuntu 18.04<\/h4>\n\n\n\n<p>Once you have downloaded the binary, extract it and proceed to install it as follows.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>tar xzf prometheus-2.10.0.linux-amd64.tar.gz<\/code><\/pre>\n\n\n\n<p>Next, copy the <strong>prometheus<\/strong> and <strong>promtool<\/strong> binaries under the extracted archive folder to <code>\/usr\/local\/bin<\/code>&nbsp;directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cp prometheus-2.10.0.linux-amd64\/{prometheus,promtool} \/usr\/local\/bin\/<\/code><\/pre>\n\n\n\n<p>After copying, set the user and group ownership of these binaries to <strong>prometheus<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chown prometheus:prometheus \/usr\/local\/bin\/{prometheus,promtool}<\/code><\/pre>\n\n\n\n<p>Next, copy the&nbsp;<code>consoles<\/code>&nbsp;and&nbsp;<code>console_libraries<\/code>&nbsp;directories to&nbsp;<code>\/etc\/prometheus<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cp -r prometheus-2.10.0.linux-amd64\/{consoles,console_libraries} \/etc\/prometheus\/<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Create Prometheus Configuration file<\/h4>\n\n\n\n<p>The default Prometheus configuration file is located on the extracted archive folder. For the demonstration purposes, we will just copy it to Prometheus configuration directory and modify it as follows;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cp prometheus-2.10.0.linux-amd64\/prometheus.yml \/etc\/prometheus\/prometheus.yml<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>less \/etc\/prometheus\/prometheus.yml\nglobal:\n  scrape_interval:     15s\n  evaluation_interval: 15s\n\nrule_files:\n\nscrape_configs:\n  - job_name: 'prometheus'\n    static_configs:\n    - targets: ['localhost:9090']<\/code><\/pre>\n\n\n\n<p>In the default configuration there is a single job, called&nbsp;<strong>prometheus<\/strong>&nbsp;, which scrapes the time series data&nbsp;<strong>exposed<\/strong>&nbsp;by the&nbsp;<strong>Prometheus<\/strong>&nbsp;server. The job contains a single, statically configured, target, the localhost on&nbsp;<strong>port 9090<\/strong>.<\/p>\n\n\n\n<p>Next, set the user and group ownership of Prometheus configuration directory, <strong>\/etc\/prometheus<\/strong> to <strong>prometheus<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chown -R prometheus:prometheus \/etc\/prometheus<\/code><\/pre>\n\n\n\n<p>Once that is done, similarly set the user and group ownership of Prometheus data directory, <strong>\/var\/lib\/prometheus\/<\/strong> to <strong>prometheus<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>chown prometheus:prometheus \/var\/lib\/prometheus<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Running Prometheus<\/h4>\n\n\n\n<p>At the very least, Prometheus is now set and is ready to run. However, at this point we do not have the Prometheus service configuration file and hence, we can run it as shown below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>prometheus --config.file=\/etc\/prometheus\/prometheus.yml<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Create Prometheus Systemd Service File<\/h4>\n\n\n\n<p>To be able to run prometheus as a service, you can create a systemd service configuration file as shown below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/systemd\/system\/prometheus.service<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>[Unit]\nDescription=Prometheus Time Series Collection and Processing Server\nWants=network-online.target\nAfter=network-online.target\n\n[Service]\nUser=prometheus\nGroup=prometheus\nType=simple\nExecStart=\/usr\/local\/bin\/prometheus \\\n    --config.file \/etc\/prometheus\/prometheus.yml \\\n    --storage.tsdb.path \/var\/lib\/prometheus\/ \\\n    --web.console.templates=\/etc\/prometheus\/consoles \\\n    --web.console.libraries=\/etc\/prometheus\/console_libraries\n\n[Install]\nWantedBy=multi-user.target<\/code><\/pre>\n\n\n\n<p>Next, reload systemd configuration files and start and enable Prometheus to run on system boot.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl daemon-reload\nsystemctl start prometheus\nsystemctl enable prometheus<\/code><\/pre>\n\n\n\n<p>To check the status of Prometheus service;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl status prometheus<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\u25cf prometheus.service - Prometheus Time Series Collection and Processing Server\n   Loaded: loaded (\/etc\/systemd\/system\/prometheus.service; enabled; vendor preset: enabled)\n   Active: active (running) since Wed 2019-05-29 18:56:28 EAT; 8s ago\n Main PID: 15835 (prometheus)\n    Tasks: 7 (limit: 1130)\n   CGroup: \/system.slice\/prometheus.service\n           \u2514\u250015835 \/usr\/local\/bin\/prometheus --config.file \/etc\/prometheus\/prometheus.yml --storage.tsdb.path \/var\/lib\/prometheus\/ --web.console.templa...<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Access Prometheus Web Interface<\/h3>\n\n\n\n<p>You can now access Prometheus using the address, <strong>http:\/\/&lt;server_IP&gt;:9090<\/strong>. This will take you to Prometheus&#8217;s built-in expression browser.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/prometheus-dashboard.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1353\" height=\"464\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/prometheus-dashboard.png\" alt=\"install Prometheus on Ubuntu 18.04: Prometheus built-in expression browser\" class=\"wp-image-3161\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/prometheus-dashboard.png 1353w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/prometheus-dashboard-768x263.png 768w\" sizes=\"(max-width: 1353px) 100vw, 1353px\" \/><\/a><\/figure>\n\n\n\n<p>The scraped metrics can be viewed under, <strong>http:\/\/&lt;server_IP&gt;:9090\/metrics<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/prometheus-metrics.png\"><img loading=\"lazy\" decoding=\"async\" width=\"992\" height=\"551\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/prometheus-metrics.png\" alt=\"install Prometheus on Ubuntu 18.04: Prometheus scraped metrics\" class=\"wp-image-3162\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/prometheus-metrics.png 992w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/prometheus-metrics-768x427.png 768w\" sizes=\"(max-width: 992px) 100vw, 992px\" \/><\/a><\/figure>\n\n\n\n<p>To check the status of your node, navigate to <strong>Status<\/strong> &gt; <strong>Targets<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/node-status.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1182\" height=\"361\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/node-status.png\" alt=\"Prometheus node status\" class=\"wp-image-3163\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/node-status.png 1182w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/05\/node-status-768x235.png 768w\" sizes=\"(max-width: 1182px) 100vw, 1182px\" \/><\/a><\/figure>\n\n\n\n<p>Well, that is just about it on how to install Prometheus on Ubuntu 18.04. Want to learn how to monitor Linux hosts with Prometheus Node Exporter? Check the link below;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/monitor-linux-system-metrics-with-prometheus-node-exporter\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Monitor Linux System Metrics with Prometheus Node Exporter<\/a><\/p>\n\n\n\n<p>Check our related articles by following the links below;<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-graylog-3-0-on-centos-7\/\" target=\"_blank\">Install Graylog 3.0 on CentOS 7<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/monitor-squid-access-logs-with-graylog-server\/\" target=\"_blank\">Monitor Squid Access Logs with Graylog Server<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/monitor-squid-logs-with-grafana-and-graylog\/\" target=\"_blank\">Monitor Squid logs with Grafana and Graylog<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-grafana-6-2-x-on-ubuntu-18-04-debian-9\/\" target=\"_blank\">Install Grafana 6.2.x on Ubuntu 18.04\/Debian 9<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-grafana-metrics-monitoring-tool-on-debian-9\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Install Grafana Metrics Monitoring Tool on Debian 9<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we are going to learn how to install Prometheus on Ubuntu 18.04. Prometheus&nbsp;is an open-source systems and service monitoring system. It collects<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,72,294,64],"tags":[295,67],"class_list":["post-3155","post","type-post","status-publish","format-standard","hentry","category-howtos","category-monitoring","category-prometheus","category-ubuntu-18-04","tag-prometheus","tag-ubuntu-18-04","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/3155"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=3155"}],"version-history":[{"count":8,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/3155\/revisions"}],"predecessor-version":[{"id":5008,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/3155\/revisions\/5008"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=3155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=3155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=3155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}