📊 A minimalist, self-hosted WakaTime-compatible backend for coding statistics
Go to file
Ferdinand Mütsch b9ea6530f9 fix: serve static file from local fs when on dev (fix #176) 2021-04-16 12:24:19 +02:00
.github ci: adapt go version in github build action 2021-04-13 10:34:35 +02:00
config fix: serve static file from local fs when on dev (fix #176) 2021-04-16 12:24:19 +02:00
coverage fix: make range picker show actual range with ceiled to date (fix #175) 2021-04-16 11:53:37 +02:00
data ref: embed files, bump to go 1.16 (#167) 2021-04-11 10:42:43 +00:00
middlewares chore: write authenticated user to logs and sentry 2021-03-26 13:10:10 +01:00
migrations fix: table drop in migration 2021-04-12 22:58:40 +02:00
mocks fix: adapt tests 2021-04-05 23:00:21 +02:00
models fix: make range picker show actual range with ceiled to date (fix #175) 2021-04-16 11:53:37 +02:00
postman chore: include postman collection (resolve #148) [ci-skip] 2021-03-25 15:50:47 +01:00
repositories feat: smtp mail provider implementation 2021-04-10 00:07:13 +02:00
routes fix: serve static file from local fs when on dev (fix #176) 2021-04-16 12:24:19 +02:00
scripts fix: precedence in case of multiple matching language mappings (fix #172) 2021-04-13 23:39:31 +02:00
services fix: missing summary aggregation after days without heartbeats (see #168) 2021-04-12 23:36:22 +02:00
static chore: add contribute.json (resolve #170) 2021-04-13 23:49:54 +02:00
utils fix: make range picker show actual range with ceiled to date (fix #175) 2021-04-16 11:53:37 +02:00
views fix: make range picker show actual range with ceiled to date (fix #175) 2021-04-16 11:53:37 +02:00
.dockerignore docker: reduce image layers 2021-01-12 21:50:20 +11:00
.gitignore chore: remove legacy config.ini and .env 2021-01-31 10:51:56 +11:00
Dockerfile ref: embed files, bump to go 1.16 (#167) 2021-04-11 10:42:43 +00:00
LICENSE Add license. 2019-05-22 07:32:35 +02:00
README.md ref: embed files, bump to go 1.16 (#167) 2021-04-11 10:42:43 +00:00
config.default.yml feat: smtp mail provider implementation 2021-04-10 00:07:13 +02:00
doap.rdf Add DOAP description. 2020-04-05 13:36:01 +02:00
docker-compose.yml ref: embed files, bump to go 1.16 (#167) 2021-04-11 10:42:43 +00:00
entrypoint.sh ci: make docker container wait properly for database to come up 2021-02-06 10:43:32 +01:00
go.mod ref: embed files, bump to go 1.16 (#167) 2021-04-11 10:42:43 +00:00
go.sum ref: embed files, bump to go 1.16 (#167) 2021-04-11 10:42:43 +00:00
main.go fix: serve static file from local fs when on dev (fix #176) 2021-04-16 12:24:19 +02:00
sonar-project.properties chore: exclude static assets from sonarqube [ci skip] 2021-03-24 23:38:38 +01:00
tailwind.config.js chore: purge tailwind classes (resolve #22) 2021-02-21 11:14:55 +01:00
version.txt chore: add contribute.json (resolve #170) 2021-04-13 23:49:54 +02:00

README.md

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

Table of Contents

Further instructions can be found in the Wiki.

📬 User Survey

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

🚀 Features

  • 100 % free and open-source
  • Built by developers for developers
  • Statistics for projects, languages, editors, hosts and operating systems
  • Badges
  • REST API
  • Partially compatible with WakaTime
  • WakaTime integration
  • Support for Prometheus exports
  • Lightning fast
  • Self-hosted

🚧 Roadmap

Plans for the near future mainly include, besides usual improvements and bug fixes, a UI redesign as well as additional types of charts and statistics (see #101, #80, #76, #12). If you have feature requests or any kind of improvement proposals feel free to open an issue or share them in our user survey.

⌨️ How to use?

There are different options for how to use Wakapi, ranging from our hosted cloud service to self-hosting it. Regardless of which option choose, you will always have to do the client setup in addition.

☁️ Option 1: Use wakapi.dev

If you want to you out free, hosted cloud service, all you need to do is create an account and the set up your client-side tooling (see below).

However, we do not guarantee data persistence, so you might potentially lose your data if the service is taken down some day

🐳 Option 2: Use Docker

# Create a persistent volume
$ docker volume create wakapi-data

# Run the container
$ 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)" \
  -v wakapi-data:/data \
  --name wakapi n1try/wakapi

Note: 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.

If you want to run Wakapi on Kubernetes, there is wakapi-helm-chart for quick and easy deployment.

📦 Option 3: Run a release

# Download the release and unpack it
$ wget https://github.com/muety/wakapi/releases/download/1.20.2/wakapi_linux_amd64.zip
$ unzip wakapi_linux_amd64.zip

# Optionally adapt config to your needs
$ vi config.yml

# Run it
$ ./wakapi

🧑‍💻 Option 4: Run from source

Prerequisites

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

Compile & Run

# Adapt config to your needs
$ cp config.default.yml config.yml
$ vi config.yml

# Build the executable
$ go build -o wakapi

# Run it
$ ./wakapi

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 = true in config.yml.

💻 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. Editing your local ~/.wakatime.cfg file as follows
[settings]

# Your Wakapi server URL or 'https://wakapi.dev/api/heartbeat' when using the cloud server
api_url = http://localhost:3000/api/heartbeat

# Your Wakapi API key (get it from the web interface after having created an account)
api_key = 406fe41f-6d69-4183-a4cc-121e0c524c2b

Optionally, you can set up a client-side proxy in addition.

🔧 Configuration Options

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
security.allow_signup WAKAPI_ALLOW_SIGNUP true Whether to enable user registration
security.expose_metrics WAKAPI_EXPOSE_METRICS false Whether to expose Prometheus metrics under /api/metrics
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.charset WAKAPI_DB_CHARSET utf8mb4 Database connection charset (for MySQL only)
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)
mail.enabled WAKAPI_MAIL_ENABLED true Whether to allow Wakapi to send e-mail (e.g. for password resets)
mail.provider WAKAPI_MAIL_PROVIDER smtp Implementation to use for sending mails (one of [smtp, mailwhale])
mail.smtp.* WAKAPI_MAIL_SMTP_* - Various options to configure SMTP. See default config for details
mail.mailwhale.* WAKAPI_MAIL_MAILWHALE_* - Various options to configure MailWhale sending service. See default config for details
sentry.dsn WAKAPI_SENTRY_DSN DSN for to integrate Sentry for error logging and tracing (leave empty to disable)
sentry.enable_tracing WAKAPI_SENTRY_TRACING false Whether to enable Sentry request tracing
sentry.sample_rate WAKAPI_SENTRY_SAMPLE_RATE 0.75 Probability of tracing a request in Sentry
sentry.sample_rate_heartbats WAKAPI_SENTRY_SAMPLE_RATE_HEARTBEATS 0.1 Probability of tracing a heartbeats request in Sentry

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-side proxy (optional)

See the advanced setup instructions.

🔧 API Endpoints

See our Swagger API Documentation.

Generating Swagger docs

$ go get -u github.com/swaggo/swag/cmd/swag
$ swag init -o static/docs

🤝 Integrations

Prometheus Export

You can export your Wakapi statistics to Prometheus to view them in a Grafana dashboard or so. Here is how.

# 1. Start Wakapi with the feature enabled
$ export WAKAPI_EXPOSE_METRICS=true
$ ./wakapi

# 2. Get your API key and hash it
$ echo "<YOUR_API_KEY>" | base64

# 3. Add a Prometheus scrape config to your prometheus.yml (see below)

Scrape config example

# prometheus.yml
# (assuming your Wakapi instance listens at localhost, port 3000)

scrape_configs:
  - job_name: 'wakapi'
    scrape_interval: 1m
    metrics_path: '/api/metrics'
    bearer_token: '<YOUR_BASE64_HASHED_TOKEN>'
    static_configs:
      - targets: ['localhost:3000']

Grafana

There is also a nice Grafana dashboard, provided by the author of wakatime_exporter.

WakaTime Integration

Wakapi plays well together with WakaTime. For one thing, you can forward heartbeats from Wakapi to WakaTime to effectively use both services simultaneously. In addition, there is the option to import historic data from WakaTime for consistency between both services. Both features can be enabled in the Integrations section of your Wakapi instance's settings page.

GitHub Readme Stats Integrations

Wakapi also integrates with GitHub Readme Stats to generate fancy cards for you. Here is an example.

👍 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

🤓 Developer Notes

Running tests

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

Building Tailwind

To keep things minimal, Wakapi does not contain a package.json, node_modules or any sort of frontend build step. Instead, all JS and CSS assets are included as static files and checked in to Git. This way we can avoid requiring NodeJS to build Wakapi. However, for TailwindCSS it makes sense to run it through a "build" step to benefit from purging and significantly reduce it in size. To only require this at the time of development, the compiled asset is checked in to Git as well.

$ tailwindcss-cli build static/assets/vendor/tailwind.css -o static/assets/vendor/tailwind.dist.css

🙏 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!

FAQs

Since Wakapi heavily relies on the concepts provided by WakaTime, their FAQs apply to Wakapi for large parts as well. You might find answers there.

What data is sent to Wakapi?
  • File names
  • Project names
  • Editor names
  • You computer's host name
  • Timestamps for every action you take in your editor
  • ...

See the related WakaTime FAQ section for details.

If you host Wakapi yourself, you have control over all your data. However, if you use our webservice and are concerned about privacy, you can also exclude or obfuscate certain file- or project names.

What happens if I'm offline?

All data is cached locally on your machine and sent in batches once you're online again.

How did Wakapi come about?

Wakapi was started when I was a student, who wanted to track detailed statistics about my coding time. Although I'm a big fan of WakaTime I didn't want to pay 9 $ a month back then. Luckily, most parts of WakaTime are open source!

How does Wakapi compare to WakaTime?

Wakapi is a small subset of WakaTime and has a lot less features. Cool WakaTime features, that are missing Wakapi, include:

  • Leaderboards
  • Embeddable Charts
  • Personal Goals
  • Team- / Organization Support
  • Integrations (with GitLab, etc.)
  • Richer API

WakaTime is worth the price. However, if you only want basic statistics and keep sovereignty over your data, you might want to go with Wakapi.

How are durations calculated?

Inferring a measure for your coding time from heartbeats works a bit different than in WakaTime. While WakaTime has timeout intervals, Wakapi essentially just pads every heartbeat, that occurs after a longer pause, with 2 extra minutes.

Here is an example (circles are heartbeats):

|---o---o--------------o---o---|
|   |10s|      3m      |10s|   |

It is unclear how to handle the three minutes in between. Did the developer do a 3-minute break or were just no heartbeats being sent, e.g. because the developer was starring at the screen find a solution, but not actually typing code.

  • WakaTime (with 5 min timeout): 3 min 20 sec
  • WakaTime (with 2 min timeout): 20 sec
  • Wakapi: 10 sec + 2 min + 10 sec = 2 min 20 sec

Wakapi adds a "padding" of two minutes before the third heartbeat. This is why total times will slightly vary between Wakapi and WakaTime.

🙏 Thanks

I highly appreciate the efforts of @alanhamlett and the WakaTime team and am thankful for their software being open source.

📓 License

GPL-v3 @ Ferdinand Mütsch