Store and access data published by OwnTracks apps
Go to file
2015-08-29 15:03:56 +02:00
wdocs feature: HTTP in recorder! 2015-08-27 23:42:18 +02:00
.gitignore add binary 2015-08-29 15:01:30 +02:00
base64.c Initial import 2015-08-14 18:40:35 +02:00
base64.h Initial import 2015-08-14 18:40:35 +02:00
config.h.example ocat: [NEW] $OCAT_STORAGEDIR or --storage (defaults to ./store) 2015-08-25 20:22:50 +02:00
config.mk feature: HTTP in recorder! 2015-08-27 23:42:18 +02:00
file.c moved yyyymm() to utils 2015-08-29 15:00:24 +02:00
file.h Initial import 2015-08-14 18:40:35 +02:00
geo.c correctly handle all revgeocoding errors 2015-08-16 12:49:51 +02:00
geo.h Initial import 2015-08-14 18:40:35 +02:00
geohash.c Initial import 2015-08-14 18:40:35 +02:00
geohash.h Initial import 2015-08-14 18:40:35 +02:00
ghash.c Do not store ghash in ghash file! 2015-08-25 18:51:41 +02:00
ghash.h protect 2015-08-22 13:59:55 +02:00
ghashfind.c feature: ghashfind (WiP) 2015-08-27 22:52:58 +02:00
http.c split out HTTP functions 2015-08-29 15:03:56 +02:00
http.h split out HTTP functions 2015-08-29 15:03:56 +02:00
jget.h Initial import 2015-08-14 18:40:35 +02:00
json.c Initial import 2015-08-14 18:40:35 +02:00
json.h Initial import 2015-08-14 18:40:35 +02:00
LICENSE feature: HTTP in recorder! 2015-08-27 23:42:18 +02:00
Makefile feature: HTTP in recorder! 2015-08-27 23:42:18 +02:00
misc.c s/JSONDIR/STORAGEDIR/g 2015-08-19 18:58:12 +02:00
misc.h ocat: [NEW] $OCAT_STORAGEDIR or --storage (defaults to ./store) 2015-08-25 20:22:50 +02:00
mkpath.c Initial import 2015-08-14 18:40:35 +02:00
mongoose.c upgrade to latest version 2015-08-29 15:00:55 +02:00
mongoose.h feature: HTTP in recorder! 2015-08-27 23:42:18 +02:00
ocat.c ocat: dist and trip are also "integer" 2015-08-26 22:31:18 +02:00
ot-recorder.c feature: HTTP in recorder! 2015-08-27 23:42:18 +02:00
README.md ocat: [NEW] $OCAT_STORAGEDIR or --storage (defaults to ./store) 2015-08-25 20:22:50 +02:00
safewrite.c Initial import 2015-08-14 18:40:35 +02:00
safewrite.h use safewrite() for monitor hook file so that it cannot disappear temporarily 2015-08-15 16:27:19 +02:00
storage.c ocat: [NEW] $OCAT_STORAGEDIR or --storage (defaults to ./store) 2015-08-25 20:22:50 +02:00
storage.h Feature: ocat userlist (incomplete!) 2015-08-25 18:01:50 +02:00
TODO.md rm card in TODO 2015-08-23 15:05:33 +02:00
udata.h feature: HTTP in recorder! 2015-08-27 23:42:18 +02:00
utarray.h Initial import 2015-08-14 18:40:35 +02:00
util.c Implemented tac() 2015-08-29 14:59:46 +02:00
util.h Implemented tac() 2015-08-29 14:59:46 +02:00
utstring.h Initial import 2015-08-14 18:40:35 +02:00

recorder

Recorder

Design decisions

We took a number of decisions for the design of the recorder and its utilities:

  • Flat files. The filesystem is the database. Period. That's were everything is stored. It makes incremental backups, purging old data, manipulation via the Unix toolset easy. (Admittedly, for fast lookups you can employ Redis as a cache, but the final word is in the filesystem.) We considered all manner of databases and decided to keep this as simple and lightweight as possible.
  • Storage format is typically JSON because it's extensible. If we add an attribute to the JSON published by our apps, you have it right there. There's one slight exception: the monthly logs have a leading timestamp and a relative topic; see below.
  • File names are lower case. A user called JaNe with a device named myPHONe will be found in a file named jane/myphone.
  • All times are UTC (a.k.a. Zulu or GMT). We got sick and tired of converting stuff back and forth. It is up to the consumer of the data to convert to localtime if need be.
  • ocat, the cat program for the recorder uses the same back-end which is used by the API though it accesses it directly (i.e. without resorting to HTTP).

Storage

As mentioned earlier, data is stored in files, and these files are relative to STORAGEDIR (compiled into the programs or specified as an option). In particular, the following directory structure can exist, whereby directories are created as needed by the recorder:

  • cards/, optional, contain user cards.
  • ghash/, unless disabled, reverse Geo data is collected in files named after the geohash in directories named with the first three characters of the geohash.
  • last/ contains the last location publish from a device. E.g. Jane's last publish from her iPhone would be in last/jjolie/iphone/jjolie-iphone.json.
  • monitor a file which contains a timestamp and the last received topic (see Monitoring below).
  • msg/ contains messages received by the Messaging system.
  • photos/ optional; contains the binary photos from a card.
  • rec/ the recorder data proper. One subdirectory per user, one subdirectory therein per device. Data files are named YYYY-MM.rec (e.g. 2015-08.rec for the data accumulated during the month of August 2015.

Requirements

  • hiredis unless HAVE_REDIS is false.

Installation

  1. Copy config.h.example to config.h
  2. Edit config.h
  3. Edit config.mk and select features
  4. Type make

Reverse Geo

If not disabled with option -G, the recorder will attempt to perform a reverse-geo lookup on the location coordinates it obtains. This is stored in Redis (ghash:xxx) if available or in files. If a lookup is not possible, for example because you're over quota, the service isn't available, etc., recorder keeps tracks of the coordinates which could not be resolved in a missing file:

$ cat store/ghash/missing
u0tfsr3 48.292223 8.274535
u0m97hc 46.652733 7.868803
...

This can be used to subsequently obtain said geo lookups.

Monitoring

In order to monitor the recorder, whenever an MQTT message is received, the recorder will add an epoch timestamp and the last received topic a Redis key (if configured) or a file otherwise. The Redis key looks like this:

redis 127.0.0.1:6379> hgetall ot-recorder-monitor
1) "time"
2) "1439738692"
3) "topic"
4) "owntracks/jjolie/ipad"

The monitor file is located relative to STORE and contains a single line, the epoch timestamp at the moment of message reception and the topic separated from eachother by a single space:

1439738692 owntracks/jjolie/ipad

ocat

ocat is a CLI driver for recorder: it prints data stored by the recorder in a variety of output formats.

Environment

The following environment variables control ocat's behaviour:

  • OCAT_FORMAT can be set to the preferred output format. If unset, JSON is used. The --format option overrides this setting.
  • OCAT_USERNAME can be set to the preferred username. The --user option overrides this environment variable.
  • OCAT_DEVICE can be set to the preferred device name. The --device option overrides this environment variable.