{"id":32165,"date":"2018-11-09T18:35:15","date_gmt":"2018-11-09T13:05:15","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=32165"},"modified":"2018-11-09T18:35:15","modified_gmt":"2018-11-09T13:05:15","slug":"install-prometheus-on-ubuntu-16-04","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/install-prometheus-on-ubuntu-16-04\/","title":{"rendered":"Install Prometheus on Ubuntu 16.04"},"content":{"rendered":"<p><span style=\"color: #003366;\"><strong>Install Prometheus on Ubuntu 16.04<\/strong><\/span><\/p>\n<h3 id=\"prometheus\"><span style=\"color: #008080;\">Prometheus<\/span><\/h3>\n<p><strong>Prometheus<\/strong> could be a powerful and open-source, ASCII text file observance system that collects metrics from your services and stores them in an exceedingly time-series information.<\/p>\n<p>It proposes a multi-dimensional data model, a versatile <a href=\"https:\/\/www.wikitechy.com\/tutorials\/neo4j\/neo4j-query-language-cypher\" target=\"_blank\" rel=\"noopener\">query language<\/a>, and numerous visualization image prospects through tools like <strong>Grafana<\/strong>.<\/p>\n<p>Prometheus solely exports metrics regarding itself (e.g. the number of requests it&#8217;s received, its memory consumption, etc.). But, you&#8217;ll greatly expand Prometheus by installing exporters, optional gratia programs that generate further metrics.<\/p>\n<p><strong>Exporters<\/strong>\u2014both the official ones that the Prometheus team maintains further because the <strong>community-contributed ones<\/strong>\u2014provide info regarding everything from infrastructure, databases, and web servers to electronic communication systems, APIs, and more.<\/p>\n<h3 id=\"some-of-the-foremost-common-selections-include\"><span style=\"color: #3366ff;\">Some of the foremost common selections include:<\/span><\/h3>\n<ul>\n<li><span style=\"color: #003300;\"><strong>node_exporter<\/strong><\/span> &#8211; This produces metrics regarding infrastructure, as well as the present CPU, memory, and disk usage, further as I\/O and network statistics, like the quantity of bytes scan from a disk or a server&#8217;s average load.<\/li>\n<li><span style=\"color: #003300;\"><strong>blackbox_exporter<\/strong><\/span> &#8211; This generates metrics derived from inquisitory protocols like protocol HTTP and HTTPS to see end convenience, time interval, and more.<\/li>\n<li><span style=\"color: #003300;\"><strong>mysqld_exporter<\/strong><\/span> &#8211; This gathers metrics associated with a MySQL server, like the quantity of executed queries, average response time interval, and cluster replication standing.<\/li>\n<li><span style=\"color: #003300;\"><strong>rabbitmq_exporter<\/strong><\/span> &#8211; This outputs metrics regarding the RabbitMQ electronic communication system, as well as the number of messages printed, the number of messages able to be delivered, and also the size of all the messages within the queue.<\/li>\n<li><span style=\"color: #003300;\"><strong>nginx-vts-exporter<\/strong> <\/span>&#8211; This provides metrics regarding associate Nginx web server victimization the Nginx VTS module, as well as the number of open connections, the quantity of sent responses (grouped by response codes), and also the total size of sent or received requests in bytes.<\/li>\n<\/ul>\n<p>You will notice a lot of complete list of each official and community-contributed exporters on Prometheus&#8217; web site.<\/p>\n<p>You&#8217;ll install, configure, and secure Prometheus and Node Exporter to come up with metrics that may build it easier to observe your server&#8217;s performance.<\/p>\n<h3 id=\"prerequisites\"><span style=\"color: #ff0000;\">Prerequisites<\/span><\/h3>\n<p>Before following this tutorial check that you have:<\/p>\n<ul>\n<li>One <strong>Ubuntu 16.04 Droplet<\/strong>, established by following the<strong> Initial Server Setup with Ubuntu sixteen.04<\/strong> tutorial, as well as a sudo non-root user and a firewall.<\/li>\n<li>Nginx installed by following the primary 2 steps of the way to <a href=\"https:\/\/www.wikitechy.com\/technology\/how-to-install-nginx-on-ubuntu-16-04\/\" target=\"_blank\" rel=\"noopener\">Install Nginx on Ubuntu 16.04 tutorial<\/a>.<\/li>\n<\/ul>\n<h3 id=\"step-1-create-service-users\"><span style=\"color: #800080;\">Step 1 \u2014 Create Service Users<\/span><\/h3>\n<p>For the safety functions, we&#8217;ll begin by making 2 new user accounts, <strong>prometheus<\/strong> and <strong>node_exporter<\/strong>. We&#8217;ll use these accounts throughout the tutorial to isolate the possession on Prometheus&#8217; core files and directories.<\/p>\n<p>Create these 2 users, and use the <strong>&#8211;no-create-home<\/strong> and <strong>&#8211;shell \/bin\/false<\/strong> choices in order that these users cannot log into the server.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo useradd --no-create-home --shell \/bin\/false prometheus<br\/>$ sudo useradd --no-create-home --shell \/bin\/false node_exporter<\/code><\/pre> <\/div>\n<p>Before downloading the Prometheus binaries, create the essential directories to store Prometheus&#8217; files and data.<\/p>\n<p>The upcoming standard Linux conventions, we&#8217;ll generate a directory in <strong>\/etc<\/strong> for Prometheus&#8217; configuration files and a directory in <strong>\/var\/lib<\/strong> for its data.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo mkdir \/etc\/prometheus<br\/>$ sudo mkdir \/var\/lib\/prometheus<\/code><\/pre> <\/div>\n<p>Set user and group ownership for new directories of prometheus user.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo chown prometheus:prometheus \/etc\/prometheus<br\/>$ sudo chown prometheus:prometheus \/var\/lib\/prometheus<\/code><\/pre> <\/div>\n<p>With our users in place, we will currently download prometheus so produce the specified configuration file to run for 1st time.<\/p>\n<h3 id=\"step-2-download-prometheus\"><span style=\"color: #800080;\">Step 2 \u2014 Download Prometheus<\/span><\/h3>\n<p>Download and take the present stable version of Prometheus into your home directory. You&#8217;ll notice the newest binaries together with their checksums on the Prometheus transfer page.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ cd ~<br\/>$ curl -LO https:\/\/github.com\/prometheus\/prometheus\/releases\/download\/v2.0.0\/prometheus-2.0.0.linux-amd64.tar.gz<\/code><\/pre> <\/div>\n<p>Next, use the <strong>sha256sum<\/strong> command to come up with a checksum of the downloaded file:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sha256sum prometheus-2.0.0.linux-amd64.tar.gz<\/code><\/pre> <\/div>\n<p>Compare the output from this command with the checksum on the Prometheus download page to confirm that your file is each real and not corrupted.<\/p>\n<h3 id=\"output\"><span style=\"color: #333399;\">Output<\/span><\/h3>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">e12917b25b32980daee0e9cf879d9ec197e2893924bd1574604eb0f550034d46  prometheus-2.0.0.linux-amd64.tar.gz<\/code><\/pre> <\/div>\n<p>If the checksums do not match, take away the downloaded file and repeat the preceding steps to re-download the file.<\/p>\n<p>Now, take out the downloaded archive.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ tar xvf prometheus-2.0.0.linux-amd64.tar.gz<\/code><\/pre> <\/div>\n<p>This can produce a directory known as <strong>prometheus-1.7.1.linux-amd64<\/strong> containing 2 binary files (<strong>prometheus and promtool<\/strong>), consoles, <strong>console_libraries<\/strong>, and several other example files.<\/p>\n<p>Copy the 2 binaries to the<strong> \/usr\/local\/bin<\/strong> directory.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo cp prometheus-2.0.0.linux-amd64\/prometheus \/usr\/local\/bin\/<br\/>$ sudo cp prometheus-2.0.0.linux-amd64\/promtool \/usr\/local\/bin\/<\/code><\/pre> <\/div>\n<p>Set the user and cluster possession on the binaries to the Prometheus user created in Step 1.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo chown prometheus:prometheus \/usr\/local\/bin\/prometheus<br\/>$ sudo chown prometheus:prometheus \/usr\/local\/bin\/promtool<\/code><\/pre> <\/div>\n<p>Copy the consoles and<strong> console_libraries<\/strong> directories to <strong>\/etc\/prometheus.<\/strong><\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo cp -r prometheus-2.0.0.linux-amd64\/consoles \/etc\/prometheus<br\/>$ sudo cp -r prometheus-2.0.0.linux-amd64\/console_libraries \/etc\/prometheus<\/code><\/pre> <\/div>\n<p>Set the user and cluster ownership on the directories to the prometheus user. Using the <strong>-R flag<\/strong> will confirm that ownership is set on the files inside the directory as well.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo chown -R prometheus:prometheus \/etc\/prometheus\/consoles<br\/>$ sudo chown -R prometheus:prometheus \/etc\/prometheus\/console_libraries<\/code><\/pre> <\/div>\n<p>Lastly, take away the leftover files from your home directory as they&#8217;re not required.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ rm -rf prometheus-2.0.0.linux-amd64.tar.gz prometheus-2.0.0.linux-amd64<\/code><\/pre> <\/div>\n<p>Now Prometheus is installed, we&#8217;ll produce its configuration and service files in preparation of its initial run.<\/p>\n<h3 id=\"step-3-configure-prometheus\"><span style=\"color: #800080;\">Step 3 \u2014 Configure Prometheus<\/span><\/h3>\n<p>In the \/e<strong>tc\/prometheus<\/strong> directory, use nano or your favorite text editor to make a configuration file named <strong>Prometheus.yml<\/strong>. For now, this file can contain barely enough info to run Prometheus for the primary time.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo nano \/etc\/prometheus\/prometheus.yml<\/code><\/pre> <\/div>\n<p><span style=\"color: #ff0000;\"><strong>Warning:<\/strong> <\/span>Prometheus&#8217; configuration file uses the YAML format, that strictly forbids tabs and needs 2 areas for indentation. Prometheus can fail to start out if the configuration file is incorrectly formatted.<\/p>\n<p>In the global settings, outline the default interval for scraping metrics. Note that Prometheus can apply these settings to each exporter unless a personal exporter&#8217;s own settings override the globals.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Prometheus config file part 1 - \/etc\/prometheus\/prometheus.yml<\/span> <\/div> <pre class=\"language-haml code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-haml code-embed-code\">global:<br\/>  scrape_interval: 15s<\/code><\/pre> <\/div>\n<p>This <strong>scrape_interval<\/strong> value tells Prometheus to gather metrics from its exporters every fifteen seconds, that is long enough for many exporters.<\/p>\n<p>Now, add Prometheus itself to the list of exporters to scrape from with the subsequent<strong> scrape_configs directive:<\/strong><\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Prometheus config file part 2 - \/etc\/prometheus\/prometheus.yml<\/span> <\/div> <pre class=\"language-haml code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-haml code-embed-code\">...<br\/>scrape_configs:<br\/>  - job_name: &#039;prometheus&#039;<br\/>    scrape_interval: 5s<br\/>    static_configs:<br\/>      - targets: [&#039;localhost:9090&#039;]<\/code><\/pre> <\/div>\n<p>Prometheus uses the<strong> job_name<\/strong> to label exporters in queries and on graphs, therefore make certain to choose one thing descriptive here.<\/p>\n<p>And, as Prometheus exports necessary information regarding itself that you simply will use for observance performance and debugging, we&#8217;ve overridden the global <strong>scrape_interval<\/strong> directive from 15 seconds to 5 seconds for a lot of frequent updates.<\/p>\n<p>Lastly, Prometheus uses the <strong>static_configs<\/strong> and targets directives to see wherever exporters square measure running. Since this explicit exporter is running on an identical server as Prometheus itself, we will use localhost rather than IP address together with the default port, 9090.<\/p>\n<p>Your configuration file will to currently seem like this:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Prometheus config file - \/etc\/prometheus\/prometheus.yml<\/span> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">global:<br\/>  scrape_interval: 15s<br\/><br\/>scrape_configs:<br\/>  - job_name: &#039;prometheus&#039;<br\/>    scrape_interval: 5s<br\/>    static_configs:<br\/>      - targets: [&#039;localhost:9090&#039;]<\/code><\/pre> <\/div>\n<p>Save the file and exit your text editor.<\/p>\n<p>Now, set the user and cluster possession on the configuration file to the Prometheus user created in Step 1.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo chown prometheus:prometheus \/etc\/prometheus\/prometheus.yml<\/code><\/pre> <\/div>\n<p>With the configuration complete, we&#8217;re able to take a look at <strong>prometheus<\/strong> by running it for the primary time.<\/p>\n<h3 id=\"step-4-running-prometheus\"><span style=\"color: #800080;\">Step 4 \u2014 Running Prometheus<\/span><\/h3>\n<p><strong>Startup Prometheus<\/strong> because the Prometheus user, providing the trail to each the configuration file and also the data directory.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo -u prometheus \/usr\/local\/bin\/prometheus \\<br\/>$    --config.file \/etc\/prometheus\/prometheus.yml \\<br\/>$   --storage.tsdb.path \/var\/lib\/prometheus\/ \\<br\/>$    --web.console.templates=\/etc\/prometheus\/consoles \\<br\/>$    --web.console.libraries=\/etc\/prometheus\/console_libraries<\/code><\/pre> <\/div>\n<p>The output contains info regarding Prometheus&#8217; loading progress, configuration file, and connected services. It conjointly confirms that Prometheus is listening on<strong> port 9090.<\/strong><\/p>\n<h3 id=\"output-2\"><span style=\"color: #333399;\">Output<\/span><\/h3>\n<pre class=\"code-pre \"><code>level=info ts=2017-11-17T18:37:27.474530094Z caller=main.go:215 msg=\"Starting Prometheus\" version=\"(version=2.0.0, branch=HEAD, re\r\nvision=0a74f98628a0463dddc90528220c94de5032d1a0)\"\r\nlevel=info ts=2017-11-17T18:37:27.474758404Z caller=main.go:216 build_context=\"(go=go1.9.2, user=root@615b82cb36b6, date=20171108-\r\n07:11:59)\"\r\nlevel=info ts=2017-11-17T18:37:27.474883982Z caller=main.go:217 host_details=\"(Linux 4.4.0-98-generic #121-Ubuntu SMP Tue Oct 10 1\r\n4:24:03 UTC 2017 x86_64 prometheus-update (none))\"\r\nlevel=info ts=2017-11-17T18:37:27.483661837Z caller=web.go:380 component=web msg=\"Start listening for connections\" address=0.0.0.0\r\n:9090\r\nlevel=info ts=2017-11-17T18:37:27.489730138Z caller=main.go:314 msg=\"Starting TSDB\"\r\nlevel=info ts=2017-11-17T18:37:27.516050288Z caller=targetmanager.go:71 component=\"target manager\" msg=\"Starting target manager...\r\n\"\r\nlevel=info ts=2017-11-17T18:37:27.537629169Z caller=main.go:326 msg=\"TSDB started\"\r\nlevel=info ts=2017-11-17T18:37:27.537896721Z caller=main.go:394 msg=\"Loading configuration file\" filename=\/etc\/prometheus\/promethe\r\nus.yml\r\nlevel=info ts=2017-11-17T18:37:27.53890004Z caller=main.go:371 msg=\"Server is ready to receive requests.\"<\/code><\/pre>\n<p>If an error message comes, ensure that you&#8217;ve got used <strong>YAML syntax<\/strong> in your configuration file so follow the on-screen directions to resolve the matter.<\/p>\n<p>Now, halt Prometheus by pressing<strong> CTRL+C,<\/strong> so open a brand new <strong>systemd<\/strong> service file.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo nano \/etc\/systemd\/system\/prometheus.service<\/code><\/pre> <\/div>\n<p>The service file tells <strong>systemd<\/strong> to run Prometheus because the Prometheus user, with the configuration file situated within the<strong> \/etc\/prometheus\/prometheus.ym<\/strong>l directory and to store its information within the<strong> \/var\/lib\/prometheus<\/strong> directory. (The details of systemd service files square measure on the far side the scope of this tutorial)<\/p>\n<p>Copy the subsequent content into the file:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Prometheus service file - \/etc\/systemd\/system\/prometheus.service<\/span> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">[Unit]<br\/>Description=Prometheus<br\/>Wants=network-online.target<br\/>After=network-online.target<br\/><br\/>[Service]<br\/>User=prometheus<br\/>Group=prometheus<br\/>Type=simple<br\/>ExecStart=\/usr\/local\/bin\/prometheus \\<br\/>    --config.file \/etc\/prometheus\/prometheus.yml \\<br\/>    --storage.tsdb.path \/var\/lib\/prometheus\/ \\<br\/>    --web.console.templates=\/etc\/prometheus\/consoles \\<br\/>    --web.console.libraries=\/etc\/prometheus\/console_libraries<br\/><br\/>[Install]<br\/>WantedBy=multi-user.target<\/code><\/pre> <\/div>\n<p>Finally, save the file and shut your text editor.<\/p>\n<p>To use the recently created service, reload systemd.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo systemctl daemon-reload<\/code><\/pre> <\/div>\n<p>You will currently begin Prometheus victimization the subsequent command:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo systemctl start prometheus<\/code><\/pre> <\/div>\n<p>To check that Prometheus is running, check the service&#8217;s status.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo systemctl status prometheus<\/code><\/pre> <\/div>\n<p>The output tells you Prometheus&#8217; status, main method symbol (PID), memory use, and more.<\/p>\n<p>If the service&#8217;s status is not active, follow the on-screen directions and re-trace the preceding steps to resolve the matter before continued the tutorial.<\/p>\n<h3 id=\"output-3\"><span style=\"color: #333399;\">Output<\/span><\/h3>\n<pre class=\"code-pre \"><code>\u25cf prometheus.service - Prometheus\r\n   Loaded: loaded (\/etc\/systemd\/system\/prometheus.service; disabled; vendor preset: enabled)\r\n   Active: <span class=\"highlight\">active<\/span> (running) since Fri 2017-07-21 11:40:40 UTC; 3s ago\r\n Main PID: 2104 (prometheus)\r\n    Tasks: 7\r\n   Memory: 13.8M\r\n      CPU: 470ms\r\n   CGroup: \/system.slice\/prometheus.service\r\n...<\/code><\/pre>\n<p>When you are able to move, press Q to quit the status command.<\/p>\n<p>Lastly, change the service to start on boot.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo systemctl enable prometheus<\/code><\/pre> <\/div>\n<p>Now that Prometheus is up and running, we will install an extra exporter to come up with metrics regarding our server&#8217;s resources.<\/p>\n<h3 id=\"step-5-downloading-node-exporter\"><span style=\"color: #800080;\">Step 5 \u2014 Downloading Node Exporter<\/span><\/h3>\n<p>To expand Prometheus on the far side metrics regarding itself solely, we&#8217;ll install an extra exporter known as Node exporter. Node exporter provides careful info regarding the system, as well as CPU, disk, and memory usage.<\/p>\n<p>First, download the present stable version of Node Exporter into your home directory. You&#8217;ll notice the newest binaries together with their checksums on Prometheus&#8217; download page.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ cd ~<br\/>$ curl -LO https:\/\/github.com\/prometheus\/node_exporter\/releases\/download\/v0.15.1\/node_exporter-0.15.1.linux-amd64.tar.gz<\/code><\/pre> <\/div>\n<p>Use the <strong>sha256sum<\/strong> command to create a checksum of the downloaded file:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sha256sum node_exporter-0.15.1.linux-amd64.tar.gz<\/code><\/pre> <\/div>\n<p>Now, verify the downloaded file&#8217;s integrity by <strong>comparing its checksum<\/strong> with the one on the download page.<\/p>\n<h3 id=\"output-4\"><span style=\"color: #333399;\">Output<\/span><\/h3>\n<pre class=\"code-pre \"><code><span class=\"highlight\">7ffb3773abb71dd2b2119c5f6a7a0dbca0cff34b24b2ced9e01d9897df61a127<\/span>  <span class=\"highlight\">node_exporter-0.15.1.linux-amd64.tar.gz<\/span><\/code><\/pre>\n<p>If the checksums do not match, take away the downloaded file and repeat the preceding steps.<\/p>\n<p>Now, unload downloaded archive.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ tar xvf node_exporter-0.15.1.linux-amd64.tar.gz<\/code><\/pre> <\/div>\n<p>This can produce a directory known as n<strong>ode_exporter-0.14.0.linux-amd64<\/strong> containing a computer file named node_exporter, a license, and a notice.<\/p>\n<p>Copy the binary to the <strong>\/usr\/local\/bin<\/strong> directory and set the user and cluster possession to the<strong> node_exporter<\/strong> user that you simply created in Step 1.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">$ sudo cp node_exporter-0.15.1.linux-amd64\/node_exporter \/usr\/local\/bin<br\/>$ sudo chown node_exporter:node_exporter \/usr\/local\/bin\/node_exporter<\/code><\/pre> <\/div>\n<p>Lastly, take away the leftover files from your home directory as they&#8217;re not required.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ rm -rf node_exporter-0.15.1.linux-amd64.tar.gz node_exporter-0.15.1.linux-amd64<\/code><\/pre> <\/div>\n<p>Now that you&#8217;ve got put in Node Exporter, you&#8217;ll take a look at it out by running it so we will produce a service file for it in order that it starts on boot.<\/p>\n<h3 id=\"step-6-running-node-exporter\"><span style=\"color: #800080;\">Step 6 \u2014 Running Node Exporter<\/span><\/h3>\n<p>The steps for running Node Exporter is the same as those for running Prometheus itself. Begin by making the <strong>Systemd<\/strong> service file for Node Exporter.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo nano \/etc\/systemd\/system\/node_exporter.service<\/code><\/pre> <\/div>\n<p>This service file tells your system to run Node Exporter because the <strong>node_exporter<\/strong> user with the default set of collectors enabled.<\/p>\n<p>Copy the subsequent content into the service file:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Node Exporter service file - \/etc\/systemd\/system\/node_exporter.service<\/span> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">[Unit]<br\/>Description=Node Exporter<br\/>Wants=network-online.target<br\/>After=network-online.target<br\/><br\/>[Service]<br\/>User=node_exporter<br\/>Group=node_exporter<br\/>Type=simple<br\/>ExecStart=\/usr\/local\/bin\/node_exporter<br\/><br\/>[Install]<br\/>WantedBy=multi-user.target<\/code><\/pre> <\/div>\n<p>Collectors outline that metrics Node Exporter can generate. You&#8217;ll see Node Exporter&#8217;s complete list of collectors\u2014including enabled by default and that deprecated\u2014in the Node Exporter <strong>README<\/strong> file.<\/p>\n<p>If you ever have to be compelled to override the default list of collectors, you&#8217;ll use the <strong>&#8211;collectors.enabled flag<\/strong>, like:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Node Exporter service file part - \/etc\/systemd\/system\/node_exporter.service<\/span> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">...<br\/>ExecStart=\/usr\/local\/bin\/node_exporter --collectors.enabled meminfo,loadavg,filesystem<br\/>...<\/code><\/pre> <\/div>\n<p>The preceding example would tell Node Exporter to create metrics victimization solely the <strong>meminfo, loadavg, and filesystem collectors.<\/strong> You&#8217;ll limit the collectors to but few or several you would like, however, note that there are not any blank areas before or when the commas.<\/p>\n<p>Save the file and shut your text editor.<\/p>\n<p>Finally, <strong>reload systemd<\/strong> to use the recently created service.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo systemctl daemon-reload<\/code><\/pre> <\/div>\n<p>At the end of the <strong>scrape_configs block<\/strong>, add a brand new entry known as node_exporter.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Prometheus config file part 1 - \/etc\/prometheus\/prometheus.yml<\/span> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">...<br\/>  - job_name: &#039;node_exporter&#039;<br\/>    scrape_interval: 5s<br\/>    static_configs:<br\/>      - targets: [&#039;localhost:9100&#039;]<\/code><\/pre> <\/div>\n<p>Because this Exporter is additionally running on an identical server as Prometheus itself. We will use localhost rather than <strong>IP address<\/strong> once more together with <strong>Node Exporter&#8217;s default port, 9100<\/strong>.<\/p>\n<p>Your whole configuration file ought to seem like this:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Prometheus config file - \/etc\/prometheus\/prometheus.yml<\/span> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">global:<br\/>  scrape_interval: 15s<br\/><br\/>scrape_configs:<br\/>  - job_name: &#039;prometheus&#039;<br\/>    scrape_interval: 5s<br\/>    static_configs:<br\/>      - targets: [&#039;localhost:9090&#039;]<br\/>  - job_name: &#039;node_exporter&#039;<br\/>    scrape_interval: 5s<br\/>    static_configs:<br\/>      - targets: [&#039;localhost:9100&#039;]   <\/code><\/pre> <\/div>\n<p>Save the file and exit your text editor once you are able to continue.<\/p>\n<p>Finally,<strong> restart Prometheus<\/strong> to place the changes into impact.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo systemctl restart prometheus<\/code><\/pre> <\/div>\n<p>Once again, <strong>verify<\/strong> that everything is running properly with the status command.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo systemctl status prometheus<\/code><\/pre> <\/div>\n<p>If the service&#8217;s status is not set to active, follow the on-screen directions and re-trace your previous steps before moving on.<\/p>\n<h3 id=\"output-5\"><span style=\"color: #333399;\">Output<\/span><\/h3>\n<pre class=\"code-pre \"><code>prometheus.service - Prometheus\r\n   Loaded: loaded (\/etc\/systemd\/system\/prometheus.service; disabled; vendor preset: enabled)\r\n   Active: <span class=\"highlight\">active<\/span> (running) since Fri 2017-07-21 11:46:39 UTC; 6s ago\r\n Main PID: 2219 (prometheus)\r\n    Tasks: 6\r\n   Memory: 19.9M\r\n      CPU: 433ms\r\n   CGroup: \/system.slice\/prometheus.service<\/code><\/pre>\n<p>We currently have <strong>Prometheus and Node Exporter installed,<\/strong> configured, and running. As a final precaution before connecting to the online interface, we&#8217;ll enhance our installation&#8217;s security with basic protocol HTTP authentication to confirm that unauthorized users cannot access our metrics.<\/p>\n<h3 id=\"step-8-securing-prometheus\"><span style=\"color: #800080;\">Step 8 \u2014 Securing Prometheus<\/span><\/h3>\n<p>Prometheus doesn&#8217;t embrace in-built authentication or the other general purpose security mechanism. On the one hand, this suggests you are obtaining an extremely versatile system with fewer configuration restraints; on the opposite hand, it means that it&#8217;s up to you to confirm that your metrics and overall setup square measure sufficiently secure.<\/p>\n<p>For simplicity&#8217;s sake, we&#8217;ll use Nginx to feature basic <a href=\"https:\/\/www.wikitechy.com\/angularjs\/angularjs-$http\" target=\"_blank\" rel=\"noopener\">HTTP<\/a> protocol authentication to our installation, that each Prometheus and its most popular<strong> data visualization tool, Grafana<\/strong>, totally support.<\/p>\n<p>Start by putting in <strong>apache2-utils<\/strong>, which is able to offer you access to the <strong>htpasswd<\/strong> utility for generating password files.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo apt-get update<br\/>$ sudo apt-get install apache2-utils<\/code><\/pre> <\/div>\n<p>Now, generate a password file by telling<strong> htpasswd<\/strong> wherever you wish to store the file and that username you want to use for authentication.<\/p>\n<p><span style=\"color: #800000;\"><strong>Note<\/strong><\/span>: <strong>htpasswd<\/strong> can prompt you to enter and re-confirm the password you want to go together with this user. Also, build note of each the username and password you enter here, as you will need them to log into Prometheus in Step 9.<\/p>\n<p>The results of this command could be a newly-created file known as <span style=\"color: #ff0000;\"><strong>.htpasswd<\/strong><\/span>, situated within the <strong>\/etc\/nginx<\/strong> directory, containing the username and a hashed version of the password you entered.<\/p>\n<p>Next, <strong>set up Nginx<\/strong> to use the newly-created passwords.<\/p>\n<p>First, build a Prometheus-specific copy of the default <strong>Nginx configuration file<\/strong> in order that you&#8217;ll revert back to the defaults later if you run into a haul.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo cp \/etc\/nginx\/sites-available\/default \/etc\/nginx\/sites-available\/prometheus<\/code><\/pre> <\/div>\n<p>Then, open the <strong>new configuration file<\/strong>.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo nano \/etc\/nginx\/sites-available\/prometheus<\/code><\/pre> <\/div>\n<p>Locate the <strong>location\/ block<\/strong> below the <a href=\"https:\/\/www.wikitechy.com\/tutorials\/ethical-hacking\/server-hacking\/what-is-a-server-and-its-types\" target=\"_blank\" rel=\"noopener\">server<\/a> block. It must look like:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">\/etc\/nginx\/sites-available\/default<\/span> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">...<br\/>    location \/ {<br\/>        try_files $uri $uri\/ =404;<br\/>    }<br\/>...<\/code><\/pre> <\/div>\n<p>As we are going to be forwarding all traffic to Prometheus, replace the <strong>try_files<\/strong> directive with the subsequent content:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">\/etc\/nginx\/sites-available\/prometheus<\/span> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">...<br\/>    location \/ {<br\/>        auth_basic &quot;Prometheus server authentication&quot;;<br\/>        auth_basic_user_file \/etc\/nginx\/.htpasswd;<br\/>        proxy_pass http:\/\/localhost:9090;<br\/>        proxy_http_version 1.1;<br\/>        proxy_set_header Upgrade $http_upgrade;<br\/>        proxy_set_header Connection &#039;upgrade&#039;;<br\/>        proxy_set_header Host $host;<br\/>        proxy_cache_bypass $http_upgrade;<br\/>    }<br\/>...<\/code><\/pre> <\/div>\n<p>These settings make sure that users can demonstrate at the beginning of every new session. In addition, the <strong>reverse proxy<\/strong> can direct all requests handled by this block to Prometheus.<\/p>\n<p>When you are finished creating changes, save the file and shut your text editor.<\/p>\n<p>Now, <strong>deactivate<\/strong> the default Nginx configuration file by removing the link thereto within the <strong>\/etc\/nginx\/sites-enabled<\/strong> directory, and activate the new configuration file by generating a link to it.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo rm \/etc\/nginx\/sites-enabled\/default<br\/>$ sudo ln -s \/etc\/nginx\/sites-available\/prometheus \/etc\/nginx\/sites-enabled\/<\/code><\/pre> <\/div>\n<p>Before restarting Nginx, check the<strong> configuration for errors<\/strong> victimization the subsequent command:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo nginx -t<\/code><\/pre> <\/div>\n<p>The output must indicate that the <strong>syntax is ok<\/strong> and also the<strong> test is successful<\/strong>. If you receive an error message, follow the on-screen directions to repair the matter before continuing to the following step.<\/p>\n<h3 id=\"an-output-of-nginx-configuration-tests\"><span style=\"color: #333399;\">An output of Nginx configuration tests<\/span><\/h3>\n<pre class=\"code-pre \"><code>nginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok\r\nnginx: configuration file \/etc\/nginx\/nginx.conf test is successful<\/code><\/pre>\n<p>Then, <strong>reload Nginx<\/strong> to include all of the changes.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo systemctl reload nginx<\/code><\/pre> <\/div>\n<p><strong>Verify<\/strong> that <a href=\"https:\/\/www.wikitechy.com\/technology\/nginx-error-connect-to-php5-fpm-sock-failed-13-permission-denied\/\" target=\"_blank\" rel=\"noopener\">Nginx<\/a> is up and running.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo systemctl status nginx<\/code><\/pre> <\/div>\n<p>If your output does not indicate that the service&#8217;s status is <span style=\"color: #ff0000;\"><strong>active<\/strong><\/span>, follow the on-screen messages and re-trace the preceding steps to resolve the difficulty before continued.<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <span class=\"code-embed-name\">Output<\/span> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">\u25cf nginx.service - A high performance web server and a reverse proxy server<br\/>   Loaded: loaded (\/lib\/systemd\/system\/nginx.service; enabled; vendor preset: en<br\/>   Active: active (running) since Mon 2017-07-31 21:20:57 UTC; 12min ago<br\/>  Process: 4302 ExecReload=\/usr\/sbin\/nginx -g daemon on; master_process on; -s r<br\/> Main PID: 3053 (nginx)<br\/>    Tasks: 2<br\/>   Memory: 3.6M<br\/>      CPU: 56ms<br\/>   CGroup: \/system.slice\/nginx.service<\/code><\/pre> <\/div>\n<p>At this time, we have a fully-functional and secured<strong> Prometheus server<\/strong>. Therefore we will log into the web interface to start observing metrics.<\/p>\n<h3 id=\"step-9-testing-prometheus\"><span style=\"color: #800080;\">Step 9 \u2014 Testing Prometheus<\/span><\/h3>\n<p>Prometheus provides a basic web interface for observance the status of itself and its exporters, queries, and generating graphs. But, because of the interface&#8217;s simplicity, the Prometheus team recommends to <strong>install and use Grafana<\/strong> for all the difficult than testing and debugging.<\/p>\n<p>In this tutorial, we&#8217;ll use the inbuilt web interface to <strong>confirm that Prometheus and Node Exporter<\/strong> are up and running, and we&#8217;ll conjointly take a glance at straightforward queries and graphs.<\/p>\n<p>To begin, purpose your <a href=\"https:\/\/www.wikitechy.com\/technology\/use-linux-mac-windows-vivaldi-web-browser\/\" target=\"_blank\" rel=\"noopener\">web browser<\/a> to <span style=\"color: #ff0000;\">http:\/\/your_server_ip.<\/span><\/p>\n<p>In the HTTP protocol authentication dialogue box, enter the <strong>username and password<\/strong> you selected in <strong>Step 8<\/strong>.<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-32172\" src=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Authentication.png\" alt=\"Prometheus-Authentication\" width=\"583\" height=\"295\" srcset=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Authentication.png 1154w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Authentication-300x152.png 300w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Authentication-768x388.png 768w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Authentication-1024x517.png 1024w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Authentication-990x500.png 990w\" sizes=\"(max-width: 583px) 100vw, 583px\" \/><\/p>\n<p>Once logged in, you will see the<strong> Expression<\/strong> Browser, wherever you&#8217;ll execute and visualize custom queries.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-32174 \" src=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Graph.png\" alt=\"Prometheus-Dashboard-Graph\" width=\"808\" height=\"413\" srcset=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Graph.png 1154w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Graph-300x153.png 300w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Graph-768x393.png 768w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Graph-1024x524.png 1024w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Graph-990x506.png 990w\" sizes=\"(max-width: 808px) 100vw, 808px\" \/><\/p>\n<p>Before performing any expressions, verify the status of each Prometheus and Node Explorer by clicking initial on the status menu at the highest of the screen so on the Targets menu possibility. As we&#8217;ve organized Prometheus to scrape each itself and Node Exporter, you must see each target listed within the <strong>UP<\/strong> state.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-32175\" src=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Targets.png\" alt=\"Prometheus-Dashboard-Targets\" width=\"716\" height=\"406\" srcset=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Targets.png 1154w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Targets-300x170.png 300w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Targets-768x436.png 768w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Targets-1024x581.png 1024w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Targets-990x562.png 990w\" sizes=\"(max-width: 716px) 100vw, 716px\" \/><\/p>\n<p>If either Exporter is missing or <strong><span style=\"color: #ff0000;\">displays an error message<\/span><\/strong>, check the service&#8217;s status with the subsequent commands:<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ sudo systemctl status prometheus<br\/>$ sudo systemctl status node_exporter<\/code><\/pre> <\/div>\n<p>The output for each service must report a status of Active: <span style=\"color: #ff0000;\"><strong>active<\/strong><\/span> (running). If a service either is not active in the least or is active however still not operating properly. Follow the on-screen directions and re-trace the previous steps before continuing.<\/p>\n<p>Next, to form certain that the exporters are operating properly, we&#8217;ll execute some expressions against <strong>Node Exporter<\/strong>.<\/p>\n<p>First, click on the <strong>Graph menu<\/strong> at the highest of the screen to come back to the Expression Browser.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-32176\" src=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Welcome.png\" alt=\"Prometheus-Dashboard-Welcome\" width=\"750\" height=\"378\" srcset=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Welcome.png 1154w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Welcome-300x151.png 300w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Welcome-768x387.png 768w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Welcome-1024x516.png 1024w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-Welcome-990x499.png 990w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/p>\n<p>In the Expression field, type <span style=\"color: #008080;\"><strong>node_memory_MemAvailable<\/strong><\/span> and press the <strong>Execute<\/strong> button to update the Console tab with the quantity of memory your server has.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-32177\" src=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal.png\" alt=\"Prometheus-Dashboard-MemTotal\" width=\"777\" height=\"433\" srcset=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal.png 1153w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal-300x168.png 300w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal-768x428.png 768w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal-1024x571.png 1024w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal-215x120.png 215w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal-414x232.png 414w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal-990x552.png 990w\" sizes=\"(max-width: 777px) 100vw, 777px\" \/><\/p>\n<p>By default, Node Exporter reports this quantity in bytes. To convert to megabytes, we&#8217;ll use math operators to divide by <strong>1024<\/strong> double time.<\/p>\n<p>In the Expression field, <strong>enter node_memory_MemAvailable\/1024\/1024<\/strong> so press the <strong>Execute<\/strong> button.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-32178 \" src=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal-MB.png\" alt=\"Prometheus-Dashboard-MemTotal-MB\" width=\"742\" height=\"418\" srcset=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal-MB.png 1153w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal-MB-300x168.png 300w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal-MB-768x433.png 768w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal-MB-1024x577.png 1024w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal-MB-990x558.png 990w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal-MB-470x264.png 470w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal-MB-640x360.png 640w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal-MB-215x120.png 215w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Dashboard-MemTotal-MB-414x232.png 414w\" sizes=\"(max-width: 742px) 100vw, 742px\" \/><\/p>\n<p>The<strong> Console tab<\/strong> can currently show the ends up in megabytes.<\/p>\n<p>If you wish to verify the results, execute the free command from your terminal. (The <strong>-h flag<\/strong> tells <strong>free<\/strong> to report back in an exceedingly human-readable format, giving a quantity in megabytes.)<\/p>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-bash code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-bash code-embed-code\">$ free -h<\/code><\/pre> <\/div>\n<p>This output contains details regarding memory usage, as well as on the available memory displayed within the on the available column.<\/p>\n<h3 id=\"output-6\"><span style=\"color: #333399;\">Output<\/span><\/h3>\n<pre class=\"code-pre \"><code>              total        used        free      shared  buff\/cache   available\r\nMem:           488M        144M         17M        3.7M        326M        324M\r\nSwap:            0B          0B          0B<\/code><\/pre>\n<p>In addition to basic operators, the Prometheus query language conjointly provides several functions for aggregating results.<\/p>\n<p>In the Expression field, type <strong>avg_over_time(node_memory_MemAvailable[5m])\/1024\/1024<\/strong> and click on on the Execute button. The result is going to be common on the available memory over the last five minutes in megabytes.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-32173\" src=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Average-Memory.png\" alt=\"Prometheus-Average-Memory\" width=\"760\" height=\"384\" srcset=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Average-Memory.png 1154w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Average-Memory-300x152.png 300w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Average-Memory-768x388.png 768w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Average-Memory-1024x517.png 1024w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Average-Memory-990x500.png 990w\" sizes=\"(max-width: 760px) 100vw, 760px\" \/><\/p>\n<p>Now, click on the <strong>Graph tab<\/strong> to show the executed expression as a graph rather than as text.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-32179\" src=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Graph-Average-Memory2.png\" alt=\"Prometheus-Graph-Average-Memory2\" width=\"780\" height=\"557\" srcset=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Graph-Average-Memory2.png 1362w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Graph-Average-Memory2-300x214.png 300w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Graph-Average-Memory2-768x548.png 768w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Graph-Average-Memory2-1024x731.png 1024w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Graph-Average-Memory2-990x707.png 990w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2018\/11\/Prometheus-Graph-Average-Memory2-1320x942.png 1320w\" sizes=\"(max-width: 780px) 100vw, 780px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Finally, whereas still on this tab, hover your mouse over the graph for extra details regarding any specific purpose on the <strong>graph&#8217;s X and Y axes<\/strong>.<\/p>\n<p>If you want to find out a lot of regarding making expressions in <strong>Prometheus&#8217; intrinsic web interface<\/strong>, see the<a href=\"https:\/\/prometheus.io\/docs\/querying\/basics\/\" target=\"_blank\" rel=\"noopener\"> Querying Prometheus<\/a> portion of the official documentation.<\/p>\n<h3 id=\"conclusion\"><span style=\"color: #008000;\">Conclusion<\/span><\/h3>\n<ul>\n<li>In this tutorial we have a tendency to<strong> downloaded, configured, secured, and tested a whole Prometheus installation with one further Exporter<\/strong>.<\/li>\n<li>If you want to find out a lot of regarding, however, Prometheus works below the hood, take a glance at How to Query Prometheus on Ubuntu fourteen.04. (Since you have already got Prometheus put in, you&#8217;ll skip the primary step.)<\/li>\n<li>To see what else Prometheus will do, visit the <a href=\"https:\/\/prometheus.io\/docs\/introduction\/overview\/\" target=\"_blank\" rel=\"noopener\">official Prometheus documentation<\/a>.<\/li>\n<li>And, to learn more about extending Prometheus, check out the list of available exporters as well as the official <a href=\"https:\/\/grafana.com\/\" target=\"_blank\" rel=\"noopener\">Grafana website.<\/a><\/li>\n<\/ul>\n<p><code class=\"code-highlight language-nginx hljs \"><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Install Prometheus on Ubuntu 16.04 Prometheus Prometheus could be a powerful and open-source, ASCII text file observance system that collects metrics from your services and stores them in an exceedingly time-series information. It proposes a multi-dimensional data model, a versatile query language, and numerous visualization image prospects through tools like Grafana. Prometheus solely exports metrics [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":14796,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[86307,85748],"tags":[86499,86500,86501,86502,86503,86504,86505,86506,86507,86508,86509],"class_list":["post-32165","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-nginx","category-ubuntu","tag-install-prometheus-ubuntu","tag-node-exporter-uptime","tag-node_exporter-systemd","tag-prometheus-monitoring","tag-prometheus-node-exporter","tag-prometheus-node-exporter-ubuntu","tag-prometheus-repository","tag-prometheus-systemd","tag-prometheus-systemd-exporter","tag-prometheus-ubuntu-package","tag-prometheus-version"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/32165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=32165"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/32165\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media\/14796"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=32165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=32165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=32165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}