Add additional statistics reporting

ulab-original
Timothy Pearson 12 years ago
parent 880b8ccbe8
commit a53204b8c9

@ -988,3 +988,49 @@ void raptor_sm_terminate_server(char* username) {
free(command_string);
}
}
void raptor_sm_stats_report_server_start(char* hostname) {
MYSQL_RES *res;
MYSQL_ROW row;
char* query;
MYSQL *conn = connect_if_needed();
if (!conn) {
return -1;
}
// Insert information into the statistics database
char* safe_servername = get_mysql_escaped_string(conn, hostname);
long long timestamp = time(NULL);
asprintf(&query, "INSERT INTO statistics (timestamp, eventtypeid, servername, display, typeid) VALUES ('%lld', '%d', '%s', '%d', '%d')", timestamp, STATISTICS_SERVER_START_EVENT, safe_servername, -1, -1);
free(safe_servername);
if (mysql_query_internal(conn, query)) {
// Server error
dprint("Unable to insert data into statistics database! [%s]\n\r", mysql_error(conn));
}
free(query);
mysql_close(conn);
}
void raptor_sm_stats_report_server_stop(char* hostname) {
MYSQL_RES *res;
MYSQL_ROW row;
char* query;
MYSQL *conn = connect_if_needed();
if (!conn) {
return -1;
}
// Insert information into the statistics database
char* safe_servername = get_mysql_escaped_string(conn, hostname);
long long timestamp = time(NULL);
asprintf(&query, "INSERT INTO statistics (timestamp, eventtypeid, servername, display, typeid) VALUES ('%lld', '%d', '%s', '%d', '%d')", timestamp, STATISTICS_SERVER_STOP_EVENT, safe_servername, -1, -1);
free(safe_servername);
if (mysql_query_internal(conn, query)) {
// Server error
dprint("Unable to insert data into statistics database! [%s]\n\r", mysql_error(conn));
}
free(query);
mysql_close(conn);
}

@ -44,4 +44,6 @@ bool raptor_sm_sesslimit_reached(char* username);
char raptor_sm_set_session_state(int display, int state);
void raptor_sm_run_remote_desktop(char* username, int display, char* executable);
void raptor_sm_terminate_server(char* username);
char* raptor_sm_get_hostname_for_display(int display);
char* raptor_sm_get_hostname_for_display(int display);
void raptor_sm_stats_report_server_start(char* hostname);
void raptor_sm_stats_report_server_stop(char* hostname);

@ -23,6 +23,9 @@
#include "xrdp.h"
#include "log.h"
#include <netdb.h>
#include "libraptorsmiface.h"
#define THREAD_WAITING 100
static struct xrdp_listen* g_listen = 0;
@ -499,6 +502,18 @@ main(int argc, char** argv)
g_file_open("/dev/null");
/* end of daemonizing code */
}
// Update statistics
char hostname[512];
gethostname(hostname, 512);
struct hostent* hostinfo;
if(hostinfo=gethostbyname(hostname)) {
raptor_sm_stats_report_server_start(hostinfo->h_name);
}
else {
raptor_sm_stats_report_server_start(hostname);
}
g_threadid = tc_get_threadid();
g_listen = xrdp_listen_create();
g_signal_user_interrupt(xrdp_shutdown); /* SIGINT */
@ -536,5 +551,13 @@ main(int argc, char** argv)
}
g_free(startup_params);
g_deinit();
if(hostinfo) {
raptor_sm_stats_report_server_stop(hostinfo->h_name);
}
else {
raptor_sm_stats_report_server_stop(hostname);
}
return 0;
}

Loading…
Cancel
Save