# Fly.io + qryn

[![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1667308904381/IQoGpTgXH.png align="left")](https://qryn.dev)

If you're a [Fly.io](https://fly.io) user, you can start an instance of [qryn](https://qryn.dev) in seconds using our public Docker images and seamlessly connect it to your *local or remote* **ClickHouse**.

#### Requirements

* Fly.io account and browser access to the [Fly.io](http://Fly.io) [WebCLI](https://flyctl.sh/shell)
    
* Any ClickHouse Service *(ClickHouse Cloud, DoubleCloud, Altinity, Gigapipe)*
    
* Something to observe! add *Logs, Metrics or Traces from anywhere*
    

Ready? Let's get started!

#### Configure **qryn**

Configure the `ENV` settings to match your **ClickHouse** server endpoint.

```bash
flyctl secrets set CLICKHOUSE_SERVER = "your.clickhouse.server"
flyctl secrets set CLICKHOUSE_AUTH = "admin:secretpassword"
flyctl secrets set CLICKHOUSE_PROTO = "https"
flyctl secrets set CLICKHOUSE_PORT = 8443
```

#### Launch **qryn**

Double check your settings and deploy your **qryn** container.

```bash
fly launch --image qryn:latest --now
```

The `fly launch` command detects your `Dockerfile` and builds it.

```plaintext
? App Name (leave blank to use an auto-generated name):
? Select region: lax (Los Angeles, California (US))
? Would you like to deploy now? (y/N)
```

Choose `y` or run `fly open` to open your deployed app in a browser.

*SSL/Encryption are automatically handled by the fly.io edge servers.* 🔒

*That's it! Your API instance is up and running!* 🎉

![](https://user-images.githubusercontent.com/1423657/184487816-fcc86e34-0395-4927-8ceb-33c2ad3e63d4.gif align="left")

#### Usage

The system is quite **boring** *without data*. Let's insert some and start querying!

As a quick example, let's use CURL to send our first little log:

```plaintext
curl -X POST -H "Content-Type: application/json" \
https://your-own-qryn.fly.io/loki/api/v1/push --data '{"streams":[{"stream":{"type":"test"},"values":[["'$(date +"%s%N")'", "hello qryn"]]}]}'
```

* Start sending [logs, metrics and traces](https://qryn.metrico.in/#/ingestion) from your systems into **qryn**.
    
* Explore data using qryn's [View UI or using Grafana](https://qryn.metrico.in/#/getting-started).
    

#### 👁️ qryn view

![](https://user-images.githubusercontent.com/1423657/198894721-65e29bc8-697f-4fbb-b95d-4cdc5427e2a2.gif align="left")

#### 👁️ Grafana

Grafana user? No problem! **qryn** works using the native **Loki, Tempo and Prometheus** data sources available in any setup without plugins or special settings.

![](https://user-images.githubusercontent.com/1423657/196654073-b84a218c-6a70-49bb-a477-e8be5714e0ba.gif align="left")

### Scaling

The *free* instances should handle 100s and even 1000s of inserts per second into ClickHouse but might fall short when querying very large datasets requiring memory and time-series buffering.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1666189133359/lyF-pQsdp.png align="left")

You can increase instance resources using the `Fly Dashboard` or `Fly CLI`.

```plaintext
# Give the vm 2GB of ram
fly scale memory 2048
```

### Auto-Scaling

Since **qryn** is completely stateless, multiple instances can be deployed in parallel across different regions and scaled to *handle large amounts of traffic, split insert/read roles, partition users over the same ClickHouse cluster, etc.*

[![](https://cdn.hashnode.com/res/hashnode/image/upload/v1666188751512/TpBhlIdEK.png?height=150 align="left")](https://qryn.dev)

Easy wasn't it? Learn more about all the project features and capabilities using the [online documentation](https://qryn.dev) and enjoy your superlight, free **qryn** polyglot stack on Fly!

#### 📝 Notes

##### configuration

If you'd rather build the `fly.toml` configuration yourself, here's a template:

```toml
# fly.toml file cloned from qryn.dev

app = "qrynjs"
primary_region = "mad"

[build]
  image = "qxip/qryn:latest"

[env]
  CLICKHOUSE_AUTH = "default:xxxxxxxxxxxx"
  CLICKHOUSE_DB = "qryn"
  CLICKHOUSE_PORT = 8443
  CLICKHOUSE_PROTO = "https"
  CLICKHOUSE_SERVER = "xxxxxxxxxx.eu-central-1.aws.clickhouse.xxx"
  HOST = "0.0.0.0"
  PORT = 3100

[[services]]
  internal_port = 3100
  protocol = "tcp"
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20

  [[services.ports]]
    handlers = ["http"]
    port = "80"

  [[services.ports]]
    handlers = ["tls", "http"]
    port = "443"

  [[services.tcp_checks]]
    interval = 10000
    timeout = 2000
```

*That's it! Enjoy your free polyglot stack!*

[Running large scale and looking for an all-inclusive cloud solution? Try **qryn.cloud**](https://qryn.cloud)

[![](https://user-images.githubusercontent.com/1423657/218816262-e0e8d7ad-44d0-4a7d-9497-0d383ed78b83.png align="center")](https://qryn.cloud)
