reportier 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +36 -22
- data/lib/reportier.rb +0 -1
- data/lib/reportier/defaults.rb +2 -1
- data/lib/reportier/persister.rb +7 -13
- data/lib/reportier/reporter.rb +2 -0
- data/lib/reportier/tracker.rb +1 -1
- data/lib/reportier/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2a6af84f7ba493c64deb711f1a16090b1536921
|
4
|
+
data.tar.gz: 70ab0f75ab322a914775a5410f309176ddc92c4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60c57b1a029518c684494c8142d9aacf49dad9c59fc4b8b3681e6b9987b1e5725017320f698a68f721210a71105c1b5aa34d25749a4c33f00867443c5bb54f3e
|
7
|
+
data.tar.gz: ef60218d7121948d4611fd7c2bcfd5c9bb2b92c7f7b29ae20debf13b5b4a03afd039be32e4eb2c9b2376e4305c0897a4ebd1f509763b4a5d27c653ffc6af5179
|
data/README.md
CHANGED
@@ -1,42 +1,44 @@
|
|
1
1
|
# Reportier the stat tracker
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
A tracker that tracks the count of events. Most notably (as long as you keep adding items)
|
4
|
+
it can track and report automatically on time (roughly) without the use of 3rd party software like cron.
|
5
|
+
And it has an extremely thin public interface, basically you just add items.
|
6
6
|
|
7
7
|
## Usage
|
8
8
|
|
9
9
|
`gem 'reportier'`
|
10
10
|
|
11
|
-
Use Reportier to track how
|
12
|
-
Reportier has a minimal public interface however is quite
|
11
|
+
Use Reportier to track how many times something happened in a certain amount of time.
|
12
|
+
Reportier has a minimal public interface however is quite powerful inside.
|
13
13
|
|
14
14
|
To use first configure it with intervals by setting a name and when to report
|
15
15
|
|
16
|
+
```
|
16
17
|
Reportier.configure do |c|
|
17
18
|
# Time is in seconds
|
18
19
|
c.trackers = {
|
19
|
-
|
20
|
-
|
20
|
+
daily: 60 * 60 * 24,
|
21
|
+
daily_page_visits: 60 * 60 * 24
|
21
22
|
}
|
22
23
|
end
|
24
|
+
```
|
23
25
|
|
24
26
|
Then you can add items to trackers and it will keep track of them.
|
25
27
|
|
26
28
|
```
|
27
|
-
Reportier[:
|
29
|
+
Reportier[:daily_page_visits].add "Home page visit"
|
28
30
|
# or
|
29
|
-
Reportier[:
|
31
|
+
Reportier[:daily].add @newly_registered_user # object of type User
|
30
32
|
```
|
31
33
|
|
32
34
|
Note that you can add objects and Reporiter will track their class.
|
33
|
-
You can also add the item to all trackers by doing
|
35
|
+
You can also add the item to all *registered* <sup>[1](#myfootnote1)</sup> trackers by doing
|
34
36
|
|
35
37
|
```
|
36
38
|
Reportier.add_to_all @item
|
37
39
|
```
|
38
40
|
|
39
|
-
You can
|
41
|
+
You can manually report or convert it to json.
|
40
42
|
|
41
43
|
```
|
42
44
|
Reportier[:daily].add('new user registration')
|
@@ -49,13 +51,13 @@ Reportier[:daily].to_json
|
|
49
51
|
# -> "{\"new_user_registrations\": 1}"
|
50
52
|
```
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
+
Each time an item is added the tracker will check if they have expired.
|
55
|
+
If they have they will report and reset.
|
54
56
|
|
55
|
-
##
|
57
|
+
## Persistence
|
56
58
|
|
57
59
|
Reportier saves items to memory by default however we also support long time
|
58
|
-
|
60
|
+
persistence with redis, and maybe postgres in the future.
|
59
61
|
|
60
62
|
To use redis look on setting defaults below.
|
61
63
|
|
@@ -74,7 +76,7 @@ end
|
|
74
76
|
### Reporters
|
75
77
|
|
76
78
|
By default Reportier will only report to logger and console
|
77
|
-
but we also support reporting to slack through slack-reporter
|
79
|
+
but we also support reporting to slack through slack-reporter,
|
78
80
|
and you can easily create your custom reporting methods.
|
79
81
|
|
80
82
|
```
|
@@ -82,7 +84,7 @@ Reportier.configure do |c|
|
|
82
84
|
c.reporters = { logger: 'logger', slack: 'slack-reporter' }
|
83
85
|
end
|
84
86
|
|
85
|
-
## Note you need to
|
87
|
+
## Note you need to add 'slack-reporter' to your gemfile
|
86
88
|
```
|
87
89
|
|
88
90
|
If you want to add custom reporters just add their name and library and then define a `to_#{name)` method to the `Reporter`
|
@@ -92,15 +94,15 @@ e.x.
|
|
92
94
|
Reportier.configure { |c| c.reporters = { twilio: 'twilio-ruby' } }
|
93
95
|
|
94
96
|
class Reportier::Reporter
|
95
|
-
def to_twilio
|
96
|
-
##
|
97
|
+
def to_twilio(message)
|
98
|
+
## Do something with #{message}
|
97
99
|
end
|
98
100
|
end
|
99
101
|
```
|
100
102
|
|
101
103
|
### Default reporting vars
|
102
104
|
|
103
|
-
Sometimes its
|
105
|
+
Sometimes its useful to have stats from other services or modules.
|
104
106
|
To do that you can configure reportier to have some default reporting variables
|
105
107
|
|
106
108
|
```
|
@@ -112,17 +114,29 @@ Reportier.configure do |c|
|
|
112
114
|
todays_messages: Message.where('created_at > ?', Datetime.yesterday)
|
113
115
|
}
|
114
116
|
end
|
117
|
+
```
|
115
118
|
|
116
119
|
### Full configuration
|
117
120
|
|
118
|
-
|
121
|
+
Of course you can have it all in a single configuration in the startup of your
|
119
122
|
application. A full configuration would look something like this.
|
120
123
|
|
121
124
|
```
|
122
125
|
Reportier.configure do |c|
|
123
126
|
c.persister = :redis
|
124
|
-
c.trackers = { daily: 60 * 60 * 24
|
127
|
+
c.trackers = { daily: 60 * 60 * 24 }
|
125
128
|
c.reporters = { logger: 'logger', slack: 'slack-reporter' }
|
126
129
|
c.reporting_vars = { active_users: UserRepo.active.count }
|
127
130
|
end
|
128
131
|
```
|
132
|
+
|
133
|
+
## Custom Trackers
|
134
|
+
Documentation soon
|
135
|
+
|
136
|
+
|
137
|
+
## ToDo
|
138
|
+
Documentation for custom trackers
|
139
|
+
Event driven reports
|
140
|
+
Reportier.add_to(trackers // [])
|
141
|
+
|
142
|
+
<a name="myfootnote1">1</a>: Trackers that are configured by `Reportier.configure { |c| c.trackers = ... }`
|
data/lib/reportier.rb
CHANGED
data/lib/reportier/defaults.rb
CHANGED
@@ -12,7 +12,7 @@ module Reportier
|
|
12
12
|
@reporting_vars.merge! Hash(opts[:reporting_vars])
|
13
13
|
end
|
14
14
|
|
15
|
-
def configure
|
15
|
+
def configure
|
16
16
|
yield self
|
17
17
|
end
|
18
18
|
|
@@ -30,6 +30,7 @@ module Reportier
|
|
30
30
|
_require_reporter_libraries
|
31
31
|
end
|
32
32
|
|
33
|
+
|
33
34
|
private
|
34
35
|
|
35
36
|
def initialize_defaults
|
data/lib/reportier/persister.rb
CHANGED
@@ -10,7 +10,6 @@ module Reportier
|
|
10
10
|
def initialize(tracker)
|
11
11
|
@tracker = tracker
|
12
12
|
@reporting_vars = {}
|
13
|
-
_initialize_reporting_vars
|
14
13
|
end
|
15
14
|
|
16
15
|
def save(item)
|
@@ -24,12 +23,12 @@ module Reportier
|
|
24
23
|
end
|
25
24
|
|
26
25
|
def to_json
|
27
|
-
|
26
|
+
hash = to_hash.map { |k,v| "\"#{k}\": #{v}" }.join(",\n")
|
27
|
+
"{#{hash}}"
|
28
28
|
end
|
29
29
|
|
30
30
|
def clear
|
31
31
|
@reporting_vars = {}
|
32
|
-
_initialize_reporting_vars
|
33
32
|
end
|
34
33
|
|
35
34
|
def get_date
|
@@ -40,8 +39,8 @@ module Reportier
|
|
40
39
|
@tracker.started_at = date
|
41
40
|
end
|
42
41
|
|
43
|
-
def to_hash
|
44
|
-
@reporting_vars
|
42
|
+
def to_hash(reporting_vars = @reporting_vars)
|
43
|
+
reporting_vars.merge(@tracker.defaults.reporting_vars)
|
45
44
|
end
|
46
45
|
|
47
46
|
private
|
@@ -63,26 +62,21 @@ module Reportier
|
|
63
62
|
"#{key}: #{val}\n"
|
64
63
|
end
|
65
64
|
end
|
66
|
-
|
65
|
+
|
67
66
|
def initialize_reporting_var(name)
|
68
67
|
set(name, 0)
|
69
68
|
end
|
70
|
-
|
71
|
-
def _initialize_reporting_vars
|
72
|
-
@reporting_vars.merge!(@tracker.defaults.reporting_vars)
|
73
|
-
end
|
74
69
|
end
|
75
70
|
class MemoryPersister < Persister; end
|
76
71
|
class RedisPersister < Persister
|
77
72
|
|
78
73
|
def clear
|
79
74
|
Redis.current.del(Redis.current.keys(name + '*'))
|
80
|
-
_initialize_reporting_vars
|
81
75
|
rescue Redis::CommandError
|
82
76
|
end
|
83
77
|
|
84
78
|
def to_hash
|
85
|
-
Hash[reporting_vars.map { |k| [k, get(k).to_i] }]
|
79
|
+
super(Hash[reporting_vars.map { |k| [k, get(k).to_i] }])
|
86
80
|
end
|
87
81
|
|
88
82
|
def get_date
|
@@ -115,7 +109,7 @@ module Reportier
|
|
115
109
|
def get(item)
|
116
110
|
Redis.current.get name(item)
|
117
111
|
end
|
118
|
-
|
112
|
+
|
119
113
|
def name(item=nil)
|
120
114
|
"#{@tracker.name}:#{item}"
|
121
115
|
end
|
data/lib/reportier/reporter.rb
CHANGED
data/lib/reportier/tracker.rb
CHANGED
data/lib/reportier/version.rb
CHANGED