Merge pull request New article: Wakapi Install #27 from ditatompel/newarticle
New article: Wakapi Install Menginstall Wakapi, Sebuah Self-Hosted Koding Statistik yang Kompatible Dengan WakaTime Client API
After Width: | Height: | Size: 75 KiB |
After Width: | Height: | Size: 108 KiB |
|
@ -0,0 +1,216 @@
|
|||
---
|
||||
title: "Menginstall Wakapi, Sebuah Self-Hosted Koding Statistik yang Kompatible Dengan WakaTime Client API"
|
||||
description: "Tutorial cara install Wakapi, sebuah self-hosted koding statistik yang kompatible dengan WakaTime Client API"
|
||||
# linkTitle:
|
||||
date: 2023-08-21T01:18:54+07:00
|
||||
lastmod:
|
||||
draft: false
|
||||
noindex: false
|
||||
featured: false
|
||||
# comments: false
|
||||
nav_weight: 1000
|
||||
# nav_icon:
|
||||
# vendor: bootstrap
|
||||
# name: toggles
|
||||
# color: '#e24d0e'
|
||||
series:
|
||||
# - Tutorial
|
||||
categories:
|
||||
- Self-Hosted
|
||||
- Programming
|
||||
- SysAdmin
|
||||
- Privasi
|
||||
tags:
|
||||
- WakaTime
|
||||
- Wakapi
|
||||
- Nginx
|
||||
- Go
|
||||
- ActivityWatch
|
||||
- CodeStats
|
||||
images:
|
||||
# menu:
|
||||
# main:
|
||||
# weight: 100
|
||||
# params:
|
||||
# icon:
|
||||
# vendor: bs
|
||||
# name: book
|
||||
# color: '#e24d0e'
|
||||
authors:
|
||||
- ditatompel
|
||||
---
|
||||
|
||||
**Wakapi** adalah sebuah _self-Hosted_ koding statistik yang kompatible dengan **WakaTime client**. Dapat diinstall di Windows, MacOS, maupun Linux. Karena Anda yang memegang server, maka data benar-benar milik Anda. Artikel ini berisi cara untuk menjalankan Wakapi di sistem operasi Linux.
|
||||
|
||||
<!--more-->
|
||||
---
|
||||
|
||||
## Pengantar
|
||||
|
||||
Saya yang sehari-harinya banyak berinteraksi dengan komputer, terutama melakukan _maintenance server_ dan koding selalu ingin tahu apa saja yang sudah saya kerjakan, projek mana yang paling banyak menyita waktu, dan bahasa program apa yang paling banyak saya gunakan. Ada beberapa jasa yang pernah saya cobaselama setahun terakhir, dari [Activity Watch](https://activitywatch.net/), [CodeStats](https://codestats.net/), hingga [WakaTime](https://wakatime.com/).
|
||||
|
||||
Untuk **Activity Watch**, memang _backend_ bisa diinstall di lokal / _remote server_, tetapi saya rasa cukup berat dijalankan. Untuk **CodeStats** dan **WakaTime** cukup memuaskan, tetapi ada yang kurang, yaitu data statistik koding dikirimkan ke server mereka. Tentu saja hal tersebut cukup mengganggu pikiran saya.
|
||||
|
||||
Beruntungnya, beberapa hari yang lalu ketika saya melakukan *"window shopping"* ke **GitHub** menemukan solusi dari yang selama ini saya inginkan yaitu [Wakapi](https://wakapi.dev/); sebuah _endpoint_ API yang kompatibel dengan **WakaTime client** yang bisa di-_self-hosted_.
|
||||
|
||||
Wakapi server dibuat dengan bahasa program **Go**, dan dapat dijalankan di sistem operasi Windows, MacOS (baik `ARM` maupun `x86_64`), maupun Linux (baik `ARM` maupun `x86_64`). Di artikel kali ini saya ingin berbagi pengalaman menginstall dan menjalankan Wakapi di Linux server.
|
||||
|
||||
## Installasi Server
|
||||
Sebelum memulai, ada beberapa prasyarat yang harus dipenuhi untuk mengikuti artikel ini:
|
||||
- Nyaman menggunakan Linux terminal
|
||||
- Salah satu WakaTime client sudah terinstall dan berjalan dengan baik
|
||||
- Sebuah Linux server / Laptop / PC
|
||||
- Sebuah Web Server (pada artikel ini saya menggunakan **Nginx**. Optional, tapi __recommended__ jika Wakapi dapat diakses dari publik)
|
||||
|
||||
Ada beberapa cara menjalankan Wakapi server sendiri:
|
||||
1. Menggunakan _precompiled binary_
|
||||
2. menggunakan **Docker**
|
||||
3. _Compile_ dari _source-code_
|
||||
|
||||
Karena di server saya sudah terinstall Go, maka pada artikel ini saya akan menggunakan opsi ketiga, yaitu melakukan _compile_ langsung dari __source-code__-nya.
|
||||
|
||||
### Mempersiapkan Sistem & Compile Executable Binary
|
||||
Pertama, persiapkan sistem dengan membuat sistem user baru:
|
||||
```shell
|
||||
sudo useradd -r -m --system -d /opt/wakapi -s /bin/bash wakapi
|
||||
```
|
||||
|
||||
_Clone_ repositori [mutey/wakapi](https://github.com/muety/wakapi) dan lakukan _compile executable binary_-nya:
|
||||
```shell
|
||||
# clone repo
|
||||
git clone https://github.com/muety/wakapi.git
|
||||
|
||||
# build executable binary
|
||||
cd wakapi
|
||||
go build -o wakapi
|
||||
```
|
||||
|
||||
### Setting Konfigurasi Wakapi
|
||||
Setelah proses _compile_ selesai, pindahkan _executable binary_ ke `$HOME` milik user `wakapi` yang sudah kita buat sebelumnya.
|
||||
```shell
|
||||
sudo mv wakapi /opt/wakapi/
|
||||
```
|
||||
Download contoh konfigurasi
|
||||
```shell
|
||||
sudo curl -o /opt/wakapi/wakapi.yml https://raw.githubusercontent.com/muety/wakapi/master/config.default.yml
|
||||
# ubah kepemilikan file ke user wakapi
|
||||
sudo chown wakapi:wakapi /opt/wakapi/wakapi.yml /opt/wakapi/wakapi
|
||||
```
|
||||
|
||||
Kemudian edit file konfigurasi `/opt/wakapi/wakapi.yml` sesuai dengan yang dibutuhkan. Misalnya, saya akan menggunakan subdomain `wakapi.example.com` dengan Nginx sebagai _reverse proxy_ untuk Wakapi, maka saya set `listen_ipv4` nya ke `127.0.0.1` dan `public_url` nya ke `https://wakapi.example.com`. Sesuaikan konfigurasi yang lain seperti koneksi database, SMTP email, dan lain-lain.
|
||||
|
||||
### Membuat Systemd Service
|
||||
Setelah konfigurasi sudah disesuaikan dengan kebutuhan, buat **Systemd service** Wakapi untuk mempermudah manajemen dalam menjalankan atau merestart _Wakapi service_.
|
||||
|
||||
Buat file `/etc/systemd/system/wakapi.service` dengan isi kurang lebih seperti berikut:
|
||||
```systemd
|
||||
[Unit]
|
||||
Description=Wakatime Wakapi
|
||||
StartLimitIntervalSec=400
|
||||
StartLimitBurst=3
|
||||
|
||||
# Optional, dan jika menggunakan SQL / PostgreSQL dengan Systemd
|
||||
Requires=mysql.service
|
||||
After=mysql.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
|
||||
WorkingDirectory=/opt/wakapi
|
||||
ExecStart=/opt/wakapi/wakapi -config /opt/wakapi/wakapi.yml
|
||||
|
||||
User=wakapi
|
||||
Group=wakapi
|
||||
RuntimeDirectory=wakapi # creates /run/wakapi, useful to place your socket file there
|
||||
|
||||
Restart=on-failure
|
||||
RestartSec=90
|
||||
|
||||
# Security hardening
|
||||
PrivateTmp=true
|
||||
PrivateUsers=true
|
||||
NoNewPrivileges=true
|
||||
ProtectSystem=full
|
||||
ProtectHome=true
|
||||
ProtectKernelTunables=true
|
||||
ProtectKernelModules=true
|
||||
ProtectKernelLogs=true
|
||||
ProtectControlGroups=true
|
||||
PrivateDevices=true
|
||||
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
|
||||
ProtectClock=true
|
||||
RestrictSUIDSGID=true
|
||||
ProtectHostname=true
|
||||
ProtectProc=invisible
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
Kemudian _reload_ dan jalankan wakapi _service_:
|
||||
```shell
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable wakapi.service --now
|
||||
|
||||
# cek apakah service berjalan dengan baik
|
||||
systemctl status wakapi.service
|
||||
```
|
||||
Jika semua berjalan dengan baik, masuk ke langkah selanjutnya untuk Nginx _reverse proxy_.
|
||||
|
||||
### Nginx Reverse Proxy
|
||||
Untuk konfigurasi Nginx, tidak memerlukan konfigurasi khusus. Cukup gunakan konfigurasi _reverse proxy_ pada umumnya. Contoh:
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name wakapi.example.com;
|
||||
root /opt/wakapi;
|
||||
access_log off;
|
||||
location /.well-known/acme-challenge/ { allow all; }
|
||||
location / { return 301 https://$host$request_uri; }
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
server_name wakapi.example.com;
|
||||
access_log off;
|
||||
|
||||
ssl_certificate /path/to/fullchain.pem;
|
||||
ssl_certificate_key /path/to/privkey.pem;
|
||||
|
||||
# bla bla bla
|
||||
|
||||
location / {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Sesuaikan `proxy_pass` dengan konfigurasi `listen_ipv4` dan `port` dari `/opt/wakapi/wakapi.yml` milik Anda.
|
||||
|
||||
Kemudian coba akses dari Wakapi server Anda dan lakukan registrasi. Setelah berhasil melakukan registrasi, Anda akan mendapatkan **API key** yang nantinya Anda perlukan untuk setting **WakaTime client**.
|
||||
|
||||
## Konfigurasi WakaTime Client
|
||||
Server sudah siap dan siap menerima _"heartbeat"__ Anda. Selanjutnya sesuaikan konfigurasi WakaTime client Anda ke _self-hosted_ Wakapi Anda.
|
||||
Ubah konfigurasi `api_url` dan `api_key` di `.wakatime.cfg` Anda ke server milik Anda. Misalnya:
|
||||
|
||||
```ini
|
||||
[settings]
|
||||
|
||||
api_url = https://wakapi.example.com/api
|
||||
api_key = API-Key-Anda-Dari-Wakapi-Server-Anda
|
||||
```
|
||||
|
||||
Coba lakukan aktifitas koding dan cek aktifitas koding Anda dari Dashboard Wakapi.
|
||||
|
||||
Jika Anda kurang puas dengan tampilan dashboard pada Wakapi web UI, anda bisa mengekspose _metrics_ ke format **Prometheus** kemudian [memvisualisasikannya menggunakan **Grafana**](https://grafana.com/grafana/dashboards/12790-wakatime-coding-stats/).
|
||||
|
||||
![Contoh Wakapi Grafana Dashboard](grafana-wakapi.png#center)
|
||||
|
||||
Anda juga bisa mengintegrasikannya dengan [GitHub Readme Stats](https://github.com/anuraghazra/github-readme-stats) sehingga aktifitas koding Anda dapat tampil di halaman Profile gitHub Anda.
|
||||
|
||||
Sekian pengalaman saya menginstall Wakapi server, semoga dapat menjadi inspirasi.
|
|
@ -0,0 +1,230 @@
|
|||
---
|
||||
title: "Running Wakapi, a Self-Hosted WakaTime Compatible Backend for Coding Stats"
|
||||
description: "A guide to install Wakapi, a self-hosted WakaTime compatible backend for your coding stats"
|
||||
# linkTitle:
|
||||
date: 2023-08-21T01:18:54+07:00
|
||||
lastmod:
|
||||
draft: false
|
||||
noindex: false
|
||||
featured: false
|
||||
# comments: false
|
||||
nav_weight: 1000
|
||||
# nav_icon:
|
||||
# vendor: bootstrap
|
||||
# name: toggles
|
||||
# color: '#e24d0e'
|
||||
series:
|
||||
# - Tutorial
|
||||
categories:
|
||||
- Self-Hosted
|
||||
- Programming
|
||||
- SysAdmin
|
||||
- Privacy
|
||||
tags:
|
||||
- WakaTime
|
||||
- Wakapi
|
||||
- Nginx
|
||||
- Go
|
||||
- ActivityWatch
|
||||
- CodeStats
|
||||
images:
|
||||
# menu:
|
||||
# main:
|
||||
# weight: 100
|
||||
# params:
|
||||
# icon:
|
||||
# vendor: bs
|
||||
# name: book
|
||||
# color: '#e24d0e'
|
||||
authors:
|
||||
- ditatompel
|
||||
---
|
||||
|
||||
**Wakapi** is a minimalist, __self-hosted__ **WakaTime**-compatible backend for coding statistics. It's cross platform (Windows, MacOS, Linux) and can be self-hosted to your local computer or your own server, so your data is really yours. This article will guide you how to run Wakapi on Linux operating system.
|
||||
|
||||
<!--more-->
|
||||
---
|
||||
|
||||
## Introduction
|
||||
|
||||
As someone who extensively use computers on a daily basis, particularly performing server maintenance and coding, I'm always curious about what I've been working on, which projects consume the most of my time, and which programming languages I use the most. Over the past year, I've tried several services, from [Activity Watch](https://activitywatch.net/), [CodeStats](https://codestats.net/) to [WakaTime](https://wakatime.com/).
|
||||
|
||||
With **Activity Watch**, while the backend can be installed on a local or remote server, I found it to be somewhat _resource-intensive_. While **CodeStats** and **WakaTime** were really good, the coding statistics data was sent to their servers; this aspect was a concern for me.
|
||||
|
||||
A few days ago, I found a solution for that problem: [Wakapi](https://wakapi.dev/). It's an API endpoint **compatible with the WakaTime client**, and it can be _self-hosted_.
|
||||
|
||||
The **Wakapi server** is built using the **Go** programming language and can be run on various operating systems, including Windows, MacOS (both `ARM` and `x86_64`), and Linux (both `ARM` and `x86_64`). In this article, I want to share my experience installing and running Wakapi on a Linux server.
|
||||
|
||||
## Server Installation
|
||||
|
||||
Before we begin, there are some prerequisites to meet in order to follow this article:
|
||||
- Comfortable using Linux terminal
|
||||
- A WakaTime client already installed and working properly
|
||||
- A Linux server / laptop / PC
|
||||
- A web server (for this article, I'm using Nginx. _Optional, but **recommended if Wakapi will be accessed publicly**_)
|
||||
|
||||
There are a few ways to run your own Wakapi server:
|
||||
1. Using precompiled binary
|
||||
2. Using Docker
|
||||
3. Compiling from source code
|
||||
|
||||
Since **Go** is already installed on my server, I'll be using the third option here — compiling directly from source code.
|
||||
|
||||
### System Preparation & Compiling Executable Binary
|
||||
|
||||
First, prepare the system by creating a new system user:
|
||||
|
||||
```shell
|
||||
sudo useradd -r -m --system -d /opt/wakapi -s /bin/bash wakapi
|
||||
```
|
||||
|
||||
Clone the [mutey/wakapi repository](https://github.com/muety/wakapi) and compile the executable binary:
|
||||
|
||||
```shell
|
||||
# clone repo
|
||||
git clone https://github.com/muety/wakapi.git
|
||||
|
||||
# build executable binary
|
||||
cd wakapi
|
||||
go build -o wakapi
|
||||
```
|
||||
|
||||
### Wakapi Configuration Setup
|
||||
|
||||
After the compilation process is complete, move the executable binary to the `wakapi`'s `$HOME` directory that we created earlier:
|
||||
```shell
|
||||
sudo mv wakapi /opt/wakapi/
|
||||
```
|
||||
|
||||
Download a sample configuration:
|
||||
|
||||
```shell
|
||||
sudo curl -o /opt/wakapi/wakapi.yml https://raw.githubusercontent.com/muety/wakapi/master/config.default.yml
|
||||
# Change file ownership to the wakapi user
|
||||
sudo chown wakapi:wakapi /opt/wakapi/wakapi.yml /opt/wakapi/wakapi
|
||||
```
|
||||
|
||||
Then, edit the `/opt/wakapi/wakapi.yml` configuration file as needed. For instance, if I'm using the subdomain `wakapi.example.com` with **Nginx** as a _reverse proxy_ for Wakapi, I'd set the `listen_ipv4` to `127.0.0.1` and `public_url` to `https://wakapi.example.com`. Adjust other configurations such as database connection, SMTP email, etc if you need to.
|
||||
|
||||
### Creating a Systemd Service
|
||||
|
||||
Creating **Systemd** service making it easy to start or restart the Wakapi service.
|
||||
|
||||
Create `/etc/systemd/system/wakapi.service` and adapt from these following example configuration:
|
||||
|
||||
```systemd
|
||||
[Unit]
|
||||
Description=Wakatime Wakapi
|
||||
StartLimitIntervalSec=400
|
||||
StartLimitBurst=3
|
||||
|
||||
# Optional, and if you using MySQL or PostgreSQL
|
||||
Requires=mysql.service
|
||||
After=mysql.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
|
||||
WorkingDirectory=/opt/wakapi
|
||||
ExecStart=/opt/wakapi/wakapi -config /opt/wakapi/wakapi.yml
|
||||
|
||||
User=wakapi
|
||||
Group=wakapi
|
||||
RuntimeDirectory=wakapi # creates /run/wakapi, useful to place your socket file there
|
||||
|
||||
Restart=on-failure
|
||||
RestartSec=90
|
||||
|
||||
# Security hardening
|
||||
PrivateTmp=true
|
||||
PrivateUsers=true
|
||||
NoNewPrivileges=true
|
||||
ProtectSystem=full
|
||||
ProtectHome=true
|
||||
ProtectKernelTunables=true
|
||||
ProtectKernelModules=true
|
||||
ProtectKernelLogs=true
|
||||
ProtectControlGroups=true
|
||||
PrivateDevices=true
|
||||
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
|
||||
ProtectClock=true
|
||||
RestrictSUIDSGID=true
|
||||
ProtectHostname=true
|
||||
ProtectProc=invisible
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
```
|
||||
|
||||
Then, reload and start the wakapi service:
|
||||
|
||||
```shell
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable wakapi.service --now
|
||||
|
||||
# Check if the service is running properly
|
||||
systemctl status wakapi.service
|
||||
```
|
||||
|
||||
If everything is running smoothly, proceed to the next step for Nginx reverse proxy configuration.
|
||||
|
||||
### Nginx Reverse Proxy
|
||||
|
||||
For the Nginx configuration, no special adjustments are needed. You can simply use a standard reverse proxy configuration. For example:
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 80;
|
||||
server_name wakapi.example.com;
|
||||
root /opt/wakapi;
|
||||
access_log off;
|
||||
location /.well-known/acme-challenge/ { allow all; }
|
||||
location / { return 301 https://$host$request_uri; }
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
server_name wakapi.example.com;
|
||||
access_log off;
|
||||
|
||||
ssl_certificate /path/to/fullchain.pem;
|
||||
ssl_certificate_key /path/to/privkey.pem;
|
||||
|
||||
# bla bla bla
|
||||
|
||||
location / {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Adjust the `proxy_pass` to match with the `listen_ipv4` and `port` configurations from your `/opt/wakapi/wakapi.yml`.
|
||||
|
||||
Now, try accessing your Wakapi server and register for an account. You'll receive an API key that you'll need to set in your **WakaTime client**.
|
||||
|
||||
## WakaTime Client Configuration
|
||||
|
||||
Your server is ready to accept your __"heartbeat"__, configure your **WakaTime client** to connect to your __self-hosted__ **Wakapi instance**.
|
||||
|
||||
To do so, modify the `api_url` and `api_key` in your `.wakatime.cfg` to match with your server configuration. For example:
|
||||
|
||||
```ini
|
||||
[settings]
|
||||
api_url = https://wakapi.example.com/api
|
||||
api_key = Your-API-Key-From-Your-Wakapi-Server
|
||||
```
|
||||
|
||||
Start coding and check your coding activity on the Wakapi Dashboard.
|
||||
|
||||
Wakapi also have a feature to export metrics to **Prometheus** format and then [visualize them with Grafana](https://grafana.com/grafana/dashboards/12790-wakatime-coding-stats/).
|
||||
|
||||
![Example Wakapi Grafana Dashboard](grafana-wakapi.png#center)
|
||||
|
||||
You can also integrate it with [GitHub Readme Stats](https://github.com/anuraghazra/github-readme-stats#wakatime-week-stats) to display your coding activity on your GitHub profile page.
|
||||
|
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 74 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 48 KiB |