Skip to content

Commit

Permalink
Merge pull request #6 from frecar/frecar/metrics
Browse files Browse the repository at this point in the history
Add simple metric docs
  • Loading branch information
frecar committed May 29, 2015
2 parents bae4fec + e1d2e4d commit 82a22ba
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Obelix Personalization Search Engine

Quickstart <quickstart>
How it works <how-it-works>

Metrics <metrics>


.. include:: quickstart.rst
Expand Down
19 changes: 19 additions & 0 deletions docs/metrics.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Metrics
==========

Introduction
------------

The metrics are produced and stored in an ObelixStore object, this may be an internal ObelixStoreImpl or Redis.
By default, this is stored in redis.

Enable metrics
------------
For metrics to be collected and stored, the --enable-metrics argument needs to be passord to the jar.

.. code-block:: bash
java -jar obelix.jar
# Enable Metrics
--enable-metrics
3 changes: 3 additions & 0 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ However, for most projects it is required to configure more options.
# Tell Obelix to rebuild all recommendations
--build-cache-for-all-users-on-startup
# Enable Metrics
--enable-metrics
Running Obelix as a Daemon (background service) on Ubuntu 14.04
--------------------------
In a production environment it is wise to run Obelix as a background service.
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void main(String... args) {
String redisQueuePrefix = "obelix:queue:";
String redisQueueName = "logentries";
String metricsSaveLocation = "obelix_metrics.json";

boolean enableMetrics = false;
int maxRelationships = 30;
int workers = 1;
int webPort = 4500;
Expand Down Expand Up @@ -67,6 +67,14 @@ public static void main(String... args) {
carg += 1;
}

carg = 0;
for (String arg : args) {
if (arg.equals("--enable-metrics")) {
enableMetrics = true;
}
carg += 1;
}

carg = 0;
for (String arg : args) {
if (arg.equals("--redis-queue-name")) {
Expand Down Expand Up @@ -169,11 +177,14 @@ public static void main(String... args) {

feedDummyData(redisQueueManager);

MetricsCollector metricsCollector =
new MetricsCollector(metricsSaveLocation, graphDb,
redisQueueManager, usersCacheQueue);
MetricsCollector metricsCollector = new MetricsCollector(
enableMetrics,
metricsSaveLocation, graphDb,
redisQueueManager, usersCacheQueue);

new Thread(metricsCollector).start();
if (enableMetrics) {
new Thread(metricsCollector).start();
}

(new Thread(new ObelixFeeder(graphDb, metricsCollector, maxRelationships,
redisQueueManager, usersCacheQueue, 1))).start();
Expand Down
25 changes: 18 additions & 7 deletions src/main/java/metrics/MetricsCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.json.JSONObject;
import org.neo4j.graphdb.GraphDatabaseService;
import queue.interfaces.ObelixQueue;
import store.impl.InternalObelixStore;
import store.impl.ObelixStoreElement;
import store.impl.RedisObelixStore;
import store.interfaces.ObelixStore;
Expand All @@ -25,17 +26,27 @@ public class MetricsCollector implements Runnable {
private Map<String, Integer> metrics = new HashMap<>();
private Map<String, Integer> totalMetrics = new HashMap<>();

public MetricsCollector(String metricsSaveLocation,
public MetricsCollector(boolean enableMetrics, String metricsSaveLocation,
GraphDatabaseService graphDb,
ObelixQueue redisQueueManager,
ObelixQueue usersCacheQueue) {

this.storage = new RedisObelixStore();
this.metricsSaveLocation = metricsSaveLocation;
this.graphDb = graphDb;
this.redisQueueManager = redisQueueManager;
this.usersCacheQueue = usersCacheQueue;
loadStoredMetrics();
if(!enableMetrics) {
this.storage = new InternalObelixStore();
this.metricsSaveLocation = metricsSaveLocation;
this.graphDb = graphDb;
this.redisQueueManager = redisQueueManager;
this.usersCacheQueue = usersCacheQueue;
}
else {

this.storage = new RedisObelixStore();
this.metricsSaveLocation = metricsSaveLocation;
this.graphDb = graphDb;
this.redisQueueManager = redisQueueManager;
this.usersCacheQueue = usersCacheQueue;
loadStoredMetrics();
}
}

private void loadStoredMetrics() {
Expand Down

0 comments on commit 82a22ba

Please sign in to comment.