Skip to content

Practice Exercise 3

Practice Exercise 3 : Basic Prometheus Query Operations

Objective: Practice fundamental query operations within the Prometheus system to retrieve and analyze metrics.

Instructions:

1. Access Prometheus Web UI:

  • Open a web browser and navigate to your Prometheus web UI.

2. Query for Uptime:

  • Retrieve the system uptime metric.
    `uptime`
    

3. Count Available CPUs:

  • Find out the total number of available CPUs.
    `count(cpu)`
    

4. Calculate Average CPU Usage:

  • Calculate the average CPU usage percentage.
    `avg(cpu_usage)`
    

5. Filter for Specific Process Memory Usage:

  • Query for the memory usage of a specific process (replace <process_name> with the actual process name).
    `process_memory_usage_bytes{process_name="<process_name>"}`
    

6. Explore Range Queries:

  • Perform a range query to analyze historical data.
  • Query for the maximum CPU temperature over the last hour.
    `max_over_time(cpu_temperature{sensor="cpu"}[1h])`
    

7. Aggregate CPU Usage Over Time:

  • Aggregate CPU usage over a 5-minute interval and express it as a percentage.
    `avg_over_time(cpu_usage[5m]) * 100`
    

8. Filter Metrics by Label:

  • Filter metrics by a specific label (replace <label_key> and <label_value> with the actual label key and value).
    `metric_name{<label_key>="<label_value>"}`
    

9. Calculate Memory Usage Percentage:

  • Calculate the percentage of used memory.
    `(1 - (node_memory_MemFree_bytes + node_memory_Cached_bytes) / node_memory_MemTotal_bytes) * 100`
    

10. Use Offset in Range Query:

  • Query for the average disk space usage over the last 6 hours, with a 1-hour offset.

    plaintextCopy code

    avg_over_time(node_filesystem_avail_bytes{mountpoint="/"}[6h] offset 1h)