{"id":2123,"date":"2025-05-06T22:15:00","date_gmt":"2025-05-06T22:15:00","guid":{"rendered":"https:\/\/serverhub.com\/kb\/?p=2123"},"modified":"2025-05-07T03:07:33","modified_gmt":"2025-05-07T03:07:33","slug":"prometheus-powerful-open-source-monitoring-alerting-toolkit","status":"publish","type":"post","link":"https:\/\/serverhub.com\/kb\/prometheus-powerful-open-source-monitoring-alerting-toolkit\/","title":{"rendered":"Prometheus: Powerful Open-Source Monitoring &amp; Alerting Toolkit"},"content":{"rendered":"\n<p>Welcome to the wild world of <strong>Prometheus monitoring<\/strong>! If you&#8217;ve ever wondered how to make sense of thousands of metrics, query your data like a pro, or configure Prometheus on Windows machines, you&#8217;re in the right place.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"597\" src=\"https:\/\/serverhub.com\/kb\/wp-content\/uploads\/2025\/05\/Blog-artcle-Blog-1024x597.jpg\" alt=\"\" class=\"wp-image-2134\" srcset=\"https:\/\/serverhub.com\/kb\/wp-content\/uploads\/2025\/05\/Blog-artcle-Blog-1024x597.jpg 1024w, https:\/\/serverhub.com\/kb\/wp-content\/uploads\/2025\/05\/Blog-artcle-Blog-300x175.jpg 300w, https:\/\/serverhub.com\/kb\/wp-content\/uploads\/2025\/05\/Blog-artcle-Blog-768x448.jpg 768w, https:\/\/serverhub.com\/kb\/wp-content\/uploads\/2025\/05\/Blog-artcle-Blog.jpg 1200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is Prometheus and What Does It Do?<\/strong><\/h2>\n\n\n\n<p><strong>Prometheus <\/strong>is an open-source <strong>monitoring<\/strong> and <strong>alerting toolkit<\/strong> originally developed at SoundCloud. It helps developers and DevOps engineers to efficiently <strong>collect, store, and query<\/strong> metrics. Think of it as a digital watchdog\u2014but instead of barking, it sends alerts when things go haywire.<\/p>\n\n\n\n<p>Prometheus excels at <strong>time-series data collection<\/strong>, meaning it continuously scrapes and stores data points indexed by time and labels. Unlike traditional logging solutions, Prometheus is optimized for high-cardinality data, which means you can tag your metrics with as much detail as needed without breaking performance.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How Does Prometheus Work?<\/strong><\/h2>\n\n\n\n<p>Prometheus works on a <strong>pull-based model<\/strong> where it scrapes metrics from configured targets at regular intervals. The high-level breakdown on how Prometheus works:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Data Collection:<\/strong> Prometheus scrapes metrics from applications, nodes, or external services using exporters.<\/li>\n\n\n\n<li><strong>Storage:<\/strong> The data is stored in a time-series database optimized for high-volume, real-time querying.<\/li>\n\n\n\n<li><strong>Querying:<\/strong> You can use <strong>PromQL<\/strong> (Prometheus Query Language) to extract and analyze metrics.<\/li>\n\n\n\n<li><strong>Alerting:<\/strong> Integrated with <strong>Alertmanager<\/strong>, it sends notifications when anomalies occur.<\/li>\n\n\n\n<li><strong>Visualization:<\/strong> Prometheus integrates with Grafana for dashboards and visualizations.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Prometheus vs. Grafana: What\u2019s the Difference?<\/strong><\/h2>\n\n\n\n<p>Prometheus is a monitoring system that collects data, while Grafana is a visualization tool that uses that data to create dashboards and graphs. Think of <strong>Prometheus<\/strong> as your detective gathering clues (metrics), and <strong>Grafana<\/strong> as the artist painting a picture with those clues. Together, they can be a powerful combination for data-driven insights and decision-making.<\/p>\n\n\n\n<p><br>They collaborate when Grafana retrieves data from Prometheus via PromQL when it is integrated by the DevOps teams on top of Prometheus. Both Grafana and Prometheus work with a variety of data sources. Prometheus and Grafana are useful tools for creating dashboards that show system data, experimenting with metrics, and troubleshooting metrics collection-related difficulties.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Passing Multiple Query Parameters in Prometheus Queries<\/strong><\/h2>\n\n\n\n<p>You can pass multiple query parameters in <strong>PromQL<\/strong> using curly braces and logical operators. An example is the following command:<\/p>\n\n\n\n<p><mark class=\"has-inline-color has-accent-color\">node_cpu_seconds_total{mode=&#8221;idle&#8221;, instance=&#8221;localhost:9090&#8243;}<\/mark><\/p>\n\n\n\n<p>Want to query multiple labels at once? Try this command:<\/p>\n\n\n\n<p><mark class=\"has-inline-color has-accent-color\">node_cpu_seconds_total{mode=~&#8221;idle|user&#8221;, instance=~&#8221;localhost.*&#8221;}<\/mark><\/p>\n\n\n\n<p>\ud83d\ude80<strong>Pro tip:<\/strong> Use regex carefully\u2014there\u2019s a <strong>Prometheus regex character limit<\/strong> to keep in mind!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Prometheus Metrics for Kubernetes Cronjobs<\/strong><\/h2>\n\n\n\n<p>To send <strong>metrics from Kubernetes CronJobs<\/strong> to Prometheus, do these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Expose metrics<\/strong> in your CronJob container using an HTTP endpoint.<\/li>\n\n\n\n<li><strong>Configure a ServiceMonitor<\/strong> to scrape those metrics.<\/li>\n\n\n\n<li><strong>Use PromQL queries<\/strong> to analyze scheduled job executions.<\/li>\n<\/ol>\n\n\n\n<p>Example <strong>K8s Prometheus alert rules<\/strong>:<\/p>\n\n\n\n<p><mark class=\"has-inline-color has-accent-color\">alert: CronJobFailures<br>expr: kube_job_status_failed &gt; 0<br>for: 5m<br>labels:<br> severity: critical<br>annotations:<br> summary: &#8220;CronJob failed&#8221;<\/mark><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Prometheus and AWS: AlertManager, IAM, and CLI<\/strong><\/h2>\n\n\n\n<p>When using <strong>AWS Prometheus<\/strong> (AMP &#8211; Amazon Managed Prometheus), you need proper <strong>IAM permissions<\/strong> to interact with it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Setting Up AWS Prometheus AlertManager Role<\/strong><\/h2>\n\n\n\n<p>When using AWS Prometheus (AMP &#8211; Amazon Managed Prometheus), you need proper IAM permissions to interact with it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Setting Up AWS Prometheus AlertManager Role<\/strong><\/h2>\n\n\n\n<p>{<br>     &#8220;Version&#8221;: &#8220;2012-10-17&#8221;,<br>     &#8220;Statement&#8221;:   [<br>         {<br>             &#8220;Effect&#8221;: &#8220;Allow&#8221;,<br>             &#8220;Action&#8221;: [<br>                &#8220;aps:ListAlertManagers&#8221;,<br>                &#8220;aps:PutAlertManagerDefinition&#8221;<br>              ],<br>               &#8220;Resource&#8221;: &#8220;*&#8221;<br>          }<br>       ]<br>   }<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Using the AWS Prometheus CLI<\/strong><\/h2>\n\n\n\n<p>Use the following commands:<\/p>\n\n\n\n<p><mark class=\"has-inline-color has-accent-color\">aws aps list-workspaces<br>aws aps get-metrics &#8211;workspace-id=xyz<\/mark><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Prometheus Metrics for Everything!<\/strong><\/h2>\n\n\n\n<p>From pods to databases, Prometheus captures it all. Some essential metric categories:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Prometheus node exporter:<\/strong> System metrics (CPU, Memory, Disk, Network)<\/li>\n\n\n\n<li><strong>Prometheus RAID exporter:<\/strong> Disk RAID status and health monitoring<\/li>\n\n\n\n<li><strong>Prometheus disk RAID monitor:<\/strong> Ensuring disk redundancy<\/li>\n\n\n\n<li><strong>MongoDB Atlas Metrics Prometheus meta labels:<\/strong> Monitoring MongoDB Atlas with Prometheus<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Configuring Prometheus External Service Monitor<\/strong><\/h2>\n\n\n\n<p>Want to scrape metrics from an external API? Use <strong>Prometheus external service monitor<\/strong> by using the following commands:<\/p>\n\n\n\n<p><mark class=\"has-inline-color has-accent-color\">apiVersion: monitoring.coreos.com\/v1<br>kind: ServiceMonitor<br>metadata:<br>      name: external-service-monitor<br>spec:<br>      endpoints:<br>             &#8211; port: metrics<br>                interval: 30s<br>      selector:<br>          matchLabels:<br>                 app: external-service<\/mark><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Adding Prometheus Metrics to Open API MUX Golang<\/strong><\/h2>\n\n\n\n<p>Here&#8217;s a concise summary of the steps to add <strong>Prometheus metrics<\/strong> to an OpenAPI Mux-based Golang application:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>1) Install Dependencies<\/strong>\n<ul class=\"wp-block-list\">\n<li>Use the following commands:<\/li>\n\n\n\n<li><mark class=\"has-inline-color has-accent-color\">go get github.com\/prometheus\/client_golang\/prometheus<\/mark><\/li>\n\n\n\n<li><mark class=\"has-inline-color has-accent-color\">go get github.com\/prometheus\/client_golang\/prometheus\/promhttp<\/mark><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>2) Register Prometheus Metrics<\/strong>\n<ul class=\"wp-block-list\">\n<li>Define custom metrics (requestsTotal, requestDuration).<\/li>\n\n\n\n<li>Register them using prometheus.MustRegister().<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>3) Create Middleware to Track Metrics<\/strong>\n<ul class=\"wp-block-list\">\n<li>Capture request method and route.<\/li>\n\n\n\n<li>Record request count and duration.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li> <strong>4) Integrate with Mux Router<\/strong>\n<ul class=\"wp-block-list\">\n<li>Attach middleware to the router.<\/li>\n\n\n\n<li>Define API routes and the \/metrics endpoint.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>5) Run the Server by using this command<\/strong>:\n<ul class=\"wp-block-list\">\n<li>go run main.go<\/li>\n\n\n\n<li>Test API at http:\/\/localhost:8080\/hello.<\/li>\n\n\n\n<li>View metrics at http:\/\/localhost:8080\/metrics.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>6) Configure Prometheus to Scrape Metrics<\/strong>\n<ul class=\"wp-block-list\">\n<li>a) Update prometheus.yml:\n<ul class=\"wp-block-list\">\n<li><mark class=\"has-inline-color has-accent-color\">yam<\/mark><\/li>\n\n\n\n<li><mark class=\"has-inline-color has-accent-color\">CopyEdit<\/mark><\/li>\n\n\n\n<li><mark class=\"has-inline-color has-accent-color\">scrape_configs:<\/mark><\/li>\n\n\n\n<li><mark class=\"has-inline-color has-accent-color\">&#8211; <span style=\"font-size: inherit\">job_name: &#8216;golang_app&#8217; static_configs:<\/span><\/mark><\/li>\n\n\n\n<li><span style=\"font-size: inherit\"><span style=\"font-size: inherit\"><mark class=\"has-inline-color has-accent-color\">targets: [&#8216;localhost:8080&#8217;]<\/mark><\/span><\/span><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>b) Start Prometheus and query metrics.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Prometheus Cortex: How Long Does It Keep Data in Memory?<\/strong><\/h2>\n\n\n\n<p>When using <strong>Prometheus Cortex<\/strong>, data retention depends on configuration:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>In-memory storage<\/strong>: Short-term, optimized for fast reads.<\/li>\n\n\n\n<li><strong>Long-term storage<\/strong>: AWS S3, Google Cloud Storage, or object storage solutions.<\/li>\n<\/ul>\n\n\n\n<p>Typical retention in <strong>Prometheus globalconfig<\/strong>:<br><mark class=\"has-inline-color has-accent-color\">storage.tsdb.retention.time: &#8220;15d<\/mark><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Advanced Prometheus Topics<\/strong><\/h2>\n\n\n\n<p><strong>Prometheus Lookback Delta<\/strong><br><strong>Lookback delta<\/strong> is used to fill missing data points in queries:<br><mark class=\"has-inline-color has-accent-color\">rate(http_requests_total[5m] offset 5m)<\/mark><br>To configure it manually, use this command:<br><mark class=\"has-inline-color has-accent-color\">query.lookback-delta: &#8220;30s&#8221;<\/mark><\/p>\n\n\n\n<p><strong>Prometheus Hot Reload Config<\/strong><br>Need to reload configuration <strong>without restarting?<\/strong> Use this command:<br><mark class=\"has-inline-color has-accent-color\">curl -X POST http:\/\/localhost:9090\/-\/reload<\/mark><\/p>\n\n\n\n<p><strong>Drop All Prometheus Metrics with a Label<br><\/strong>Use relabeling to drop unwanted metrics with the following commands:<br><mark class=\"has-inline-color has-accent-color\">metric_relabel_configs:<br>&#8211; source_labels: [&#8220;unwanted_label&#8221;]<br>   regex: &#8220;.*&#8221;<br>   action: drop<\/mark><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Prometheus + AI Bots?<\/strong><\/h2>\n\n\n\n<p>While <strong>Prometheus AI bots <\/strong>aren\u2019t here (yet), <strong>AWS Prometheus AI-driven alerting<\/strong> can help analyze trends and anomalies!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Wrapping Up<\/strong><\/h2>\n\n\n\n<p>Whether you&#8217;re monitoring a <strong>Kubernetes cluster<\/strong>, integrating with<strong> AWS<\/strong>, or exploring <strong>Prometheus avalanche data<\/strong>, this guide should give you a <strong>solid foundation<\/strong>. \ud83d\ude80 Now, go forth and monitor everything! And if things go south\u2014Prometheus has your back. (Or at least your logs).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>References:<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"https:\/\/prometheus.io\/docs\/\" title=\"\">Prometheus Official Documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/grafana.com\/docs\/grafana\/latest\/datasources\/prometheus\/\" title=\"\">Grafana + Prometheus Integration<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/aws.amazon.com\/prometheus\/\" title=\"\">AWS Prometheus (Amazon Managed Service for Prometheus &#8211; AMP)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/prometheus.io\/docs\/alerting\/latest\/alertmanager\/\" title=\"\">Prometheus Alerting and Alertmanager<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/prometheus.io\/\" title=\"\">Prometheus &#8211; Monitoring system &amp; time series database<\/a><\/li>\n<\/ol>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to the wild world of Prometheus monitoring! If you&#8217;ve ever wondered how to make sense of thousands of metrics, query your data like a pro, or configure Prometheus on Windows machines, you&#8217;re in the right place. What is Prometheus and What Does It Do? Prometheus is an open-source monitoring and alerting toolkit originally developed &#8230; <a title=\"Prometheus: Powerful Open-Source Monitoring &amp; Alerting Toolkit\" class=\"read-more\" href=\"https:\/\/serverhub.com\/kb\/prometheus-powerful-open-source-monitoring-alerting-toolkit\/\" aria-label=\"More on Prometheus: Powerful Open-Source Monitoring &amp; Alerting Toolkit\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"om_disable_all_campaigns":false,"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2123","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/posts\/2123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/comments?post=2123"}],"version-history":[{"count":14,"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/posts\/2123\/revisions"}],"predecessor-version":[{"id":2138,"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/posts\/2123\/revisions\/2138"}],"wp:attachment":[{"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/media?parent=2123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/categories?post=2123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/serverhub.com\/kb\/wp-json\/wp\/v2\/tags?post=2123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}