Skip to content

Commit

Permalink
Modules
Browse files Browse the repository at this point in the history
  • Loading branch information
bentonam committed Apr 4, 2024
1 parent fe0970d commit 75f39f7
Show file tree
Hide file tree
Showing 41 changed files with 9,132 additions and 0 deletions.
168 changes: 168 additions & 0 deletions modules/integrations/agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Agent Module

Handles scraping Grafana Agent metrics.

## Components

- [kubernetes](#kubernetes)
- [local](#local)
- [scrape](#scrape)

### kubernetes

Handles discovery of kubernetes targets and exports them, this component does not perform any scraping at all and is not required to be used for kubernetes, as a custom service discovery and targets can be defined and passed to `agent.scrape`

Check failure on line 13 in modules/integrations/agent/README.md

View workflow job for this annotation

GitHub Actions / markdownlint

[markdownlint] modules/integrations/agent/README.md#L13

MD013/line-length Line length [Expected: 150; Actual: 242]
Raw output
modules/integrations/agent/README.md:13:151 MD013/line-length Line length [Expected: 150; Actual: 242]

#### Arguments

| Name | Required | Default | Description |
| :----------- | :------- | :----------------------------------------- | :---------- |
| `namespaces` | _no_ | `[]` | The namespaces to look for targets in, the default (`[]`) is all namespaces |
| `selectors` | _no_ | `["app.kubernetes.io/name=grafana-agent"]` | The label selectors to use to find matching targets |
| `port_name` | _no_ | `http-metrics` | The of the port to scrape metrics from |

#### Exports

| Name | Type | Description |
| :------- | :------------------ | :--------------------------|
| `output` | `list(map(string))` | List of discovered targets |

#### Labels

The following labels are automatically added to exported targets.

| Label | Description |
| :---------- | :-------------------------------------------------------------------------------------------------------------------------------------------------- |
| `app` | Derived from the pod label value of `app.kubernetes.io/name`, `k8s-app`, or `app` |
| `component` | Derived from the pod label value of `app.kubernetes.io/component`, `k8s-component`, or `component |
| `container` | The name of the container, usually `haproxy` |
| `namespace` | The namespace the target was found in. |
| `pod` | The full name of the pod |
| `source` | Constant value of `kubernetes`, denoting where the results came from, this can be useful for LBAC |
| `workload` | Kubernetes workload, a combination of `__meta_kubernetes_pod_controller_kind` and `__meta_kubernetes_pod_controller_name`, i.e. `ReplicaSet/my-app` |
---

### local

#### Arguments

| Name | Optional | Default | Description |
| :----- | :------- | :------ | :------------------------------------- |
| `port` | `true` | `12345` | The of the port to scrape metrics from |

#### Exports

| Name | Type | Description |
| :------- | :------------------ | :------------------------- |
| `output` | `list(map(string))` | List of discovered targets |

#### Labels

The following labels are automatically added to exported targets.

| Label | Description |
| :------- | :------------------------------------------------------------------------------------------- |
| `source` | Constant value of `local`, denoting where the results came from, this can be useful for LBAC |

---

### scrape

#### Arguments

| Name | Required | Default | Description |
| :---------------- | :------- | :---------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------- |
| `targets` | _yes_ | `list(map(string))` | List of targets to scrape |
| `forward_to` | _yes_ | `list(MetricsReceiver)` | Must be a where scraped should be forwarded to |
| `job_label` | _no_ | `integrations/agent` | The job label to add for all mimir metric |
| `port_name` | _no_ | `http-metrics` | The of the port to scrape metrics from |
| `keep_metrics` | _no_ | [see code](module.river#L228) | A regex of metrics to keep |
| `drop_metrics` | _no_ | [see code](module.river#L235) | A regex of metrics to drop |
| `scrape_interval` | _no_ | `60s` | How often to scrape metrics from the targets |
| `scrape_timeout` | _no_ | `10s` | How long before a scrape times out |
| `max_cache_size` | _no_ | `100000` | The maximum number of elements to hold in the relabeling cache. This should be at least 2x-5x your largest scrape target or samples appended rate. |
| `clustering` | _no_ | `false` | Whether or not [clustering](https://grafana.com/docs/agent/latest/flow/concepts/clustering/) should be enabled |

Check notice on line 83 in modules/integrations/agent/README.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] modules/integrations/agent/README.md#L83

Consider shortening this phrase to just ‘whether’, unless you mean ‘regardless of whether’. (WHETHER[7]) Suggestions: `Whether` URL: https://languagetool.org/insights/post/whether-vs-if/#when-to-use-%E2%80%9Cwhether%E2%80%9D Rule: https://community.languagetool.org/rule/show/WHETHER?lang=en-US&subId=7 Category: REDUNDANCY
Raw output
modules/integrations/agent/README.md:83:65: Consider shortening this phrase to just ‘whether’, unless you mean ‘regardless of whether’. (WHETHER[7])
 Suggestions: `Whether`
 URL: https://languagetool.org/insights/post/whether-vs-if/#when-to-use-%E2%80%9Cwhether%E2%80%9D 
 Rule: https://community.languagetool.org/rule/show/WHETHER?lang=en-US&subId=7
 Category: REDUNDANCY
| `clustering` | _no_ | `false` | Whether or not [clustering](https://grafana.com/docs/agent/latest/flow/concepts/clustering/) should be enabled |

Check notice on line 84 in modules/integrations/agent/README.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] modules/integrations/agent/README.md#L84

Consider shortening this phrase to just ‘whether’, unless you mean ‘regardless of whether’. (WHETHER[7]) Suggestions: `Whether` URL: https://languagetool.org/insights/post/whether-vs-if/#when-to-use-%E2%80%9Cwhether%E2%80%9D Rule: https://community.languagetool.org/rule/show/WHETHER?lang=en-US&subId=7 Category: REDUNDANCY
Raw output
modules/integrations/agent/README.md:84:65: Consider shortening this phrase to just ‘whether’, unless you mean ‘regardless of whether’. (WHETHER[7])
 Suggestions: `Whether`
 URL: https://languagetool.org/insights/post/whether-vs-if/#when-to-use-%E2%80%9Cwhether%E2%80%9D 
 Rule: https://community.languagetool.org/rule/show/WHETHER?lang=en-US&subId=7
 Category: REDUNDANCY

#### Labels

The following labels are automatically added to exported targets.

| Label | Description |
| :---- | :--------------------------------------------- |
| `job` | Set to the value of `argument.job_label.value` |

---

## Usage

### Kubernetes

The following example will scrape all agents in cluster.

```river
import.git "agent" {

Check notice on line 103 in modules/integrations/agent/README.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] modules/integrations/agent/README.md#L103

If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Git`, ` git` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING
Raw output
modules/integrations/agent/README.md:103:7: If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1])
 Suggestions: ` Git`, ` git`
 Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1
 Category: CASING
repository = "https://github.com/grafana/agent-modules.git"
revision = "main"
path = "v2/integrations/agent/module.river"
pull_frequency = "15m"
}
// get the targets
agent.kubernetes "targets" {}
// scrape the targets
agent.scrape "metrics" {

Check notice on line 114 in modules/integrations/agent/README.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] modules/integrations/agent/README.md#L114

If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Scrape`, ` scrape` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING
Raw output
modules/integrations/agent/README.md:114:6: If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1])
 Suggestions: ` Scrape`, ` scrape`
 Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1
 Category: CASING
targets = agent.kubernetes.targets.output
forward_to = [
prometheus.remote_write.default.receiver,
]
}
// write the metrics
prometheus.remote_write "local_primary" {
endpoint {
url = "http://mimir:9009/api/v1/push"
basic_auth {
username = "example-user"
password = "example-password"
}
}
}
```

### Local

The following example will scrape the agent for metrics on the local machine.

```river
import.git "agent" {

Check notice on line 139 in modules/integrations/agent/README.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] modules/integrations/agent/README.md#L139

If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Git`, ` git` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING
Raw output
modules/integrations/agent/README.md:139:7: If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1])
 Suggestions: ` Git`, ` git`
 Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1
 Category: CASING
repository = "https://github.com/grafana/agent-modules.git"
revision = "main"
path = "v2/integrations/agent/module.river"
pull_frequency = "15m"
}
// get the targets
agent.local "targets" {}
// scrape the targets
agent.scrape "metrics" {

Check notice on line 150 in modules/integrations/agent/README.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] modules/integrations/agent/README.md#L150

If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Scrape`, ` scrape` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING
Raw output
modules/integrations/agent/README.md:150:6: If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1])
 Suggestions: ` Scrape`, ` scrape`
 Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1
 Category: CASING
targets = agent.local.targets.output
forward_to = [
prometheus.remote_write.default.receiver,
]
}
// write the metrics
prometheus.remote_write "default" {
endpoint {
url = "http://mimir:9009/api/v1/push"
basic_auth {
username = "example-user"
password = "example-password"
}
}
}
```
Loading

0 comments on commit 75f39f7

Please sign in to comment.