{"id":280,"date":"2018-05-08T08:54:00","date_gmt":"2018-05-08T08:54:00","guid":{"rendered":"https:\/\/opstree.com\/blog\/\/2018\/05\/08\/prometheus-overview-and-setup\/"},"modified":"2019-09-18T16:59:22","modified_gmt":"2019-09-18T11:29:22","slug":"prometheus-overview-and-setup","status":"publish","type":"post","link":"https:\/\/opstree.com\/blog\/2018\/05\/08\/prometheus-overview-and-setup\/","title":{"rendered":"Prometheus Overview and Setup"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align:left;\">\n<h2 style=\"text-align:left;\">Overview<\/h2>\n<div><span style=\"color:#24292e;\"><span style=\"background-color:white;\">Prometheus is an opensource monitoring solution that gathers time series based numerical data. It is a project which was started by Google&#8217;s ex-employees&nbsp;at SoundCloud.&nbsp;<\/span><\/span><br \/>\n<span style=\"color:#24292e;\"><span style=\"background-color:white;\"><br \/>\n<\/span><\/span> <span style=\"color:#24292e;\"><span style=\"background-color:white;\">To monitor your services and infra with Prometheus your service needs to expose an endpoint in the form of port or URL. For example:- {{localhost:9090}}. The endpoint is an HTTP interface that exposes the metrics.<\/span><\/span><br \/>\n<span style=\"color:#24292e;\"><span style=\"background-color:white;\"><br \/>\n<\/span><\/span> <span style=\"color:#24292e;\"><span style=\"background-color:white;\">For some platforms such as Kubernetes and skyDNS Prometheus act as directly instrumented software that means you don&#8217;t have to install any kind of exporters to monitor these platforms. It can directly monitor by Prometheus.<\/span><\/span><br \/>\n<span style=\"color:#24292e;\"><span style=\"background-color:white;\"><br \/>\n<\/span><\/span> <span style=\"color:#24292e;\"><span style=\"background-color:white;\">One of the best thing about Prometheus is that it uses a Time Series Database(TSDB) because of that you can use mathematical operations, queries to analyze them. Prometheus uses SQLite as a database but it keeps the monitoring data in volumes.<\/span><\/span><\/div>\n<div><span><br \/>\n<\/span><\/div>\n<h2 style=\"text-align:left;\"><span>Pre-requisites<\/span><\/h2>\n<div>\n<ul>\n<li style=\"box-sizing:border-box;\">A CentOS 7 or Ubuntu VM<\/li>\n<li style=\"box-sizing:border-box;margin-top:.25em;\">A non-root sudo user, preferably one named prometheus<\/li>\n<\/ul>\n<div>\n<h2>Installing Prometheus Server<\/h2>\n<\/div>\n<\/div>\n<div><span>First, create a new directory to store all the files you download in this tutorial and move to it.<\/span><\/div>\n<div><span><br \/>\n<\/span><\/div>\n<div>\n<pre><code>mkdir \/opt\/prometheus-setup\ncd <\/code>\/opt\/prometheus-setup<\/pre>\n<\/div>\n<div><span>Create a user named &#8220;prometheus&#8221;<\/span><br \/>\n<span><\/span><\/p>\n<pre style=\"background-color:#f6f8fa;border-radius:3px;box-sizing:border-box;color:#24292e;font-size:13.6px;line-height:1.45;margin-bottom:16px;overflow:auto;padding:16px;word-wrap:normal;\">useradd prometheus<\/pre>\n<p><span>Use&nbsp;<\/span><em><b>wget<\/b><\/em><span>&nbsp;to download the latest build of the Prometheus server and time-series database from GitHub.<\/span><\/p>\n<\/div>\n<div><span><br \/>\n<\/span><\/div>\n<div>\n<pre><code>wget https:\/\/github.com\/prometheus\/prometheus\/releases\/download\/v2.0.0\/prometheus-2.0.0.linux-amd64.tar.gz\n<\/code><\/pre>\n<\/div>\n<div><code><span>The Prometheus monitoring system consists of several components, each of which needs to be installed separately.<\/span><\/code><\/p>\n<\/div>\n<div><code><\/code><\/div>\n<div><span>Use tar to extract prometheus-2.0.0.linux-amd64.tar.gz:<\/span><\/div>\n<div><span><br \/>\n<\/span><\/div>\n<div>\n<pre style=\"border-radius:3px;box-sizing:border-box;line-height:1.45;margin-bottom:16px;overflow:auto;padding:16px;word-wrap:normal;\"><span style=\"background-color:#f6f8fa;color:#24292e;font-size:13.6px;\"><code>tar -xvzf ~\/opt\/prometheus-setup\/<\/code>prometheus-2.0.0.linux-amd64.tar.gz .<\/span><span><span style=\"background-color:white;white-space:normal;\">\n<\/span><\/span><\/pre>\n<\/div>\n<div><span style=\"color:#24292e;\"><span style=\"background-color:white;\">&nbsp;Place your executable file somewhere in your PATH variable, or add them into a path for easy access.<\/span><\/span><\/div>\n<div><span><br \/>\n<\/span><\/div>\n<div>\n<pre style=\"background-color:#f6f8fa;border-radius:3px;box-sizing:border-box;line-height:1.45;margin-bottom:16px;overflow:auto;padding:16px;word-wrap:normal;\">\n<pre class=\"graf graf--pre\">mv prometheus-2.0.0.linux-amd64  prometheus\nsudo mv  prometheus\/prometheus  \/usr\/bin\/\nsudo chown prometheus:prometheus \/usr\/bin\/prometheus\nsudo chown -R prometheus:prometheus \/opt\/prometheus-setup\/<\/pre>\n<pre class=\"graf graf--pre\">mkdir \/etc\/prometheus<\/pre>\n<pre class=\"graf graf--pre\">\n<pre class=\"graf graf--pre\">mv prometheus\/prometheus.yml \/etc\/prometheus\/<\/pre>\n<pre class=\"graf graf--pre\">sudo chown -R prometheus:prometheus \/etc\/prometheus\/<\/pre>\n<pre class=\"graf graf--pre\">\n<pre class=\"graf graf--pre\">prometheus --version<\/pre>\n<\/div>\n<div>\n<div class=\"graf graf--p\"><\/div>\n<div class=\"graf graf--p\">&nbsp;&nbsp;<\/div>\n<p><span>You should see the following message on your screen:<\/span><\/p>\n<\/div>\n<div>\n<pre><code>  prometheus,       version 2.0.0 (branch: HEAD, revision: 0a74f98628a0463dddc90528220c94de5032d1a0)\n  build user:       root@615b82cb36b6\n  build date:       20171108-07:11:59\n  go version:       go1.9.2<\/code><\/pre>\n<\/div>\n<div><span>Create a service for Prometheus&nbsp;<\/span><br \/>\n<span><\/span><\/p>\n<pre style=\"background-color:#f6f8fa;border-radius:3px;box-sizing:border-box;line-height:1.45;margin-bottom:16px;overflow:auto;padding:16px;word-wrap:normal;\"><span style=\"color:#24292e;\"><span style=\"font-size:13.6px;\">sudo vi \/etc\/systemd\/system\/prometheus.service<\/span><\/span><\/pre>\n<pre style=\"background-color:#f6f8fa;border-radius:3px;box-sizing:border-box;line-height:1.45;margin-bottom:16px;overflow:auto;padding:16px;word-wrap:normal;\"><span style=\"color:#24292e;\"><span style=\"font-size:13.6px;\">[Unit]\nDescription=Prometheus\n\n[Service]\nUser=prometheus\nExecStart=\/usr\/bin\/prometheus --config.file \/etc\/prometheus\/prometheus.yml --storage.tsdb.path \/opt\/prometheus-setup\/\n\n[Install]\nWantedBy=multi-user.target<\/span><\/span><\/pre>\n<pre style=\"background-color:#f6f8fa;border-radius:3px;box-sizing:border-box;line-height:1.45;margin-bottom:16px;overflow:auto;padding:16px;word-wrap:normal;\"><span style=\"color:#24292e;\"><span style=\"font-size:13.6px;\">systemctl daemon-reload\n\nsystemctl start prometheus\n\nsystemctl enable prometheus<\/span><\/span><\/pre>\n<\/div>\n<div>\n<div style=\"background-color:white;border-bottom:1px solid rgb(234,236,239);box-sizing:border-box;color:#24292e;line-height:1.25;margin-bottom:16px;margin-top:24px;padding-bottom:.3em;text-align:left;\"><\/div>\n<h2>Installing Node Exporter<\/h2>\n<\/div>\n<div><span><br \/>\n<\/span><\/div>\n<div><span>Prometheus was developed for the purpose of monitoring web services. In order to monitor the metrics of your server, you should install a tool called Node Exporter. Node Exporter, as its name suggests, exports lots of metrics (such as disk I\/O statistics, CPU load, memory usage, network statistics, and more) in a format Prometheus understands. Enter the Downloads directory and use&nbsp;<\/span><em>wget<\/em><span>&nbsp;to download the latest build of Node Exporter which is available on GitHub.<\/span><br \/>\n<span><br \/>\n<\/span> <span>Node exporter is a binary which is written in go which monitors the resources such as cpu, ram and filesystem.&nbsp;<\/span><br \/>\n<span><br \/>\n<\/span><\/div>\n<div>\n<pre><code>wget https:\/\/github.com\/prometheus\/node_exporter\/releases\/download\/v0.15.1\/node_exporter-0.15.1.linux-amd64.tar.gz\n<\/code><\/pre>\n<\/div>\n<div><code><\/code> <code><\/code><\/p>\n<div><code><span>You can now use the tar command to extract : node_exporter-0.15.1.linux-amd64.tar.gz<\/span><\/code><\/div>\n<p><code><\/code><\/p>\n<div>\n<pre><code><code>tar -xvzf <\/code><\/code>node_exporter-0.15.1.linux-amd64.tar.gz .\n\nmv node_exporter-0.15.1.linux-amd64 node-exporter<\/pre>\n<\/div>\n<p><code><\/code><\/p>\n<\/div>\n<div><span>Perform this action:-<\/span><\/div>\n<div><span><br \/>\n<\/span><\/div>\n<div>\n<pre><code>mv node-exporter\/node_exporter \/usr\/bin\/\n<\/code><\/pre>\n<\/div>\n<div>\n<h2>Running Node Exporter as a Service<\/h2>\n<\/div>\n<div>Create a user named &#8220;prometheus&#8221; on the machine on which you are going to create node exporter service.<\/p>\n<pre style=\"background-color:#f6f8fa;border-radius:3px;box-sizing:border-box;color:#24292e;font-size:13.6px;line-height:1.45;margin-bottom:16px;overflow:auto;padding:16px;word-wrap:normal;\"><code style=\"background:transparent;border-radius:3px;border:0;box-sizing:border-box;display:inline;font-size:13.6px;line-height:inherit;margin:0;overflow:visible;padding:0;word-break:normal;word-wrap:normal;\">useradd prometheus<\/code><\/pre>\n<p><span>To make it easy to start and stop the Node Exporter, let us now convert it into a service. Use vi or any other text editor to create a unit configuration file called node_exporter.service.<\/span><\/p>\n<\/div>\n<div><span><br \/>\n<\/span><\/div>\n<div>\n<pre><code>sudo vi \/etc\/systemd\/system\/node_exporter.service\n<\/code><\/pre>\n<\/div>\n<div><code><span>This file should contain the path of the node_exporter executable, and also specify which user should run the executable. Accordingly, add the following code:<\/span><\/code><\/div>\n<div><code><\/code><\/p>\n<pre><code><code>[Unit]\nDescription=Node Exporter\n\n[Service]\nUser=prometheus\nExecStart=\/usr\/bin\/node_exporter\n\n[Install]\nWantedBy=default.target<\/code><\/code><\/pre>\n<p><code><\/code><\/p>\n<\/div>\n<div><span>Save the file and exit the text editor. Reload systemd so that it reads the configuration file you just created.<\/span><\/p>\n<\/div>\n<div><span><br \/>\n<\/span><\/div>\n<div>\n<pre><code>sudo systemctl daemon-reload<\/code><\/pre>\n<\/div>\n<div><span>At this point, Node Exporter is available as a service which can be managed using the systemctl command. Enable it so that it starts automatically at boot time.<\/span><\/div>\n<div><span><br \/>\n<\/span><\/div>\n<div>\n<pre><code>sudo systemctl enable node_exporter.service<\/code><\/pre>\n<\/div>\n<div><span>You can now either reboot your server or use the following command to start the service manually:<\/span><\/div>\n<div>\n<pre><code>sudo systemctl start node_exporter.service<\/code><\/pre>\n<\/div>\n<div><span>Once it starts, use a browser to view Node Exporter&#8217;s web interface, which is available at http:\/\/your_server_ip:9100\/metrics. You should see a page with a lot of text:<\/span><\/div>\n<div><span><br \/>\n<\/span><\/div>\n<div>\n<h3>Starting Prometheus Server with a new node<\/h3>\n<\/div>\n<div><span>Before you start Prometheus, you must first edit a configuration file for it called prometheus.yml.<\/span><\/div>\n<div><span><br \/>\n<\/span><\/div>\n<div>\n<pre><code>vim \/etc\/prometheus\/prometheus.yml<\/code><\/pre>\n<\/div>\n<div><span>Copy the following code into the file.<\/span><br \/>\n<span><br \/>\n<\/span> <span><\/span><\/p>\n<pre style=\"background-color:#f6f8fa;border-radius:3px;box-sizing:border-box;font-size:13.6px;line-height:1.45;margin-bottom:16px;overflow:auto;padding:16px;word-wrap:normal;\">\n<pre style=\"white-space:pre-wrap;word-wrap:break-word;\"><span style=\"color:blue;\"># my global configuration which means it will applicable for all jobs in file<\/span>\nglobal:\n  scrape_interval:     15s <span style=\"color:blue;\"># Set the scrape interval to every 15 seconds. Default is every 1 minute. scrape_interval should be provided for scraping data from exporters <\/span>\n  evaluation_interval: 15s <span style=\"color:blue;\"># Evaluate rules every 15 seconds. The default is every 1 minute. Evaluation interval checks at particular time is there any update on alerting rules or not.<\/span>\n\n<span style=\"color:blue;\"># Load rules once and periodically evaluate them according to the global 'evaluation_interval'. Here we will define our rules file path <\/span>\n#rule_files:\n#  - \"node_rules.yml\"\n#  - \"db_rules.yml\"\n\n<span style=\"color:blue;\"># A scrape configuration containing exactly one endpoint to scrape: In the scrape config we can define our job definitions<\/span>\nscrape_configs:\n  <span style=\"color:blue;\"># The job name is added as a label `job=` to any timeseries <\/span>scraped from this config.\n  - job_name: 'node-exporter'\n<span style=\"color:blue;\">    # metrics_path defaults to '\/metrics'\n    # scheme defaults to 'http'. <\/span><\/pre>\n<pre style=\"white-space:pre-wrap;word-wrap:break-word;\">    <span style=\"color:blue;\"># target are the machine on which exporter are running and exposing data at particular port.<\/span>\n    static_configs:\n      - targets: ['localhost:9100']<\/pre>\n<\/div>\n<div>After adding configuration in prometheus.yml. We should restart the service by<\/p>\n<pre style=\"background-color:#f6f8fa;border-radius:3px;box-sizing:border-box;color:#24292e;font-size:13.6px;line-height:1.45;margin-bottom:16px;overflow:auto;padding:16px;word-wrap:normal;\">systemctl restart prometheus<\/pre>\n<\/div>\n<div>\n<div>This creates a scrape_configs section and defines a job called a node. It includes the URL of your Node Exporter&#8217;s web interface in its array of targets. The scrape_interval is set to 15 seconds so that Prometheus scrapes the metrics once every fifteen seconds. You could name your job anything you want, but calling it &#8220;node&#8221; allows you to use the default console templates of Node Exporter.<\/div>\n<div><span style=\"color:#24292e;\">Use a browser to visit Prometheus&#8217;s homepage available at <\/span><i><span style=\"color:blue;\">http:\/\/your_server_ip:9090<\/span><\/i><span style=\"color:#24292e;\">. You&#8217;ll see the following homepage. Visit <\/span><span style=\"color:blue;\"><i>http:\/\/your_server_ip:9090\/<\/i><i>consoles\/node.html<\/i><\/span><span style=\"color:#24292e;\"> to access the Node Console and click on your server, localhost:9100, to view its metrics.<\/span><\/div>\n<div><\/div>\n<div><\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Overview Prometheus is an opensource monitoring solution that gathers time series based numerical data. It is a project which was started by Google&#8217;s ex-employees&nbsp;at SoundCloud.&nbsp; To monitor your services and infra with Prometheus your service needs to expose an endpoint in the form of port or URL. For example:- {{localhost:9090}}. The endpoint is an HTTP &hellip; <a href=\"https:\/\/opstree.com\/blog\/2018\/05\/08\/prometheus-overview-and-setup\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Prometheus Overview and Setup&#8221;<\/span><\/a><\/p>\n","protected":false},"author":171775670,"featured_media":29900,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[28070474],"tags":[44070,768739308,676319247,768739293,676319245,676319246,768739287],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2025\/11\/DevSecOps-1.jpg","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pfDBOm-4w","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/280"}],"collection":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/users\/171775670"}],"replies":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/comments?post=280"}],"version-history":[{"count":1,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/280\/revisions"}],"predecessor-version":[{"id":647,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/280\/revisions\/647"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media\/29900"}],"wp:attachment":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media?parent=280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/categories?post=280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/tags?post=280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}