DEV Community

loading...
Cover image for #30DaysOfAppwrite: Grafana Integration
Appwrite

#30DaysOfAppwrite: Grafana Integration

Christy Jacob
・5 min read

Intro

Appwrite is an open-source, self-hosted Backend-as-a-Service that makes app development easier with a suite of SDKs and APIs to accelerate app development. #30DaysOfAppwrite is a month long event focused at giving developers a walk through of all of Appwrite's features, starting from the basics to more advanced features like Cloud Functions! Alongside we will also be building a fully featured Medium Clone to demonstrate how these concepts can be applied when building a real world app. We also have some exciting prizes for developers who follow along with us!

Grafana Integration

Welcome to Day 29 👋 - today marks the last day of #30DaysOfAppwrite, and we thought it would be a fun little exercise to show you how you can add external services to the Appwrite stack and make it work seamlessly! We love Dashboards, and we thought it would be great to add Grafana support to Appwrite.

Appwrite doesn't come with Grafana out of the box and for a couple of reasons. First, you may already have your own set of monitoring tools in your stack, and we believe that our stack should be un-opinionated and allow you to work with the tools you feel comfortable with. The second reason is that we try to ship the Appwrite setup with minimal components to make Appwrite easy to start, but still flexible enough to grow.

Add Grafana to Appwrite

We will be creating two Dashboards: one for monitoring Appwrite's usage stats and one for monitoring your Server stats.

The first step is to add the Grafana service to Appwrite's docker-compose.yml file.

  grafana:
    image: grafana/grafana
    container_name: appwrite-grafana
    ports:
      - "3000:3000"
    networks:
      - appwrite
    volumes:
      - appwrite-grafana:/var/lib/grafana
Enter fullscreen mode Exit fullscreen mode

Next you need to add the appwrite-grafana volume to the list of all volumes. This will allow your Grafana container to persist data.

volumes:
  appwrite-mariadb:
  appwrite-redis:
  appwrite-cache:
  appwrite-uploads:
  appwrite-certificates:
  appwrite-functions:
  appwrite-influxdb:
  appwrite-config:
  appwrite-grafana:
Enter fullscreen mode Exit fullscreen mode

Now run

docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

Dashboard #1 - Appwrite Metrics

For your first Dashboard, we don't need any additional configuration in our services. Now head over to http://localhost:3000 to configure Grafana. You can login using the default credentials

username : admin
password : admin
Enter fullscreen mode Exit fullscreen mode

You will be prompted to enter a new password and it is highly recommended that you change it. Learn more about managing users and passwords in their official guide.

The first step is to configure your Data Source. In our case, we will be using the InfluxDB plugin.

add-datasource

Once you add the InfluxDB data source, it's time to configure it. Here, you need to fill in the values of 2 fields,

Finally click Save and Test to check your database connection. If all goes well, you will see a success message.
configure-datasource

The next step is to import the Dashboard we created for you. Head to the Grafana's Dashboard Library and copy the ID of our Dashboard .

You can then Import the Dashboard in your Grafana instance like so.
import-appwrite-dashboard

And that's it! You should now see this fancy Dashboard
row-1-col-1
row-2-col-1

Dashboard #2 - Server Metrics

The next Dashboard is one that that will monitor our server metrics. This includes the CPU usage, Disk I/O, Network I/O and much more. This Dashboard requires some additional info, so we need to make a few changes in our telegraf Docker image to make this information available.

We'll start by cloning Appwrite's telegraf image

git clone https://github.com/appwrite/docker-telegraf.git 
cd docker-telegraf
Enter fullscreen mode Exit fullscreen mode

We need to make more metrics available to the collector. Add the following lines to line 83

[[inputs.cpu]]
    percpu = true
    totalcpu = true
    collect_cpu_time = false
    report_active = false
[[inputs.disk]]
    ignore_fs = ["tmpfs", "devtmpfs", "devfs"]
[[inputs.io]]
[[inputs.mem]]
[[inputs.net]]
[[inputs.system]]
[[inputs.swap]]
[[inputs.netstat]]
[[inputs.processes]]
[[inputs.kernel]]
Enter fullscreen mode Exit fullscreen mode

Now we need to build a new Docker image using the changes we made.

docker build -t telegraf-local .
Enter fullscreen mode Exit fullscreen mode

Once this build is complete, we can make use of our new telegraf-local image in the main Appwrite docker-compose.yml. Replace the appwrite/telegraf:1.1.0 image in line 434 with our telegraf-local image.

  telegraf:
    image: telegraf-local
    container_name: appwrite-telegraf
    networks:
      - appwrite
Enter fullscreen mode Exit fullscreen mode

Now run docker-compose up -d --remove-orphans from your appwrite directory to restart your services.
Now head over to your Grafana Dashboard and import this new Dashboard the same way as you did the previous one and if everything goes well, you should see the following Dashboard!
row-1-col-1
row-2-col-1
row-3-col-1

And just like that, you now have access to all your server information in one place! This was just the tip of the iceberg! Grafana has many more amazing features. It's completely open-source, has support for over 30 Data Sources, has support for Alerting etc. You can setup custom alerts and Grafana will continuously evaluate and send notifications to systems like Slack, PagerDuty, VictorOps and OpsGenie. You can learn more about all of Grafana's features in their dedicated tutorials section.

Credits

We hope you liked this write up. You can follow #30DaysOfAppwrite on Social Media to keep up with all of our posts. The complete event timeline can be found here

Feel free to reach out to us on Discord if you would like to learn more about Appwrite, Aliens or Unicorns 🦄. Stay tuned for tomorrow's article! Until then 👋

Discussion (3)

Collapse
alexweininger profile image
Alex Weininger

🤯 🤯 🤯

I was just thinking about trying this, but I wasn't sure where to start. I am 100% doing this!

Collapse
christyjacob4 profile image
Christy Jacob Author

Hehhe This should be a good starting point

Collapse
alexweininger profile image
Alex Weininger

I just got it all set up! This is super cool.