# Authentication

To authenticate with the Mimir and Loki APIs, you can either use a [IAM Service Account](<https://documentation.syseleven.de/en/products/iam/usage/service-accounts/#create-service-account>) or an [API Key](<https://documentation.syseleven.de/en/products/iam/usage/api-keys/#create-an-api-key>) with applicable [observability permissions](<https://documentation.syseleven.de/en/products/iam/concepts/authorization-model/#observability-permissions>), granting either read-only, write-only or read/write access to the Mimir and Loki APIs.

## Mimir

Grafana Mimir is a long-term storage system (time-series database) for metrics. We host Mimir at `https://metrics.syseleven.services/<org-id>/<project-id>`. Append `/prometheus` to the base URL to access the Prometheus-compatible API (for example, `https://metrics.syseleven.services/4e8ba78f-918a-4c94-9be6-9ee5c5748b21/45c1abc103cd49dc9b8d7f9f16bc9362/prometheus`).

See the official [Mimir API documentation](<https://grafana.com/docs/mimir/latest/references/http-api/>) to learn how to use the Mimir API.

> [!NOTE]
>
> You must append your **org-id** and **project-id** to the base URL (for example, `https://metrics.syseleven.services/4e8ba78f-918a-4c94-9be6-9ee5c5748b21/45c1abc103cd49dc9b8d7f9f16bc9362/prometheus`).

## Loki

Grafana Loki is a long-term storage system for logs. We host Loki at `https://logs.syseleven.services/<org-id>/<project-id>`.

See the official [Loki API documentation](<https://grafana.com/docs/loki/latest/reference/loki-http-api/>) to learn how to use the Loki API.

> [!NOTE]
>
> As with Mimir, you need to append your **org-id** and **project-id** to the base URL (for example, `https://logs.syseleven.services/4e8ba78f-918a-4c94-9be6-9ee5c5748b21/45c1abc103cd49dc9b8d7f9f16bc9362`).

## Recommended Setup

We recommend the following setup for ingesting logs and metrics from your OpenStack Cloud resources:

- [Grafana Alloy](<https://grafana.com/docs/alloy/latest/introduction/>) as a central collector service.
- [Mimir](<https://grafana.com/docs/mimir/latest/>) as a long-term storage for metrics.
- [Loki](<https://grafana.com/docs/loki/latest/>) as a long-term storage for logs.

For instance, to scrape a local log file, use the following configuration:

```alloy
# Configure file matcher (all log files in `/var/log/`)
local.file_match "local_files" {
    path_targets = [{"__path__" = "/var/log/*.log"}]
    sync_period = "5s"
}

# Configure scraping of the `local_files` components
loki.source.file "log_scrape" {
  targets    = local.file_match.local_files.targets
  forward_to = [loki.process.filter_logs.receiver]
  tail_from_end = true
}
```

and then configure Alloy to remote-write the logs to Loki.

```alloy
loki.write "grafana_loki" {
  endpoint {
    url = "https://logs.syseleven.services/<org-id>/<project-id>/loki/api/v1/push"
    bearer_token = "s11_prak_<uuid>_<secret>"
  }
}
```

## Integrate Observability with Grafana

You can integrate Observability Mimir/Loki tenants with Grafana as separate data sources. Programmatically, use the following configuration in your Grafana `datasources.yaml` file to set up the data sources for Mimir and Loki:

```yaml
datasources:
  datasources.yaml:
    apiVersion: 1
    datasources:
      - name: Alertmanager
        type: alertmanager
        url: https://metrics.syseleven.services/<org_id>/<project_id>
        access: proxy
        editable: false
        jsonData:
          httpHeaderName1: Authorization
        secureJsonData:
          httpHeaderValue1: "Bearer s11_prak_<uuid>_<secret>"
      - name: Prometheus
        type: prometheus
        url: https://metrics.syseleven.services/<org_id>/<project_id>/prometheus
        access: proxy
        isDefault: true
        editable: false
        jsonData:
          prometheusType: Mimir
          httpHeaderName1: Authorization
        secureJsonData:
          httpHeaderValue1: "Bearer s11_prak_<uuid>_<secret>"
      - name: Loki
        type: loki
        url: https://logs.syseleven.services/<org_id>/<project_id>
        access: proxy
        editable: false
        jsonData:
          httpHeaderName1: Authorization
        secureJsonData:
          httpHeaderValue1: "Bearer s11_prak_<uuid>_<secret>"
```

> [!NOTE]
>
> **Configuration via GUI**
>
> You can also configure the data sources via the Grafana GUI. From Grafana, head to **Data sources** and add a new data source for Alertmanager, Mimir and Loki. Use the configuration provided above as a reference to fill in the required values in the GUI.

Remember to replace the placeholder values with the correct data.

> [!TIP]
>
> **Using Grafana Alloy**
>
> We highly recommend taking a look at the [`alloy-scenarios` repository](<https://github.com/grafana/alloy-scenarios>), which contains various Alloy scenarios that can be used as a starting point for your own Alloy configuration.
