# Organize Content Using Tags

Datasentinel uses **InfluxDB**, a time-series database, to store activity metrics collected from PostgreSQL instances.

InfluxDB supports [**Tags**](https://docs.datasentinel.io/manual/features/tips-and-hints/tags), which can be associated with measurements to index and filter metrics based on specific criteria. When used correctly, tags make it easier to organize data, improve query performance, and simplify analysis.

{% hint style="info" %}
A tag is made up of a key and a value. (Ex **application=crm**)
{% endhint %}

<div data-with-frame="true"><figure><img src="https://1072624949-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlcWi6G1jtNuyGT9C0pkc%2Fuploads%2FgMTQXb9w8KpjZXPEgfdo%2Fhome-tags.png?alt=media&#x26;token=6ce0a968-7ad5-47cd-9e18-43b16c745b79" alt=""><figcaption></figcaption></figure></div>

## Automatic tags

Datasentinel automatically creates a set of default tags for each monitored PostgreSQL instance

<table><thead><tr><th width="219.4371337890625">Tag</th><th>Description</th></tr></thead><tbody><tr><td><strong>pg_instance</strong></td><td>Concatenation of the server name and the instance name</td></tr><tr><td><strong>pg_version</strong></td><td>PostgreSQL version</td></tr><tr><td><strong>server</strong></td><td>Server name</td></tr><tr><td><strong>database</strong></td><td>Database name, if any</td></tr></tbody></table>

## **Defining custom tags**

You can define custom tags to describe additional attributes of a monitored instance, such as the application it belongs to, the deployment environment, or the infrastructure provider.

Datasentinel does not impose restrictions on custom tags, allowing you to create and use tags that best fit your monitoring and organizational needs.

The following example shows **JSON configuration file** used to [register an instance](https://docs.datasentinel.io/manual/getting-started/postgresql-clusters/adding-connection) with a Datasentinel agent, including custom tag definitions.

```json
{
    "name": "crm", 
    "host": "pg-crm-2031",
    "port": 9342,
    "user": "datasentinel",
    "password": "password",
    "tags": "application=crm,environment=production,provider=azure,datacenter=lyon"
}

```

{% hint style="info" %}
Custom tags can also be defined when using the [Agentless monitoring approach](https://docs.datasentinel.io/manual/features/other-features/agentless-monitoring). \
In this case, tags are specified as part of the instance configuration, either through the UI or via the [API](https://docs.datasentinel.io/manual/implementation/platform-usage/api-reference/connection).
{% endhint %}

{% hint style="warning" %}
To avoid issues, it is recommended to use only alphanumeric characters and underscores (`_`) in tag keys and values.
{% endhint %}

## **Session History and Tags**

***

Datasentinel [periodically samples active sessions](https://docs.datasentinel.io/manual/features/key-features/session-history).&#x20;

During sampling, it automatically adds session-related tags based on data from `pg_stat_activity`.<br>

<table><thead><tr><th width="329.8511962890625">Tag</th><th>Description</th></tr></thead><tbody><tr><td><strong>application_name</strong></td><td>Application name, if any</td></tr><tr><td><strong>client_host_name</strong></td><td>Server name or IP address</td></tr><tr><td><strong>command_type</strong></td><td>SQL command type</td></tr><tr><td><strong>query_md5_id</strong></td><td>MD5 identifier of the running SQL statement</td></tr><tr><td><strong>user_name</strong></td><td>User name</td></tr><tr><td><strong>wait_event</strong></td><td>Current wait event (I/O wait, lock, etc.) or CPU execution</td></tr><tr><td><strong>wait_event_type</strong></td><td>Event type (CPU, I/O, etc)</td></tr></tbody></table>

<figure><img src="https://1072624949-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlcWi6G1jtNuyGT9C0pkc%2Fuploads%2F4mcBBgIoqohOa5gg832Z%2FsessionHistoryTags.png?alt=media&#x26;token=01b146cd-c081-40be-ba8b-324c362e8973" alt=""><figcaption></figcaption></figure>

## **Why Use Tags?**

### Filtering

Tags allow you to filter based on specific criteria such as environment, application, or any other custom attribute.

This is especially useful when managing a large number of instances, as it helps you quickly narrow your focus to the systems relevant to your current task or analysis.

For example, if all production instances are tagged with `environment=production`, you can filter on that tag to view workloads for production systems only.

<div data-with-frame="true"><figure><img src="https://1072624949-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlcWi6G1jtNuyGT9C0pkc%2Fuploads%2Fb8317qzTFyfAkm2R1kwt%2FTagFilter.png?alt=media&#x26;token=71c1d728-49dc-4daf-9769-53c597ceb981" alt=""><figcaption></figcaption></figure></div>

### Data Analysis

\
The Data Analysis module provides tag-based statistics that offer a global view of activity.&#x20;

For example, you can group top resource consumers by a tag such as the provider.

<div data-with-frame="true"><img src="https://blog.datasentinel.io/images/top-consumers-provider.png" alt="PostgreSQL top consumers per provider"></div>

<br>

### **Consolidated Workload Analysis**

Tags make it possible to extract aggregated statistics and obtain a global view of activity across multiple instances.

This is particularly useful when you want to analyze workloads at a higher level, rather than instance by instance. By grouping instances using a common tag, you can consolidate their workload and perform cross-instance analysis.

Common use cases include:

* Listing the top SQL queries across multiple instances of the same application
* Viewing overall activity for all instances running on a given server
* Analyzing the consolidated workload of a primary instance and its read-only replicas

All of this can be done in just a few clicks, thanks to tags.

<div data-with-frame="true"><figure><img src="https://1072624949-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlcWi6G1jtNuyGT9C0pkc%2Fuploads%2F3z6D18yvraiwdqCY6ILE%2FconsolidatedWorkload.png?alt=media&#x26;token=335ed762-1601-43d8-ab63-4a1701a8e68c" alt=""><figcaption></figcaption></figure></div>

### Role-Based Access Control

***

Datasentinel provides user management with support for [**role-based access control (RBAC)**](https://docs.datasentinel.io/manual/features/other-features/role-based-access).

Roles can be defined based on the value of one or more tags. When a role is associated with a user, access can be restricted to all or part of your PostgreSQL instance scope, depending on the tags assigned to those instances.

This makes it possible to enforce fine-grained access control aligned with your organization’s structure and environments.

**Example:**\
You can create a user who has access only to instances tagged as `environment=development`.

## Conclusion

Tags play a central role in Datasentinel, enabling efficient analysis, consolidated views, and tag-based access control.&#x20;

A consistent tagging strategy is key to scaling monitoring across multiple PostgreSQL instances.
