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
2021-01-23 10:00:15 +11:00
.github chore: update build workflow to exclude certain directories 2020-10-04 12:08:58 +02:00
config feat: embed assets into binary 2021-01-23 10:00:15 +11:00
coverage feat: add ui for managing aliases (resolve #91) 2021-01-21 00:26:52 +01:00
data Resolve #7. 2020-03-31 11:24:44 +02:00
docs docs: advanced setup instructions for client-side reverse proxy 2020-12-11 23:05:49 +01:00
middlewares feat: ui for configuring wakatime integration 2021-01-21 23:26:50 +01:00
migrations/common test: add first few unit tests 2020-11-08 12:46:12 +01:00
mocks feat: ui for configuring wakatime integration 2021-01-21 23:26:50 +01:00
models feat: relay heartbeats to wakatime (resolve #28) 2021-01-21 22:17:32 +01:00
repositories feat: add ui for managing aliases (resolve #91) 2021-01-21 00:26:52 +01:00
routes feat: embed assets into binary 2021-01-23 10:00:15 +11:00
scripts chore: include machine name in sample data script 2021-01-21 22:17:46 +01:00
services feat: ui for configuring wakatime integration 2021-01-21 23:26:50 +01:00
static/assets feat: ability to choose number of top entities to display (resolve #81) 2021-01-05 12:41:01 +01:00
utils feat: add ui for managing aliases (resolve #91) 2021-01-21 00:26:52 +01:00
views chore: docs and typos 2021-01-22 00:02:56 +01:00
.dockerignore docker: reduce image layers 2021-01-12 21:50:20 +11:00
.gitignore feat: embed assets into binary 2021-01-23 10:00:15 +11:00
config.default.yml chore: support for cockroachdb (resolve #90) 2021-01-18 21:37:15 +01:00
doap.rdf Add DOAP description. 2020-04-05 13:36:01 +02:00
docker-compose.yml Merge branch 'notarock/62' 2020-10-26 22:34:50 +01:00
Dockerfile feat: embed assets into binary 2021-01-23 10:00:15 +11:00
go.mod feat: embed assets into binary 2021-01-23 10:00:15 +11:00
go.sum feat: embed assets into binary 2021-01-23 10:00:15 +11:00
LICENSE Add license. 2019-05-22 07:32:35 +02:00
main.go feat: embed assets into binary 2021-01-23 10:00:15 +11:00
README.md chore: docs and typos 2021-01-22 00:02:56 +01:00
sonar-project.properties chore: attempt to exclude test and mock code from analysis 2020-11-08 13:13:48 +01:00
version.txt chore: update version 2021-01-21 23:50:27 +01:00
wait-for-it.sh General cleanup and fixed PR comments 2020-10-25 22:18:33 -04:00

📈 wakapi

GitHub release (latest by date) GitHub code size in bytes Docker Cloud Build Status GitHub issues GitHub last commit Say thanks GitHub go.mod Go version Go Report Card Coding Activity Security Rating Maintainability Rating Technical Debt Lines of Code

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

Wakapi screenshot

📬 User Survey

I'd love to get some community feedback from active Wakapi users. If you like, please participate in the recent user survey. Thanks a lot!

👀 Demo

🔥 New: Wakapi is available as a hosted service now. Check out wakapi.dev. Please use responsibly.

To use the hosted version set api_url = https://wakapi.dev/api/heartbeat. However, we do not guarantee data persistence, so you might potentially lose your data if the service is taken down some day

⚙️ 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: One of the supported databases

On your local machine:

⌨️ Server Setup

Run from source

  1. Clone the project
  2. Copy config.default.yml to config.yml and adapt it to your needs
  3. Build executable: GO111MODULE=on go build
  4. 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 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 security.insecure_cookies to true in config.yml.

Run with Docker

docker run -d -p 3000:3000 -e "WAKAPI_PASSWORD_SALT=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1)" --name wakapi n1try/wakapi

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

Running tests

CGO_FLAGS="-g -O2 -Wno-return-local-addr" go test -json -coverprofile=coverage/coverage.out ./... -run ./...

🔧 Configuration

You can specify configuration options either via a config file (default: config.yml, customziable through the -c argument) or via environment variables. Here is an overview of all options.

YAML Key Environment Variable Default Description
env ENVIRONMENT dev Whether to use development- or production settings
app.custom_languages - - Map from file endings to language names
server.port WAKAPI_PORT 3000 Port to listen on
server.listen_ipv4 WAKAPI_LISTEN_IPV4 127.0.0.1 IPv4 network address to listen on (leave blank to disable IPv4)
server.listen_ipv6 WAKAPI_LISTEN_IPV6 ::1 IPv6 network address to listen on (leave blank to disable IPv6)
server.tls_cert_path WAKAPI_TLS_CERT_PATH - Path of SSL server certificate (leave blank to not use HTTPS)
server.tls_key_path WAKAPI_TLS_KEY_PATH - Path of SSL server private key (leave blank to not use HTTPS)
server.base_path WAKAPI_BASE_PATH / Web base path (change when running behind a proxy under a sub-path)
security.password_salt WAKAPI_PASSWORD_SALT - Pepper to use for password hashing
security.insecure_cookies WAKAPI_INSECURE_COOKIES false Whether or not to allow cookies over HTTP
security.cookie_max_age WAKAPI_COOKIE_MAX_AGE 172800 Lifetime of authentication cookies in seconds or 0 to use Session cookies
db.host WAKAPI_DB_HOST - Database host
db.port WAKAPI_DB_PORT - Database port
db.user WAKAPI_DB_USER - Database user
db.password WAKAPI_DB_PASSWORD - Database password
db.name WAKAPI_DB_NAME wakapi_db.db Database name
db.dialect WAKAPI_DB_TYPE sqlite3 Database type (one of sqlite3, mysql, postgres, cockroach)
db.max_conn WAKAPI_DB_MAX_CONNECTIONS 2 Maximum number of database connections
db.ssl WAKAPI_DB_SSL false Whether to use TLS encryption for database connection (Postgres and CockroachDB only)

Supported databases

Wakapi uses GORM as an ORM. As a consequence, a set of different relational databases is supported.

  • SQLite (default, easy setup)
  • MySQL (recommended, because most extensively tested)
  • MariaDB (open-source MySQL alternative)
  • Postgres (open-source as well)
  • CockroachDB (cloud-native, distributed, Postgres-compatible API)

💻 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.

Optional: Client-side proxy

See the advanced setup instructions.

Optional: WakaTime relay

You can connect Wakapi with WakaTime in a way that all heartbeats sent to Wakapi are relayed. This way, you can use both services at the same time. Go to the settings page of your instance to configure this integration.

🔧 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/wakatime/v1/users/current/all_time_since_today (see Wakatime API docs)
  • GET /api/compat/wakatime/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 server.listen_ipv4 to 0.0.0.0 in config.yml

🙏 Support

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!

⚠️ 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