Code Monkey home page Code Monkey logo

wakatime_exporter's Introduction

GitHub go.mod Go version Docker Image Size (latest by date) Docker Pulls

wakatime_exporter is a Prometheus exporter for Wakatime statistics. It intends to extend the existing Wakatime ecosystem via allowing users to make use of Prometheus (and therefore any consumers of its API) as companion services alongside the traditional Wakatime web application. This could be anything from including some of your coding statistics in Grafana, to forecasting your coding time with prophet.

NOTE: wakatime_exporter is currently in ALPHA. Expect things to break and change.

Click here to see an example of the exported metrics.

Click here for a simple dashboard you can use to get started.

Usage

In most cases, you should only need to provide an API key. All other parameters are for advanced use-cases only and you should be able to leave them set to their defaults.

You can get your Wakatime API key by visiting: https://wakatime.com/api-key

Provide arguments via parameters:

usage: wakatime_exporter --wakatime.api-key=WAKATIME.API-KEY [<flags>]

Flags:
  --help, -h                     Show context-sensitive help.
  --collector.all-time           Enable the all-time collector (default: enabled).
  --collector.goal               Enable the goal collector (default: enabled).
  --collector.leader             Enable the leader collector (default: enabled).
  --collector.summary            Enable the summary collector (default: enabled).
  --collector.disable-defaults   Set all collectors to disabled by default.
  --web.listen-address=":9212"   Address to listen on for web interface and telemetry.
  --web.metrics-path="/metrics"  Path under which to expose metrics.
  --web.disable-exporter-metrics Exclude metrics about the exporter itself (promhttp_*, process_*, go_*).
  --wakatime.scrape-uri="https://wakatime.com/api/v1"
                                 Base path to query for Wakatime data.
  --wakatime.user="current"      User to query for Wakatime data.
  --wakatime.api-key             Token to use when getting stats from Wakatime.
  --wakatime.timeout=5s          Timeout for trying to get stats from Wakatime.
  --wakatime.ssl-verify          Flag that enables SSL certificate verification for the scrape URI.
  --log.level=info               Only log messages with the given severity or above.
                                 One of: [debug, info, warn, error]
  --log.format=logfmt            Output format of log messages.
                                 One of: [logfmt, json]
  --version                      Show application version.

and/or via environment variables:

WAKA_LISTEN_ADDRESS=":9212"                   # Address to listen on for web interface and telemetry.
WAKA_METRICS_PATH="/metrics"                  # Path under which to expose metrics.
WAKA_SCRAPE_URI="https://wakatime.com/api/v1" # Base path to query for Wakatime data.
WAKA_USER="current"                           # User to query for Wakatime data.
WAKA_API_KEY=""                               # Token to use when getting stats from Wakatime.
WAKA_TIMEOUT="5s"                             # Timeout for trying to get stats from Wakatime.
WAKA_SSL_VERIFY="true"                        # SSL certificate verification for the scrape URI.
WAKA_DISABLE_EXPORTER_METRICS="false"         # Exclude metrics about the exporter itself.
WAKA_COLLECTOR_ALLTIME="true"                 # Enable the all-time collector.
WAKA_COLLECTOR_GOAL="true"                    # Enable the goal collector.
WAKA_COLLECTOR_LEADER="true"                  # Enable the leader collector.
WAKA_COLLECTOR_SUMMARY="true"                 # Enable the summary collector.

Docker

docker run -p 9212:9212 macropower/wakatime-exporter:latest --wakatime.api-key="YOUR_API_KEY"

Or use docker-compose:

# Linux & Darwin
WAKA_API_KEY="YOUR_API_KEY" docker-compose up
# Windows
$env:WAKA_API_KEY="YOUR_API_KEY"; docker-compose up

Compatibility

wakatime_exporter is designed to work with Wakatime. However, you can additionally use any other application that is compliant with the Wakatime API, e.g. wakapi, via --wakatime.scrape-uri or WAKA_SCRAPE_URI. If said application only implements portions of the Wakatime API, you can disable collectors for any non-compliant or non-existent endpoints using parameters or environment variables as described in usage.

License

This project was licensed GPL-2.0 from 0.0.0 to 0.0.5.

As of version 0.1.0, parts of this application use code from node_exporter, which is licensed APACHE 2.0.

As of version 0.1.0, this project in its entirety, excluding any packages found in vendor, is licensed APACHE 2.0. Each file in this project has a license header which identifies the copyright for said file.

wakatime_exporter's People

Contributors

macropower avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

wakatime_exporter's Issues

Goals are not working properly

I think making the assumption that Wakatime always returns a sorted array was very wrong. The goals collector is clearly retrieving stats from a historical date, rather than the current one. Thus metrics are not working properly.

Dashboard issue

If I import the dashboard, I get the following error.

Templating init failed
invalid parameter "query": 1:94: parse error: missing unit character in duration

Add support for enabling specific collectors

For compatibility with other services that might only implement portions of Wakatime's API.

e.g.

--exporter.collectors=alltime,summary

Should require at least one collector to be enabled.

Random SIGSEGV after running for ~8hr

level=info ts=2020-08-11T15:59:47.554Z caller=utils.go:73 msg="Scraping Wakatime" date=2020-08-11 path=goals
level=info ts=2020-08-11T15:59:47.554Z caller=utils.go:73 msg="Scraping Wakatime" date=2020-08-11 path=leaders
level=info ts=2020-08-11T15:59:47.554Z caller=utils.go:73 msg="Scraping Wakatime" date=2020-08-11 path=summaries
level=info ts=2020-08-11T15:59:47.554Z caller=utils.go:73 msg="Scraping Wakatime" date=2020-08-11 path=all_time_since_today
level=info ts=2020-08-11T15:59:47.729Z caller=main.go:139 msg="Collecting goals from Wakatime" total=4 pages=1
level=info ts=2020-08-11T15:59:47.840Z caller=main.go:144 msg="Collecting summary from Wakatime" obj=0 start="2020-08-11 04:00:00 +0000 UTC" end="2020-08-12 03:59:59 +0000 UTC" tz=America/New_York text=Today
level=info ts=2020-08-11T15:59:47.938Z caller=main.go:135 msg="Collecting rank from Wakatime" page=23 updated=2020-08-11T15:23:21Z
level=info ts=2020-08-11T15:59:47.942Z caller=main.go:138 msg="Collecting all time from Wakatime" IsUpToDate=true
level=info ts=2020-08-11T16:00:47.554Z caller=utils.go:73 msg="Scraping Wakatime" date=2020-08-11 path=summaries
level=info ts=2020-08-11T16:00:47.554Z caller=utils.go:73 msg="Scraping Wakatime" date=2020-08-11 path=leaders
level=info ts=2020-08-11T16:00:47.554Z caller=utils.go:73 msg="Scraping Wakatime" date=2020-08-11 path=all_time_since_today
level=info ts=2020-08-11T16:00:47.554Z caller=utils.go:73 msg="Scraping Wakatime" date=2020-08-11 path=goals
level=info ts=2020-08-11T16:00:47.818Z caller=main.go:144 msg="Collecting summary from Wakatime" obj=0 start="2020-08-11 04:00:00 +0000 UTC" end="2020-08-12 03:59:59 +0000 UTC" tz=America/New_York text=Today
level=info ts=2020-08-11T16:00:48.530Z caller=main.go:138 msg="Collecting all time from Wakatime" IsUpToDate=true
level=info ts=2020-08-11T16:00:50.299Z caller=main.go:139 msg="Collecting goals from Wakatime" total=4 pages=1
panic: runtime error: invalid memory address or nil pointer dereference

[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x8a35c1]

No data

Hello, I'm not sure it sure it's the right place but I don't succeed to have data on my grafana. In first time I tried to use my own config but I ended up using your compose but I don't have any data on the grafana. Is there something I'm missing ?
I have a self-host wakapi instance running on docker, I modified the exporter config with WAKA_SCRAPE_URI: 'http://localhost:3000/api/compat/wakatime/v1', added my own api-key and modify the exposed port for grafana to avoid port conflict, but I still don't have any data on my grafana. Do you have any idea why ? I have good data on my selfhost wakapi instance.
Thank you for your consideration

add support for braches

Wakatime already collects data related to branches for each project.

Would it be possible to add a new section in the dashboard with time spent on each branch with a projects filter that is automatically populated based on data received from Waka?

404 Errors with Wakapi

Hello,

There are some errors with the api (404 http)

Maybe is it normal ?
Here is my config

Thank's

image

image

Use "All Time Since Today"

For the total metric, switch to sourcing from the all_time_since_today endpoint. This is available for all users and means you will get some metrics pseudo-backfilled.

Add support for "Goals" metrics

https://wakatime.com/developers#goals

# HELP wakatime_goal_info Information about the goal.
# TYPE wakatime_goal_info gauge
wakatime_goal_info{id="69e0febc-923e-4f67-b347-8ed4623823f0",ignore_zero_days="1",is_enabled="1",is_inverse="0",is_snoozed="0",is_tweeting="0",name="Code 1 hr per day in Go"} 1
wakatime_goal_info{id="b642abef-14eb-47c3-ae46-d61a46efe78c",ignore_zero_days="1",is_enabled="1",is_inverse="0",is_snoozed="0",is_tweeting="0",name="Code 1 hr per day in Go, Python"} 1
wakatime_goal_info{id="c3b32c8c-8d4f-44e2-9859-2aa20737f12c",ignore_zero_days="1",is_enabled="1",is_inverse="0",is_snoozed="0",is_tweeting="0",name="Code 1 hr per day"} 1
wakatime_goal_info{id="d8640746-23e6-4553-812a-716efca86020",ignore_zero_days="1",is_enabled="1",is_inverse="0",is_snoozed="0",is_tweeting="0",name="Code 6 hrs per week"} 1
# HELP wakatime_goal_progress_seconds_total Progress towards the goal.
# TYPE wakatime_goal_progress_seconds_total counter
wakatime_goal_progress_seconds_total{delta="day",id="69e0febc-923e-4f67-b347-8ed4623823f0",name="Code 1 hr per day in Go",type="coding"} 3040.641039
wakatime_goal_progress_seconds_total{delta="day",id="b642abef-14eb-47c3-ae46-d61a46efe78c",name="Code 1 hr per day in Go, Python",type="coding"} 3040.641039
wakatime_goal_progress_seconds_total{delta="day",id="c3b32c8c-8d4f-44e2-9859-2aa20737f12c",name="Code 1 hr per day",type="coding"} 3040.641039
wakatime_goal_progress_seconds_total{delta="week",id="d8640746-23e6-4553-812a-716efca86020",name="Code 6 hrs per week",type="coding"} 69270.019606
# HELP wakatime_goal_seconds The goal.
# TYPE wakatime_goal_seconds gauge
wakatime_goal_seconds{delta="day",id="69e0febc-923e-4f67-b347-8ed4623823f0",name="Code 1 hr per day in Go",type="coding"} 3600
wakatime_goal_seconds{delta="day",id="b642abef-14eb-47c3-ae46-d61a46efe78c",name="Code 1 hr per day in Go, Python",type="coding"} 3600
wakatime_goal_seconds{delta="day",id="c3b32c8c-8d4f-44e2-9859-2aa20737f12c",name="Code 1 hr per day",type="coding"} 3600
wakatime_goal_seconds{delta="week",id="d8640746-23e6-4553-812a-716efca86020",name="Code 6 hrs per week",type="coding"} 21600

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.