# Examples

## Sample code for connection using C sharp

Download nuget package for working with influx: <https://www.nuget.org/packages/InfluxDB.Client/>

After importing nuget package into project we can access database using the following snippet:

```
var influxDBClient = InfluxDBClientFactory.Create(url, token);
```

* We obtain url and token using steps in connection.

To query influx database use scripting language [flux](https://docs.influxdata.com/influxdb/v2.0/query-data/get-started/).

Sample of getting data about live sessions:

```
private static async Task<List<FluxTable>> GetFluxTables(int companyId, string measurement)
{
    var flux = "from(bucket:\"mluvii_realtime\") " +
               "|> range(start: -1h)" +
              $"|> filter(fn: (r) => r[\"_measurement\"] == \"{measurement}\")" +
               "|> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")";
     return await influxDBClient.GetQueryApi().QueryAsync(flux, org: $"company_{companyId}");
}
```

* Bucket is always the same "mluvii\_realtime"
* CompanyId is company ID
* Measurement is combination of metric's name and a suffix which is configured in the metric's settings in mluvii.&#x20;

{% hint style="info" %}
Example: running\_sessions\_demo, where "running\_sessions" is the name of the metric and "demo" is configured in mluvii
{% endhint %}

### Next steps?

* [Grafana](/en/for-it-specialists/realtime-statistics/grafana.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mluvii.com/en/for-it-specialists/realtime-statistics/examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
