Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / voip / murmur_users @ 8589c6df

Historique | Voir | Annoter | Télécharger (5,26 ko)

1
#!/usr/bin/php
2
<?php
3
error_reporting( E_ALL &!E_NOTICE); //to avoid of the crap generation
4

    
5
/*///////////////////////////////////////////////////////////////////////////////////////////////////
6
/////////////////////////////////////////////////////////////////////////////////////////////////////
7
/////////////////////////////////////////////////////////////////////////////////////////////////////
8

    
9
Murmur users online grahpher
10
ver 0.2alpha 2008.12.02, 20:32 
11
author _KaszpiR_ kaszpir at gmail dot com
12
code is under GPL
13

    
14
Requirements:
15
- PHP installed in CLI (so you can run it in command line)
16
  Make sure the first line of this file points to the working php cli interpreter
17
- Murmur logfile readable by the munin user/group
18

    
19
Notice:
20
- script allows the usage of the 'config' and 'autoconf' parameters during startup, make fure you edt config section before running it
21
- $limit - number of lines to tail from the lgo file, better keep it below 5000 for lower cpu load, 
22
  additionally on busy servers you can keep it really low, suggested 3x maximum number of users online
23
- tested on 
24
	PHP 5.2.6-3 with Suhosin-Patch 0.9.6.2 (cli) (built: Aug 21 2008 17:02:32)
25
	murmur 1.1.4 precompiled binaries from sourceforge net, all running under debian etch
26
- this is not the best way to get users connected to the murmur server, maybe in the beginningn of the 2009 gonna make another script
27

    
28
Known issues and limitations:
29
- counts all users on the server not respecting different server instances
30
- if limit of 5000 log entries can sometimes be not enough on busy servers
31
- can returrn wrong number of users due to the simple user tracking (by nick, should be more advanced but I'm too lazy,)
32
  usually error is fixed after player performs any action on server like join/part channel or mute/unmute etc
33

    
34
Todo:
35
- get server id for parsing
36
- get logs from MySQL
37
- use DBUS or ICE instead of plain log file
38

    
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////*/
41
/////////////////////////////////////////////////////////////////////////////////////////////////////
42
//configuration
43
$limit=5000; //numbers of lines to process from log file
44
$logfile="/home/kaszpir/murmur/murmur.log"; // path to the murmur log file
45

    
46
//end of configuration
47
/////////////////////////////////////////////////////////////////////////////////////////////////////
48
/////////////////////////////////////////////////////////////////////////////////////////////////////
49

    
50

    
51
/////////////////////////////////////////////////////////////////////////////////////////////////////
52
/////////////////////////////////////////////////////////////////////////////////////////////////////
53
/////////////////////////////////////////////////////////////////////////////////////////////////////
54

    
55
/////////////////////////////////////////////////////////////////////////////////////////////////////
56
//autoconf test
57
if(isset($argv[1]) && $argv[1] == "autoconf")
58
{
59
	if(is_readable($logfile))
60
	{
61
		fwrite(STDOUT, "Yes\n");
62
	}
63
	else 
64
	{
65
		fwrite(STDOUT, "No\n");
66
		fwrite(STDERR, "check if '$logfile' exists and it is allowed to be read by munin user group\n");
67
	}
68
	return 0;
69
}
70

    
71
/////////////////////////////////////////////////////////////////////////////////////////////////////
72
/////////////////////////////////////////////////////////////////////////////////////////////////////
73
//config, set rrd files
74
if(isset($argv[1]) && $argv[1] == "config")
75
{
76
	if(is_readable($logfile))
77
	{
78
		fwrite(STDOUT, "graph_title Mumble Users\n");
79
		fwrite(STDOUT, "graph_vlabel Connected Users\n");
80
		fwrite(STDOUT, "graph_category VoIP\n");
81
		fwrite(STDOUT, "graph_info This graph shows the number of connected users on a murmur server\n");
82
		fwrite(STDOUT, "murmur.label Users on server\n");
83
		fwrite(STDOUT, "murmur.type GAUGE\n");
84
		return 0;
85
		
86
	}else {
87
		echo "check if '$logfile' exists and it is allowed to be read by munin user group\n";
88
		return 1;
89
	}
90
	return 0;
91
}
92

    
93
/////////////////////////////////////////////////////////////////////////////////////////////////////
94
/////////////////////////////////////////////////////////////////////////////////////////////////////
95
// do the magic
96
if(!$limit || ($limit >=5000 ) || $limit <= 0) $limit = 5000;
97
$out = shell_exec("tail -n ".$limit." \"".$logfile."\"");
98
$fp = split("\n",$out);
99
if(!count(@$fp)) {
100
	fwrite(STDOUT, "0\n");
101
	return 1;
102
	}
103
//var_dump($fp);
104
$online=0;
105
$offline=0;
106
$seen = array();
107
for($i=count($fp);$i>(count($fp)-$limit);--$i)
108
{
109
	$l = trim($fp[$i]);
110
	if(!$l) continue;
111
	list(
112
	$crap,
113
	$w,
114
	$date,
115
	$time,
116
	$serverid,
117
	$id,
118
	$nick,
119
	$id2,
120
	$msg,
121
	) = preg_split("/<(.*)>(.*) (.*) ([0-9]) => <(.*)\:(.*)\((.*)\)>(.*)/",$fp[$i],-1,PREG_SPLIT_DELIM_CAPTURE);
122
	if(!strlen(trim($nick))) continue;
123
	if(!array_key_exists($nick,$seen)){
124
	if(
125
			strpos($msg," Connection closed")!==FALSE
126
		||	strpos($msg," Tiemout")!==FALSE
127
	){
128
		$seen[$nick]['online'] = 0;		
129
		$offline+=1;
130

    
131
	}
132
	else
133
		{
134
		$seen[$nick]['online'] = 1;		
135
		$online+=1;
136
	
137
		}
138
	}
139
}
140

    
141
fwrite(STDOUT,  "murmur.value ".$online."\n");
142
//var_dump($seen);
143

    
144
return 0;
145

    
146
/////////////////////////////////////////////////////////////////////////////////////////////////////
147
/////////////////////////////////////////////////////////////////////////////////////////////////////
148
/////////////////////////////////////////////////////////////////////////////////////////////////////
149
//end of file
150
?>