# What Is The Job Label In Prometheus?

The **`job` label** in Prometheus organizes monitored instances or endpoints into logical groups. It is automatically added to metrics scraped from targets defined in the same scrape configuration block in `prometheus.yml`.

[ad-logs-small]

### Overview

The `job` label groups instances (e.g., servers, containers) with similar functionality. Each target in a job is uniquely identified by its **`instance` label** (host and port). Defined using the **`job_name`** field in `prometheus.yml`, this label is frequently used in PromQL queries to filter or group metrics.

---

### Example

In the following scrape configuration:

```yaml
scrape_configs:
  - job_name: 'api-servers'
    static_configs:
      - targets: ['192.168.1.101:8080', '192.168.1.102:8080']
  - job_name: 'db-servers'
    static_configs:
      - targets: ['192.168.1.201:5432', '192.168.1.202:5432']
```

Metrics scraped from these targets include:

- API Servers:  
  `http_requests_total{job="api-servers", instance="192.168.1.101:8080"} 42` 
 `http_requests_total{job="api-servers", instance="192.168.1.102:8080"} 56`

- Database Servers:  
  `db_queries_total{job="db-servers", instance="192.168.1.201:5432"} 120`  
`db_queries_total{job="db-servers", instance="192.168.1.202:5432"} 98`

---

### Common Uses

The `job` label is integral for filtering and aggregating metrics in PromQL. For example, to fetch metrics from all API servers: 
 
```promql
http_requests_total{job="api-servers"}
```  

To sum requests across all API server instances: 
 
```promql
sum(http_requests_total{job="api-servers"})
```

It also helps in alerting configurations. For instance, you can alert when no API server targets are available:  

```yaml
alert: NoTargetsAvailable
expr: up{job="api-servers"} == 0
for: 5m
labels:
  severity: critical
annotations:
  summary: "No targets available for API servers"
```

In tools like Grafana, the `job` label can group or filter metrics for dashboards.

---

### Best Practices

Choose clear, descriptive names for `job_name` (e.g., `api-servers` or `db-cluster`). Group targets logically—avoid mixing unrelated instances. Use the `instance` label alongside `job` for precise monitoring.

---

The `job` label simplifies metric organization, queries, and alerting, making it a cornerstone of effective monitoring in Prometheus.

[ad-uptime]
