# 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](https://docs.mluvii.com/en/for-it-specialists/realtime-statistics/grafana)
