1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00
📊 A minimalist, self-hosted WakaTime-compatible backend for coding statistics
Go to file
2020-09-12 16:58:31 +02:00
.github debug: re-add workflows again 2020-05-31 10:29:15 +02:00
data Resolve #7. 2020-03-31 11:24:44 +02:00
middlewares feat: allow insecure cookies (resolve #27) 2020-05-30 12:11:25 +02:00
migrations fix: attempt to fix invalid fixture query for postgres (fix #52) 2020-09-12 16:32:43 +02:00
models feat: implement badges endpoint and sharing functionality 2020-09-12 16:09:23 +02:00
routes chore: restrict badge access by user agent 2020-09-12 16:58:22 +02:00
scripts fix: fix build script to cross-compile with sqlite dependency 2020-04-26 14:35:53 +02:00
services feat: implement badges endpoint and sharing functionality 2020-09-12 16:09:23 +02:00
static/assets feat: show placeholders when no data is available (resolve #42) 2020-08-30 16:51:37 +02:00
utils fix: attempt to fix invalid fixture query for postgres (fix #52) 2020-09-12 16:32:43 +02:00
views fix: attempt to fix invalid fixture query for postgres (fix #52) 2020-09-12 16:32:43 +02:00
.dockerignore fix: docker build 2020-04-26 15:07:00 +02:00
.env.example chore: run in dev mode by default 2020-05-31 09:51:55 +02:00
.gitignore feat: add support for sqlite3 2020-04-19 16:58:54 -07:00
config.ini feat: show placeholders when no data is available (resolve #42) 2020-08-30 16:51:37 +02:00
doap.rdf Add DOAP description. 2020-04-05 13:36:01 +02:00
Dockerfile feat: add base_path environment variable 2020-07-14 21:22:30 +10:00
go.mod fix: save heartbeats and summaries with millisecond time precision (resolve #49) 2020-08-30 01:42:00 +02:00
go.sum fix: save heartbeats and summaries with millisecond time precision (resolve #49) 2020-08-30 01:42:00 +02:00
LICENSE Add license. 2019-05-22 07:32:35 +02:00
main.go feat: implement badges endpoint and sharing functionality 2020-09-12 16:09:23 +02:00
README.md docs: readme 2020-09-12 16:50:51 +02:00
version.txt chore: restrict badge access by user agent 2020-09-12 16:58:22 +02:00
wait-for-it.sh fix: docker build 2020-04-26 15:07:00 +02:00

📈 wakapi

Say thanks Go Report Card Coding Activity

A minimalist, self-hosted WakaTime-compatible backend for coding statistics

Wakapi screenshot

If you like this project, please consider supporting it 🙂. You can donate either through buying me a coffee or becoming a GitHub sponsor. Every little donation is highly appreciated and boosts the developers' motivation to keep improving Wakapi!

👀 Demo

🔥 New: There is a hosted demo version available now. Go check it out! Please use responsibly.

To use the demo version set api_url = https://apps.muetsch.io/wakapi/api/heartbeat. However, this hosted instance might be taken down again in the future, so you might potentially lose your data

⚙️ Prerequisites

On the server side:

  • Go >= 1.13 (with $GOPATH properly set)
  • gcc (to compile go-sqlite3)
    • Fedora / RHEL: dnf install @development-tools
    • Ubuntu / Debian: apt install build-essential
    • Windows: See here
  • Optional: A MySQL- or Postgres database

On your local machine:

⌨️ Server Setup

Run from source

  1. Clone the project
  2. Copy .env.example to .env and set database credentials
  3. Adapt config.ini to your needs
  4. Build executable: GO111MODULE=on go build
  5. Run server: ./wakapi

As an alternative to building from source you can also grab a pre-built release. Steps 2, 3 and 5 apply analogously.

Note: By default, the application is running in dev mode. However, it is recommended to set ENV=production in .env for enhanced performance and security. To still be able to log in when using production mode, you either have to run Wakapi behind a reverse proxy, that enables for HTTPS encryption (see best practices) or set insecure_cookies = true in config.ini.

Run with Docker

docker run -d -p 3000:3000 --name wakapi n1try/wakapi

By default, SQLite is used as a database. To run Wakapi in Docker with MySQL or Postgres, see Dockerfile and .env.example for further options.

💻 Client Setup

Wakapi relies on the open-source WakaTime client tools. In order to collect statistics to Wakapi, you need to set them up.

  1. Set up WakaTime for your specific IDE or editor. Please refer to the respective plugin guide
  2. Make your local WakaTime client talk to Wakapi by editing your local ~/.wakatime.cfg file as follows
api_url = https://your.server:someport/api/heartbeat`
api_key = the_api_key_printed_to_the_console_after_starting_the_server`

You can view your API Key after logging in to the web interface.

🔵 Customization

Aliases

There is an option to add aliases for project names, editors, operating systems and languages. For instance, if you want to map two projects myapp-frontend and myapp-backend two a common project name myapp-web in your statistics, you can add project aliases.

At the moment, this can only be done via raw database queries. For the above example, you would need to add two aliases, like this:

INSERT INTO aliases (`type`, `user_id`, `key`, `value`) VALUES (0, 'your_username', 'myapp-web', 'myapp-frontend');

Types

  • Project ~ type 0
  • Language ~ type 1
  • Editor ~ type 2
  • OS ~ type 3
  • Machine ~ type 4

🔧 API Endpoints

The following API endpoints are available. A more detailed Swagger documentation is about to come (#40).

  • POST /api/heartbeat
  • GET /api/summary
    • string parameter interval: One of today, day, week, month, year, any
  • GET /api/compat/v1/users/current/all_time_since_today (see Wakatime API docs)
  • GET /api/compat/v1/users/current/summaries (see Wakatime API docs)
  • GET /api/health

⤴️ Prometheus Export

If you want to export your Wakapi statistics to Prometheus to view them in a Grafana dashboard or so please refer to an excellent tool called wakatime_exporter.

It is a standalone webserver that connects to your Wakapi instance and exposes the data as Prometheus metrics. Although originally developed to scrape data from WakaTime, it will mostly for with Wakapi as well, as the APIs are partially compatible.

Simply configure the exporter with WAKA_SCRAPE_URI to equal "https://wakapi.your-server.com/api/compat/wakatime/v1" and set your API key accordingly.

🏷 Badges

We recently introduced support for Shields.io badges (see above). Visit your Wakapi server's settings page to see details.

👍 Best Practices

It is recommended to use wakapi behind a reverse proxy, like Caddy or nginx to enable TLS encryption (HTTPS). However, if you want to expose your wakapi instance to the public anyway, you need to set listen = 0.0.0.0 in config.ini

⚠️ Important Note

This is not an alternative to using WakaTime. It is just a custom, non-commercial, self-hosted application to collect coding statistics using the already existing editor plugins provided by the WakaTime community. It was created for personal use only and with the purpose of keeping the sovereignity of your own data. However, if you like the official product, please support the authors and buy an official WakaTime subscription!

📓 License

GPL-v3 @ Ferdinand Mütsch