/
statsd.module
84 lines (71 loc) · 1.73 KB
/
statsd.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* @file
* Contains helper functions and hook implementations for StatsD.
*/
use Drupal\statsd\StatsD;
/**
* Implements hook_user_login().
*/
function statsd_user_login() {
if (!\Drupal::config('statsd.settings')->get('events.user_events')) {
return;
}
statsd_call('user_events.successful_login');
}
/**
* Send failed login attempt.
*
* @param string $account
* The username of the user for whom login failed.
*/
function statsd_user_login_failed() {
if (!\Drupal::config('statsd.settings')->get('events.user_events')) {
return;
}
statsd_call('user_events.failed_login');
}
/**
* Implements hook_logger_event().
*
* @see https://drupal.org/project/logger
*/
function statsd_logger_event($name, $type, $value) {
statsd_call($name, $type, $value);
}
/**
* The generic statsd wrapper. Used for convenience.
*
* @param string $name
* Name of the value you want to track.
* @param string $type
* The type of action you want to take with the value.
* @param string $value
* The numeric value you wish to pass to statsd.
*/
function statsd_call($name, $type = 'increment', $value = NULL) {
switch ($type) {
case 'count':
StatsD::updateStats($name, $value);
break;
case 'increment':
StatsD::updateStats($name, $value ?: 1);
break;
case 'decrement':
StatsD::updateStats($name, $value ?: -1);
break;
case 'gauge':
StatsD::gauge($name, $value);
break;
case 'set':
StatsD::set($name, $value);
break;
case 'time':
case 'timing':
StatsD::timing($name, $value);
break;
default:
\Drupal::logger('statsd')->warning('Unknown method called for statsd: %type', array('%type' => $type));
break;
}
}