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!
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.
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
grafana: image: grafana/grafana container_name: appwrite-grafana ports: - "3000:3000" networks: - appwrite volumes: - appwrite-grafana:/var/lib/grafana
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:
docker-compose up -d
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
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.
Once you add the InfluxDB data source, it's time to configure it. Here, you need to fill in the values of 2 fields,
- URL - http://influxdb:8086
- Database - telegraf
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 .
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
git clone https://github.com/appwrite/docker-telegraf.git cd docker-telegraf
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]]
Now we need to build a new Docker image using the changes we made.
docker build -t telegraf-local .
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: image: telegraf-local container_name: appwrite-telegraf networks: - appwrite
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!
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.
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 👋