{"id":297,"date":"2023-11-21T18:12:43","date_gmt":"2023-11-21T18:12:43","guid":{"rendered":"https:\/\/vitorprado.com\/?p=297"},"modified":"2023-11-21T18:30:57","modified_gmt":"2023-11-21T18:30:57","slug":"set-up-grafana-monitoring","status":"publish","type":"post","link":"https:\/\/vitorprado.com\/?p=297","title":{"rendered":"Set up Grafana monitoring"},"content":{"rendered":"\n<p>Grafana and Prometheus are tools used to monitor services, servers and any other software using the <em>Open metrics<\/em>. Here is an example of implementation using Docker compose:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing Grafana and Prometheus<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>version: '3.7'\n\nservices:\n  prometheus:\n    image: prom\/prometheus\n    container_name: prometheus\n    volumes:\n      - .\/prometheus.yml:\/etc\/prometheus\/prometheus.yml\n      - .\/alert.rules:\/etc\/prometheus\/alert.rules\n    ports:\n      - 9090:9090\n    networks:\n      - \"monitoring-network\"\n    expose:\n      - 9090\n  grafana:\n    image: grafana\/grafana\n    container_name: grafana\n    volumes:\n      - .\/grafana:\/var\/lib\/grafana\n    ports:\n      - 3000:3000\n    networks:\n      - \"monitoring-network\"\n    depends_on:\n      - prometheus\n  alertmanager:\n    image: prom\/alertmanager\n    container_name: alertmanager\n    volumes:\n      - .\/alertmanager:\/etc\/alertmanager\n    ports:\n      - 9093:9093\n    networks:\n      - \"monitoring-network\"\n\nnetworks:\n  monitoring-network:\n    driver: bridge<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Target: run Cadvisor<\/h2>\n\n\n\n<p>In the <em>target<\/em> side (the service that will be monitored), we must install the exporter, for example <em>Cadvisor<\/em>. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo docker run \\\n  --volume=\/:\/rootfs:ro \\\n  --volume=\/var\/run:\/var\/run:ro \\\n  --volume=\/sys:\/sys:ro \\\n  --volume=\/var\/lib\/docker\/:\/var\/lib\/docker:ro \\\n  --volume=\/dev\/disk\/:\/dev\/disk:ro \\\n  --publish=9418:8080 \\\n  --detach=true \\\n  --name=cadvisor \\\n  --restart=always \\\n  gcr.io\/google-containers\/cadvisor:latest<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Prometheus: target configuration<\/h2>\n\n\n\n<p>To generate the <em>Open Metrics<\/em> data. Then, we need to include the target configs in the prometheus.yml the target config section. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># my global config\nglobal:\n  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.\n  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.\n  # scrape_timeout is set to the global default (10s).\n\n# Alertmanager configuration\nalerting:\n  alertmanagers:\n  - static_configs:\n    - targets:\n      - alertmanager:9093\n\n# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.\nrule_files:\n  - \"\/etc\/prometheus\/alert.rules\"\n  # - \"first_rules.yml\"\n  # - \"second_rules.yml\"\n\n# A scrape configuration containing exactly one endpoint to scrape:\n# Here it's Prometheus itself.\nscrape_configs:\n  # The job name is added as a label `job=&lt;job_name>` to any timeseries scraped from this config.\n  - job_name: 'prometheus'\n\n    # metrics_path defaults to '\/metrics'\n    # scheme defaults to 'http'.\n\n    static_configs:\n    - targets: &#91;'127.0.0.1:9090']\n\n  - job_name: \"Docker Job\"\n    static_configs:\n    - targets: &#91;'192.168.x.y:9323']\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Grafana and Prometheus are tools used to monitor services, servers and any other software using the Open metrics. Here is an example of implementation using Docker compose: Installing Grafana and Prometheus Target: run Cadvisor In the target side (the service that will be monitored), we must install the exporter, for example Cadvisor. Prometheus: target configuration [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,30,11],"tags":[24,16,20],"class_list":["post-297","post","type-post","status-publish","format-standard","hentry","category-cloud","category-os","category-software","tag-cloud","tag-docker","tag-documentation"],"_links":{"self":[{"href":"https:\/\/vitorprado.com\/index.php?rest_route=\/wp\/v2\/posts\/297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vitorprado.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vitorprado.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vitorprado.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vitorprado.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=297"}],"version-history":[{"count":3,"href":"https:\/\/vitorprado.com\/index.php?rest_route=\/wp\/v2\/posts\/297\/revisions"}],"predecessor-version":[{"id":301,"href":"https:\/\/vitorprado.com\/index.php?rest_route=\/wp\/v2\/posts\/297\/revisions\/301"}],"wp:attachment":[{"href":"https:\/\/vitorprado.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vitorprado.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vitorprado.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}