reportier 0.5.6 → 0.6.0
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 +85 -40
- data/lib/reportier.rb +5 -1
- data/lib/reportier/defaults.rb +6 -6
- data/lib/reportier/tracker.rb +3 -3
- 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: 370f511dd07462a7eee6dbabe9ed0b69a1ad3871
|
4
|
+
data.tar.gz: 7663e4fb47322832da7aa8cd42234200a5fe093c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0281eecb8827893f544d8e32bb0c833c7224b360932fa9fe1585abb3ea728eff8824b8d22e183a2885e2c2e77d48bfe1e8fe223076a692671c5034290728cc19
|
7
|
+
data.tar.gz: 0e90955b777f0d2bb6c8a923126150f1506b04c74b6cc4c8c8290661cc6b2fedd695341f1a76b9b975c7e73682e5574ee331bb94f20929e4c33b9e769f2f4199
|
data/README.md
CHANGED
@@ -1,75 +1,95 @@
|
|
1
1
|
# Reportier the stat tracker
|
2
2
|
|
3
|
-
This is a tracker that tracks the count of events.
|
3
|
+
This is a tracker that tracks the count of events. Most notable is that
|
4
|
+
as long as you keep addng items reportier will report automatically
|
5
|
+
without using 3rd party software like cron.
|
6
|
+
|
7
|
+
## Usage
|
4
8
|
|
5
|
-
## Use
|
6
9
|
`gem 'reportier'`
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
To add something to a tracker simply `.get` it and `#add` something.
|
11
|
+
Use Reportier to track how manny times something happened in a certain ammount of time.
|
12
|
+
Reportier has a minimal public interface however is quite powerfull inside.
|
11
13
|
|
12
|
-
|
13
|
-
as long as you keep adding items to them.
|
14
|
+
To use first configure it with intervals by setting a name and when to report
|
14
15
|
|
15
|
-
|
16
|
+
Reportier.configure do |c|
|
17
|
+
# Time is in seconds
|
18
|
+
c.trackers = {
|
19
|
+
hourly: 60 * 60,
|
20
|
+
bidaily: 60 * 60 * 24 * 2
|
21
|
+
}
|
22
|
+
end
|
16
23
|
|
17
|
-
|
18
|
-
Reportier::Tracker[:daily].add('new user registration')
|
24
|
+
Then you can add items to trackers and it will keep track of them.
|
19
25
|
|
20
|
-
|
21
|
-
|
22
|
-
#
|
26
|
+
```
|
27
|
+
Reportier[:hourly].add "Home page visit"
|
28
|
+
# or
|
29
|
+
Reportier[:bidaily].add @newly_registered_user # object of type User
|
23
30
|
```
|
24
31
|
|
25
|
-
|
26
|
-
|
27
|
-
nothing else.
|
32
|
+
Note that you can add objects and Reporiter will track their class.
|
33
|
+
You can also add the item to all trackers by doing
|
28
34
|
|
29
|
-
|
35
|
+
```
|
36
|
+
Reportier.add_to_all @item
|
37
|
+
```
|
30
38
|
|
39
|
+
You can make the tracker report or convert it to json.
|
31
40
|
|
32
|
-
|
41
|
+
```
|
42
|
+
Reportier[:daily].add('new user registration')
|
33
43
|
|
34
|
-
Reportier
|
44
|
+
Reportier[:daily].report
|
45
|
+
# -> Daily report started at 2016-06-17T15:34:40+03:00
|
46
|
+
# new_user_registrations: 1
|
35
47
|
|
36
|
-
|
48
|
+
Reportier[:daily].to_json
|
49
|
+
# -> "{\"new_user_registrations\": 1}"
|
50
|
+
```
|
37
51
|
|
38
|
-
|
52
|
+
Tracker check if they have expired everytime an item is added.
|
53
|
+
And they will reset and report when they realise that they
|
39
54
|
|
40
|
-
|
41
|
-
Reportier.set_default_reporting_vars active_users: User.active, open_conversations: Conversation.all.count
|
42
|
-
```
|
55
|
+
## Persistance
|
43
56
|
|
44
|
-
|
57
|
+
Reportier saves items to memory by default however we also support long time
|
58
|
+
persistance with redis, and maybe postgres in the future.
|
45
59
|
|
46
|
-
|
47
|
-
So the usage would be
|
60
|
+
To use redis look on setting defaults below.
|
48
61
|
|
62
|
+
## Setting defaults
|
63
|
+
|
64
|
+
### Persister
|
65
|
+
Right now we only support memory and redis.
|
66
|
+
Select peristance like so.
|
49
67
|
|
50
68
|
```
|
51
|
-
Reportier.
|
69
|
+
Reportier.configure do |c|
|
70
|
+
c.persister = :redis
|
71
|
+
end
|
52
72
|
```
|
53
73
|
|
54
|
-
|
55
|
-
also `Reportier.add_to_all` will take this new classes in account.
|
56
|
-
Note that if you don't use Rails you can `import` or `extend` `Reportier::Time` to you current environment
|
57
|
-
and use `hours(1)`, `days(1)`, `weeks(1)`, `months(1)`, `years(1)`, years and months are not exact.
|
74
|
+
### Reporters
|
58
75
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
but we also support reporting to slack and logger, and you can easily create your custom reporting methods.
|
76
|
+
By default Reportier will only report to logger and console
|
77
|
+
but we also support reporting to slack through slack-reporter and to logger,
|
78
|
+
and you can easily create your custom reporting methods.
|
63
79
|
|
64
80
|
```
|
65
|
-
Reportier.
|
81
|
+
Reportier.configure do |c|
|
82
|
+
c.reporters = { logger: 'logger', slack: 'slack-reporter' }
|
83
|
+
end
|
84
|
+
|
85
|
+
## Note you need to ass 'slack-reporter' to your gemfile
|
66
86
|
```
|
67
87
|
|
68
88
|
If you want to add custom reporters just add their name and library and then define a `to_#{name)` method to the `Reporter`
|
69
89
|
e.x.
|
70
90
|
|
71
91
|
```
|
72
|
-
Reportier.
|
92
|
+
Reportier.configure { |c| c.reporters = { twilio: 'twilio-ruby' } }
|
73
93
|
|
74
94
|
class Reportier::Reporter
|
75
95
|
def to_twilio
|
@@ -78,6 +98,31 @@ class Reportier::Reporter
|
|
78
98
|
end
|
79
99
|
```
|
80
100
|
|
81
|
-
###
|
101
|
+
### Default reporting vars
|
102
|
+
|
103
|
+
Sometimes its usefull no have stats from other services or modules.
|
104
|
+
To do that you can configure reportier to have some default reporting variables
|
82
105
|
|
83
|
-
|
106
|
+
```
|
107
|
+
Reportier.configure do |c|
|
108
|
+
# For adding reporting vars
|
109
|
+
c.reporting_vars = { active_users: UserRepo.active.count }
|
110
|
+
# For updating existing reporting vars
|
111
|
+
c.update_reporting_vars {
|
112
|
+
todays_messages: Message.where('created_at > ?', Datetime.yesterday)
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
### Full configuration
|
117
|
+
|
118
|
+
Ofcourse you can you all this in a single configuration in the startup of your
|
119
|
+
application. A full configuration would look something like this.
|
120
|
+
|
121
|
+
```
|
122
|
+
Reportier.configure do |c|
|
123
|
+
c.persister = :redis
|
124
|
+
c.trackers = { daily: 60 * 60 * 24
|
125
|
+
c.reporters = { logger: 'logger', slack: 'slack-reporter' }
|
126
|
+
c.reporting_vars = { active_users: UserRepo.active.count }
|
127
|
+
end
|
128
|
+
```
|
data/lib/reportier.rb
CHANGED
@@ -9,11 +9,15 @@ require_relative 'reportier/version'
|
|
9
9
|
|
10
10
|
module Reportier
|
11
11
|
def self.add_to_all(item)
|
12
|
-
Defaults.global.
|
12
|
+
Defaults.global.trackers.each do |type, v|
|
13
13
|
Tracker[type].add(item)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
def self.[](type)
|
18
|
+
Tracker[type]
|
19
|
+
end
|
20
|
+
|
17
21
|
def self.configure(&blk)
|
18
22
|
Defaults.global.configure &blk
|
19
23
|
end
|
data/lib/reportier/defaults.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Reportier
|
2
2
|
class Defaults
|
3
|
-
attr_accessor :
|
3
|
+
attr_accessor :trackers, :reporting_vars, :reporters,
|
4
4
|
:persister
|
5
5
|
|
6
6
|
def self.global
|
@@ -20,9 +20,9 @@ module Reportier
|
|
20
20
|
@reporting_vars.merge!(hash)
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
@
|
25
|
-
@
|
23
|
+
def trackers=(opts)
|
24
|
+
@trackers = Hash.new(0)
|
25
|
+
@trackers.merge! opts
|
26
26
|
end
|
27
27
|
|
28
28
|
def reporters=(opts)
|
@@ -33,9 +33,9 @@ module Reportier
|
|
33
33
|
private
|
34
34
|
|
35
35
|
def initialize_defaults
|
36
|
-
@
|
36
|
+
@trackers = Hash.new(0)
|
37
37
|
@reporting_vars = Hash.new
|
38
|
-
@reporters =
|
38
|
+
@reporters = { console: nil, logger: 'logger' }
|
39
39
|
@persister = :memory
|
40
40
|
end
|
41
41
|
|
data/lib/reportier/tracker.rb
CHANGED
@@ -21,7 +21,7 @@ module Reportier
|
|
21
21
|
|
22
22
|
def add(item)
|
23
23
|
(report && clear) unless active?
|
24
|
-
return if Defaults.global.
|
24
|
+
return if Defaults.global.trackers[@type] == 0
|
25
25
|
@persister.save(Namer.new.name_item(item))
|
26
26
|
end
|
27
27
|
|
@@ -52,7 +52,7 @@ module Reportier
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def expires_at
|
55
|
-
get_date + Defaults.global.
|
55
|
+
get_date + Defaults.global.trackers[@type]
|
56
56
|
end
|
57
57
|
|
58
58
|
def get_date
|
@@ -71,7 +71,7 @@ module Reportier
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def _long_due?
|
74
|
-
expires_at < (DateTime.now - Defaults.global.
|
74
|
+
expires_at < (DateTime.now - Defaults.global.trackers[@type])
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
data/lib/reportier/version.rb
CHANGED