root / plugins / kamailio / kamailio_transactions_users @ 17f78427
Historique | Voir | Annoter | Télécharger (5,01 ko)
| 1 | 72e4561a | Oussama Hammami | #!/usr/bin/perl |
|---|---|---|---|
| 2 | # -*- perl -*- |
||
| 3 | |||
| 4 | =head1 NAME |
||
| 5 | |||
| 6 | Munin plugin to monitor the number of users and transactions in Kamailio using 'statistics' table. |
||
| 7 | |||
| 8 | =head1 APPLICABLE SYSTEMS |
||
| 9 | |||
| 10 | It requires MySQL 'statistics' table created in Kamailio database. |
||
| 11 | http://siremis.asipto.com/install-charts-panel/ |
||
| 12 | |||
| 13 | =head1 CONFIGURATION |
||
| 14 | |||
| 15 | [kamailio*] |
||
| 16 | user root |
||
| 17 | group root |
||
| 18 | env.mysql <optional-override-of-mysqladmin-path> |
||
| 19 | env.mysqlauth -u<User> -p<Password> |
||
| 20 | env.kamailiodb <kamailio data base> |
||
| 21 | |||
| 22 | It is most usual that root must run the mysql command. |
||
| 23 | |||
| 24 | =head2 Proxy config |
||
| 25 | |||
| 26 | use rtimer module to run periodically a route. In that route you insert the values in database. |
||
| 27 | |||
| 28 | SIP Proxy configuration file: |
||
| 29 | |||
| 30 | loadmodule "rtimer.so" |
||
| 31 | loadmodule "sqlops.so" |
||
| 32 | loadmodule "cfgutils.so" |
||
| 33 | ... |
||
| 34 | modparam("rtimer", "timer", "name=tst;interval=300;mode=1;")
|
||
| 35 | modparam("rtimer", "exec", "timer=tst;route=8")
|
||
| 36 | modparam("sqlops","sqlcon","ca=>mysql://openser:openserrw@localhost/openser")
|
||
| 37 | ... |
||
| 38 | route[8] {
|
||
| 39 | sql_query("ca",
|
||
| 40 | "insert into statistics (time_stamp,random,shm_used_size,shm_real_used_size, |
||
| 41 | shm_max_used_size,shm_free_used_size,ul_users,ul_contacts) values ($Ts, |
||
| 42 | $RANDOM,$stat(used_size),$stat(real_used_size),$stat(max_used_size), |
||
| 43 | $stat(free_size),$stat(location-users),$stat(location-contacts))","ra"); |
||
| 44 | } |
||
| 45 | |||
| 46 | Note: second parameter of sql_query(...) is a single line. Next version, based on SIP-Router.org project will support string parameters broken in multiple lines. |
||
| 47 | |||
| 48 | =head2 Database |
||
| 49 | |||
| 50 | You have to create a new table in Kamailio (OpenSER) database: |
||
| 51 | |||
| 52 | CREATE TABLE `statistics` ( |
||
| 53 | `id` int(10) unsigned NOT NULL auto_increment, |
||
| 54 | `time_stamp` int(10) unsigned NOT NULL default '0', |
||
| 55 | `random` int(10) unsigned NOT NULL default '0', |
||
| 56 | `shm_used_size` int(10) unsigned NOT NULL default '0', |
||
| 57 | `shm_real_used_size` int(10) unsigned NOT NULL default '0', |
||
| 58 | `shm_max_used_size` int(10) unsigned NOT NULL default '0', |
||
| 59 | `shm_free_used_size` int(10) unsigned NOT NULL default '0', |
||
| 60 | `ul_users` int(10) unsigned NOT NULL default '0', |
||
| 61 | `ul_contacts` int(10) unsigned NOT NULL default '0', |
||
| 62 | PRIMARY KEY (`id`) |
||
| 63 | ) ENGINE=MyISAM; |
||
| 64 | |||
| 65 | Now all is ready for Kamailio (OpenSER), you can restart it. |
||
| 66 | |||
| 67 | =head1 BUGS |
||
| 68 | |||
| 69 | None known |
||
| 70 | |||
| 71 | =head1 AUTHOR |
||
| 72 | |||
| 73 | Copyright 2012 - Voxtrot <www.voxtrot.com> |
||
| 74 | Oussama Hammami <oussamacvoxtrot.com> |
||
| 75 | |||
| 76 | =head1 LICENSE |
||
| 77 | |||
| 78 | GPLv2 |
||
| 79 | |||
| 80 | =head1 VERSION |
||
| 81 | |||
| 82 | $Id: kamailio_transactions_users 2012-04-19 16:13 $ |
||
| 83 | |||
| 84 | =head1 MAGIC MARKERS |
||
| 85 | |||
| 86 | #%# family=manual |
||
| 87 | #%# capabilities=autoconf |
||
| 88 | |||
| 89 | =cut |
||
| 90 | |||
| 91 | use strict; |
||
| 92 | |||
| 93 | my $MYSQL = $ENV{mysql} || "mysql";
|
||
| 94 | my $COMMAND = "$MYSQL $ENV{mysqlauth} $ENV{kamailiodb} -e 'select * from statistics order by id desc limit 1\\G'";
|
||
| 95 | |||
| 96 | my %WANTED = ( "ul_users" => "users", |
||
| 97 | 17f78427 | Lars Kruse | "ul_contact" => "contacts", |
| 98 | "tm_active" => "transactions", |
||
| 99 | 72e4561a | Oussama Hammami | ); |
| 100 | |||
| 101 | my %VALUE = ( "users" => 0, |
||
| 102 | "contacts" => 0, |
||
| 103 | "transactions" => 0, |
||
| 104 | ); |
||
| 105 | |||
| 106 | my $arg = shift(); |
||
| 107 | |||
| 108 | if ($arg eq 'config') {
|
||
| 109 | print_config(); |
||
| 110 | exit(); |
||
| 111 | } elsif ($arg eq 'autoconf') {
|
||
| 112 | unless (test_service() ) {
|
||
| 113 | print "yes\n"; |
||
| 114 | } else {
|
||
| 115 | print "no\n"; |
||
| 116 | } |
||
| 117 | exit 0; |
||
| 118 | } |
||
| 119 | |||
| 120 | open(SERVICE, "$COMMAND |") |
||
| 121 | or die("Could not execute '$COMMAND': $!");
|
||
| 122 | |||
| 123 | while (<SERVICE>) {
|
||
| 124 | my ($k, $v) = (m/(\w+).*?(\d+(?:\.\d+)?)/); |
||
| 125 | next unless ($k); |
||
| 126 | if (exists $WANTED{$k} ) {
|
||
| 127 | $VALUE{$WANTED{$k}}=$v;
|
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | close(SERVICE); |
||
| 132 | |||
| 133 | for my $key (keys %VALUE) {
|
||
| 134 | print ("$key.value $VALUE{$key}\n");
|
||
| 135 | } |
||
| 136 | |||
| 137 | sub print_config {
|
||
| 138 | print ("graph_title Kamailio transactions and location\n");
|
||
| 139 | # Arguments to "rrdtool graph". In this case, tell it that the |
||
| 140 | # lower limit of the graph is '0', and that 1k=1000 (not 1024). |
||
| 141 | print("graph_args --base 1000 --lower-limit 0\n");
|
||
| 142 | print("graph_vlabel user/transaction\n");
|
||
| 143 | print("graph_scale no\n");
|
||
| 144 | c4b2d9a8 | dipohl | print("graph_category voip\n");
|
| 145 | 72e4561a | Oussama Hammami | print("graph_info The graph describes the number of users/transaction on kamailio.\n");
|
| 146 | |||
| 147 | print("users.label users\n");
|
||
| 148 | print("contacts.label contacts\n");
|
||
| 149 | print("transactions.label transactions\n");
|
||
| 150 | |||
| 151 | print("users.info Average sip users for the five minutes.\n");
|
||
| 152 | print("contacts.info Average sip contacts for the five minutes.\n");
|
||
| 153 | print("transactions.info Average sip transactions for the five minutes.\n");
|
||
| 154 | |||
| 155 | print("graph_order transactions users contacts\n");
|
||
| 156 | |||
| 157 | print("users.type GAUGE\n");
|
||
| 158 | print("contacts.type GAUGE\n");
|
||
| 159 | print("transactions.type GAUGE\n");
|
||
| 160 | |||
| 161 | print("users.draw LINE1\n");
|
||
| 162 | print("contacts.draw LINE1\n");
|
||
| 163 | print("transactions.draw AREA\n");
|
||
| 164 | |||
| 165 | print("users.colour 00CCC9\n");
|
||
| 166 | print("contacts.colour 8498A0\n");
|
||
| 167 | print("transactions.colour E6D300\n");
|
||
| 168 | |||
| 169 | # Ensure min values (useful when using 'DERIVE' as 'type'). |
||
| 170 | print("users.min 0\n");
|
||
| 171 | print("contacts.min 0\n");
|
||
| 172 | print("transactions.min 0\n");
|
||
| 173 | } |
||
| 174 | |||
| 175 | |||
| 176 | sub test_service {
|
||
| 177 | system ("$MYSQL --version >/dev/null 2>/dev/null");
|
||
| 178 | if ($? == 0) |
||
| 179 | {
|
||
| 180 | system ("$COMMAND >/dev/null 2>/dev/null");
|
||
| 181 | if ($? == 0) |
||
| 182 | {
|
||
| 183 | print "yes\n"; |
||
| 184 | } |
||
| 185 | else |
||
| 186 | {
|
||
| 187 | print "no (could not connect to mysql)\n"; |
||
| 188 | } |
||
| 189 | } |
||
| 190 | else |
||
| 191 | {
|
||
| 192 | print "no (mysql not found)\n"; |
||
| 193 | } |
||
| 194 | exit 0; |
||
| 195 | } |
