Skip to main content

Command Palette

Search for a command to run...

Deep Dive into Prometheus Gauge Metrics

Published
β€’3 min readβ€’View as Markdown
Deep Dive into Prometheus Gauge Metrics
P

πŸ‘‹ Hello! I'm passionate about DevOps and have over 1+ years of experience in the field. I'm proficient in a variety of cutting-edge technologies and always motivated to expand my knowledge and skills. Let's connect and grow together!

SKILLS:

πŸ”Ή Languages & Runtimes: Python, Shell Scripting, HCL, YAML πŸ”Ή Cloud Technologies: AWS, Microsoft Azure, GCP πŸ”Ή Infrastructure Tools: Docker, Terraform, AWS CloudFormation πŸ”Ή Other Tools: Linux, Git and GitHub Actions, Jenkins, Jira, GitLab (beginner), Docker, AWS DevOps πŸ”Ή Web Development: HTML, CSS, Bootstrap, Python, SQL

Job & Responsibilities:

πŸš€ Improved development efficiency by implementing CI/CD pipelines, resulting in a 30% reduction in deployment time on the test server. πŸ”’ Strengthened deployment and testing reliability by utilizing Docker containers and optimizing Dockerfile, reducing development issues on the test server by 20%. βš™οΈ Automated S3 bucket log creation with Shell scripting, eliminating 100% of manual search and saving 2 hours per week. πŸ“… Scheduled EC2 instance start/stop using Lambda functions and Event Bridge, leading to a 25% decrease in infrastructure costs. πŸ”§ Utilized AWS, Linux, Python, Docker, Shell scripting, Terraform, Jenkins Pipelines, and automation to streamline workflows and improve overall system performance.

I'm very detail-oriented and possess strong written and verbal communication skills. As a high performer with a possibility mindset, I strive to solve problems using efficient approaches.

Let's Connect & Grow:

If you find my profile suitable for the role you are searching for, please feel free to reach out to me at sumanprasad9766@gmail.com.

Introduction

Welcome to the next installment of our metrics series! In this post, we're going to explore Prometheus Gauge metrics in detail. Gauges are a crucial metric type used to measure values that can arbitrarily increase or decrease over time. These metrics provide immediate, meaningful information without additional processing and are widely used to monitor various parameters. So, let's dive into the world of Prometheus Gauges and discover their importance in IT monitoring.

πŸ“ˆ Gauges: Metrics with Real-Time Significance

Gauges are among the most familiar metric types. Unlike counters, which only increase, gauges can both increase and decrease, making them ideal for tracking values that fluctuate. Gauges are particularly well-suited for measurements like temperature, CPU and memory usage, and the size of a queue. The value of a gauge metric, without any additional calculation, is immediately meaningful.

🌑️ Example: Monitoring Memory Usage

For instance, to measure memory usage on a host, a gauge metric can be used, such as:

# HELP node_memory_used_bytes Total memory used in the node in bytes
# TYPE node_memory_used_bytes gauge
node_memory_used_bytes{hostname="host1.domain.com"} 943348382

This metric informs us that, at the time of measurement, the memory used on the node host1.domain.com is approximately 900 megabytes. The metric's value is directly interpretable, as it tells us the exact amount of memory consumption on that node.

🚫 No Rate or Delta, But More Functions

Unlike counters, gauges do not lend themselves to rate or delta calculations since they can increase or decrease. However, functions that compute average, maximum, minimum, or percentiles for specific series are often used with gauge metrics. In Prometheus, these functions include avg_over_time, max_over_time, min_over_time, and quantile_over_time. For example, to calculate the average memory usage on host1.domain.com over the last ten minutes:

avg_over_time(node_memory_used_bytes{hostname="host1.domain.com"}[10m])

🐍 Creating Gauge Metrics in Python

Creating a gauge metric using the Prometheus client library for Python is straightforward. Here's an example:

from prometheus_client import Gauge

memory_used = Gauge(
    'node_memory_used_bytes',
    'Total memory used in the node in bytes',
    ['hostname']
)

memory_used.labels(hostname='host1.domain.com').set(943348382)

In this code snippet, we define a gauge metric named node_memory_used_bytes, provide a description, and specify a label called hostname. We then set the gauge's value for the host1.domain.com host.

🌟 Conclusion

Prometheus Gauge metrics are a fundamental part of IT monitoring. They provide immediate and meaningful information about values that can both increase and decrease over time. Whether you're monitoring memory usage, CPU load, or any other dynamic parameter, gauges are your go-to metric type.

In the upcoming sections of this series, we'll continue exploring other Prometheus metric types, such as histograms and summaries, and learn how to use them effectively in various monitoring scenarios. With this knowledge, you're well on your way to mastering Prometheus metrics and enhancing your IT monitoring capabilities. Stay tuned for more metric wisdom in the upcoming posts! πŸ“ˆπŸ“‰πŸ§πŸŒŸ

Happy monitoring! πŸ˜ŠπŸ”πŸ“πŸ‘¨β€πŸ’»

More from this blog

D

DeployToCloud

405 posts

πŸ‘‹ Welcome to my Hashnode blog! I'm a DevOps Engineer with 2+ years of experience. Join ~5k followers and explore 320+ blogs on Python, AWS, Docker, Jenkins, Linux, and more. Let's connect & grow πŸš€