# Logging and monitoring

PerfectScale provides built-in monitoring and logging capabilities for your on-premises installation.&#x20;

To collect key system metrics and enable effective monitoring, the installation includes Prometheus, Grafana, and necessary exporters. For logging, Loki works alongside Promtail agents to efficiently collect and manage log data.

Remote logging and the ability to write to PerfectScale's centralized Prometheus and Loki instances remotely are enabled by default; however, this feature is optional. Port forwarding provides access to Prometheus and Grafana for viewing logs and metrics.

## How to access the logs  <a href="#how-to-access-to-the-logs" id="how-to-access-to-the-logs"></a>

1. Access Grafana via port forwarding

```
kubectl port-forward svc/monitoring-grafana 8888:80 -n ks-test
```

2. Navigate to [http://127.0.0.1:8888](http://127.0.0.1:8888/) in your browser.
3. Go to **Explore**, select **Loki** in **Outline**, and filter the logs by labels.

<figure><img src="https://3591580169-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzCh9aABpk7yLeToPr6vk%2Fuploads%2FyiSzrNgeJhVlGo5VC7qF%2FFrame%201000001435.png?alt=media&#x26;token=642044b5-aab5-42e1-bac1-f32f9714783f" alt=""><figcaption><p>How to access logs</p></figcaption></figure>

## Loki logs collection and debugging

Use the following instructions to collect logs from Loki and send them to PerfectScale for debugging.

1. Access Grafana via port forwarding

```
kubectl port-forward svc/monitoring-grafana 8888:80 -n ks-test
```

2. Navigate to [http://127.0.0.1:8888](http://127.0.0.1:8888/) in your browser.
3. Go to **Explore**, select **Loki** in **Outline**.&#x20;
4. Set the **Line Limit** to **5000** (1), switch to the **Code** mode(2), and execute the following query (3):

{% hint style="info" %}
Change the namespace to your namespace.
{% endhint %}

```
{namespace="ks-test", pod!~"logging-.*|monitoring-.*|keda-.*|psc-telemetry-.*|python-script-runner-.*|chi-.*|clickhouse-operator-.*|clickhouse-keeper-.*|postgres-postgresql-.*|rabbitmq-.*"} != `Trace` or `Debug` or `No messages left` or `Sleeping`
```

<figure><img src="https://3591580169-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzCh9aABpk7yLeToPr6vk%2Fuploads%2Fz9tqW6oFjYYCbgQ8SfMc%2FGroup%201000001809.png?alt=media&#x26;token=b4debbd6-0ff6-4679-b0fd-e5f441b27d57" alt=""><figcaption><p>Logs collection</p></figcaption></figure>

5. Click Download => CSV.
6. Sent the file to PerfectScale.

## How to access the dashboards <a href="#how-to-access-to-the-dashboards" id="how-to-access-to-the-dashboards"></a>

1. Access Grafana via port forwarding

```
kubectl port-forward svc/monitoring-grafana 8888:80 -n ks-test
```

2. Navigate to [http://127.0.0.1:8888](http://127.0.0.1:8888/) in your browser.
3. Navigate to Home and select Dashboards.
4. Import a new dashboard, or select the existing one.

<figure><img src="https://3591580169-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzCh9aABpk7yLeToPr6vk%2Fuploads%2FHnl35gELLwsg48EcI6vT%2FFrame%201000001437.png?alt=media&#x26;token=38d053a0-89b6-4bee-a756-decffb0f8b14" alt=""><figcaption><p>Dashboards</p></figcaption></figure>
