equilibrium-data_monitor.c File Reference

Relating to server monitoring. More...

#include "equilibrium-data_main.h"
#include <sys/socket.h>
#include <unistd.h>
#include "equilibrium-data_config.h"
#include "equilibrium-data_conn.h"
#include "equilibrium-data_packet.h"
#include "equilibrium-data_monitor.h"

Go to the source code of this file.

Data Structures

struct  mon_server_info_s
struct  mon_app_info_s

Defines

#define LOGM(_level, _fmt...)   LOG((_level), "Server Monitor: " _fmt)

Typedefs

typedef mon_app_info_s mon_app_info_t
typedef mon_server_info_s mon_server_info_t

Functions

typedef TAILQ_HEAD (server_info_set_s, mon_server_info_s)
static void probe_server (evContext c, void *u, struct timespec d, struct timespec i)
static void stop_server_probes (mon_server_info_t *server)
static void server_probe_failed (mon_server_info_t *server)
static void http_read (evContext ctx __unused, void *uap, int fd __unused, int evmask __unused)
static void http_connect (evContext ctx __unused, void *uap, int fd, const void *la __unused, int lalen __unused, const void *ra __unused, int ralen __unused)
static void probe_timeout (evContext ctx __unused, void *uap, struct timespec due __unused, struct timespec inter __unused)
static status_t init_http_connection (mon_server_info_t *server)
static void probe_server (evContext ctx __unused, void *uap, struct timespec due __unused, struct timespec inter __unused)
static void keep_alive (evContext ctx __unused, void *uap __unused, struct timespec due __unused, struct timespec inter __unused)
static void * start_monitor (void *params __unused)
status_t init_monitor (evContext ctx, int cpu)
void shutdown_monitor (void)
void monitor_add_server (uint16_t ss_id, in_addr_t app_addr, uint16_t app_port, in_addr_t server_addr, eq_smon_t *monitor)
void monitor_remove_server (uint16_t ss_id, in_addr_t app_addr, uint16_t app_port, in_addr_t server_addr)
void monitor_remove_all_servers_in_app (uint16_t ss_id, in_addr_t app_addr, uint16_t app_port)
void monitor_remove_all_servers_in_service_set (uint16_t ss_id)
void change_monitoring_config (uint16_t ss_id, in_addr_t app_addr, uint16_t app_port, eq_smon_t *monitor)
in_addr_t monitor_get_server_for (uint16_t ss_id, in_addr_t app_addr, uint16_t app_port)
void monitor_remove_session_for_server (uint16_t ss_id, in_addr_t app_addr, uint16_t app_port, in_addr_t server_addr)
void monitor_send_stats (void)

Variables

 mon_app_key_t
static patroot apps
 patricia tree root of mon_app_info_t's
static boolean doShutdown
 flag to exit from the main event loop
static evContext mon_ctx
 monitoring context
static msp_spinlock_t apps_big_lock
 lock for whole apps config (pat tree)


Detailed Description

Relating to server monitoring.

Relating to server monitoring / probing

Definition in file equilibrium-data_monitor.c.


Define Documentation

#define LOGM ( _level,
_fmt...   )     LOG((_level), "Server Monitor: " _fmt)

Add a monitor blurb to log msgs

Definition at line 35 of file equilibrium-data_monitor.c.

Referenced by http_connect(), http_read(), init_http_connection(), probe_server(), probe_timeout(), server_probe_failed(), start_monitor(), and stop_server_probes().


Typedef Documentation

typedef struct mon_app_info_s mon_app_info_t

Forward declaration of struct mon_app_info_s

Definition at line 45 of file equilibrium-data_monitor.c.

typedef struct mon_server_info_s mon_server_info_t

An item in a server set


Function Documentation

void change_monitoring_config ( uint16_t  ss_id,
in_addr_t  app_addr,
uint16_t  app_port,
eq_smon_t monitor 
)

Change the monitoring parameters for all servers. Does not free the pointer to the old monitor.

Parameters:
[in] ss_id service-set id
[in] app_addr Application address, used to identify the application
[in] app_port Application port
[in] monitor The server monitoring parameters (all servers in the same application use the same monitor). If NULL, then server is not monitored and assumed UP.

Definition at line 1265 of file equilibrium-data_monitor.c.

References mon_server_info_s::app, mon_app_info_s::app_lock, apps, apps_big_lock, mon_app_info_s::down_servers, INSIST_ERR, LOG, mon_app_key_t, mon_ctx, probe_server(), mon_app_info_s::server_mon_params, stop_server_probes(), and mon_app_info_s::up_servers.

Referenced by update_application().

static void http_connect ( evContext ctx  __unused,
void *  uap,
int  fd,
const void *la  __unused,
int lalen  __unused,
const void *ra  __unused,
int ralen  __unused 
) [static]

Callback for when we established a connection to the server

Parameters:
[in] ctx The event context
[in] uap The user data for this callback
[in] fd The absolute time when the event is due (now)
[in] la Local address
[in] lalen Local address length
[in] ra Remote address
[in] ralen Remote address length

Definition at line 358 of file equilibrium-data_monitor.c.

References mon_server_info_s::app, mon_app_info_s::app_lock, http_read(), INSIST_ERR, LOGM, mon_ctx, mon_app_info_s::server_mon_params, and server_probe_failed().

Referenced by init_http_connection().

static void http_read ( evContext ctx  __unused,
void *  uap,
int fd  __unused,
int evmask  __unused 
) [static]

Read messages from an HTTP server sending us a response

Parameters:
[in] ctx The event context
[in] uap The user data for this callback
[in] fd The absolute time when the event is due (now)
[in] evmask The event mask

Definition at line 226 of file equilibrium-data_monitor.c.

References mon_server_info_s::app, mon_app_info_s::app_lock, eq_smon_s::connection_interval, mon_app_info_s::down_servers, INSIST_ERR, mon_server_info_s::is_up, mon_app_info_s::key, LOGM, mon_ctx, notify_server_status(), probe_server(), mon_server_info_s::server_addr, mon_app_info_s::server_mon_params, server_probe_failed(), SERVER_STATUS_UP, mon_server_info_s::sessions, mon_server_info_s::sock, stop_server_probes(), mon_server_info_s::test_timer, mon_server_info_s::timeouts, and mon_app_info_s::up_servers.

Referenced by http_connect().

static status_t init_http_connection ( mon_server_info_t server  )  [static]

Initialize an HTTP connection to the server. Should have a lock on the application of the server to use this function.

Parameters:
[in] server The server info
Returns:
SUCCESS upon successfully connecting

Definition at line 495 of file equilibrium-data_monitor.c.

References mon_server_info_s::app, mon_server_info_s::conn_id, eq_smon_s::connection_timeout, http_connect(), mon_app_info_s::key, LOGM, mon_ctx, probe_timeout(), mon_server_info_s::server_addr, mon_app_info_s::server_mon_params, mon_server_info_s::sock, and mon_server_info_s::test_timer.

Referenced by probe_server().

status_t init_monitor ( evContext  ctx,
int  cpu 
)

Init the data structures that will store configuration info

Parameters:
[in] ctx event context
[in] cpu cpu to use or MSP_NEXT_END run on current event context and cpu
Returns:
SUCCESS if successful; otherwise EFAIL with an error message.

Definition at line 704 of file equilibrium-data_monitor.c.

References apps, apps_big_lock, doShutdown, LOG, mon_app_key_t, mon_ctx, and start_monitor().

Referenced by equilibrium_init().

static void keep_alive ( evContext ctx  __unused,
void *uap  __unused,
struct timespec due  __unused,
struct timespec inter  __unused 
) [static]

Dummy keep-alive function

Parameters:
[in] ctx The event context for this application
[in] uap The user data for this callback
[in] due The absolute time when the event is due (now)
[in] inter The period; when this will next be called

Definition at line 634 of file equilibrium-data_monitor.c.

Referenced by start_monitor().

void monitor_add_server ( uint16_t  ss_id,
in_addr_t  app_addr,
uint16_t  app_port,
in_addr_t  server_addr,
eq_smon_t monitor 
)

Add a server to monitor.

Parameters:
[in] ss_id service-set id
[in] app_addr Application address, used to identify the application
[in] app_port Application port
[in] server_addr The server address, of the server within that application
[in] monitor The server monitoring parameters (all servers in the same application must have the same monitor). If NULL, then server is not monitored and assumed UP.

Definition at line 826 of file equilibrium-data_monitor.c.

References mon_server_info_s::app, mon_app_info_s::app_lock, apps, apps_big_lock, mon_app_info_s::down_servers, INSIST_ERR, mon_server_info_s::is_up, mon_app_info_s::key, LOG, mon_app_key_t, mon_ctx, mon_app_info_s::node, probe_server(), mon_server_info_s::server_addr, mon_app_info_s::server_mon_params, mon_server_info_s::sock, mon_server_info_s::test_timer, and mon_app_info_s::up_servers.

Referenced by add_server(), and update_application().

in_addr_t monitor_get_server_for ( uint16_t  ss_id,
in_addr_t  app_addr,
uint16_t  app_port 
)

Get the server with the least load for this application

Parameters:
[in] ss_id service-set id
[in] app_addr Application address, used to identify the application
[in] app_port Application port
Returns:
the server address if the application exists and has any up servers. returns 0 if the application does not exist and, (in_addr_t)-1 if there are no "up" servers but the app exists

Definition at line 1387 of file equilibrium-data_monitor.c.

References mon_server_info_s::app, mon_app_info_s::app_lock, apps, apps_big_lock, INSIST_ERR, mon_app_key_t, mon_server_info_s::server_addr, mon_server_info_s::sessions, and mon_app_info_s::up_servers.

Referenced by process_packet().

void monitor_remove_all_servers_in_app ( uint16_t  ss_id,
in_addr_t  app_addr,
uint16_t  app_port 
)

Remove all servers from the monitor's configuration matching this application

Parameters:
[in] ss_id service-set id
[in] app_addr Application address, used to identify the application
[in] app_port Application port

Definition at line 1104 of file equilibrium-data_monitor.c.

References mon_server_info_s::app, mon_app_info_s::app_lock, apps, apps_big_lock, clean_sessions_with_app(), mon_app_info_s::down_servers, INSIST_ERR, mon_app_info_s::key, LOG, mon_app_key_t, mon_app_info_s::node, stop_server_probes(), and mon_app_info_s::up_servers.

Referenced by delete_all_servers(), delete_application(), and update_application().

void monitor_remove_all_servers_in_service_set ( uint16_t  ss_id  ) 

Remove all servers from the monitor's configuration matching this service set

Parameters:
[in] ss_id service-set id

Definition at line 1177 of file equilibrium-data_monitor.c.

References mon_server_info_s::app, mon_app_info_s::app_lock, apps, apps_big_lock, clean_sessions_with_service_set(), mon_app_info_s::down_servers, INSIST_ERR, LOG, mon_app_info_s::node, stop_server_probes(), TAILQ_HEAD(), and mon_app_info_s::up_servers.

Referenced by delete_service_set().

void monitor_remove_server ( uint16_t  ss_id,
in_addr_t  app_addr,
uint16_t  app_port,
in_addr_t  server_addr 
)

Remove the server from the monitor's configuration.

Parameters:
[in] ss_id service-set id
[in] app_addr Application address, used to identify the application
[in] app_port Application port
[in] server_addr The server address, of the server within that application

Definition at line 987 of file equilibrium-data_monitor.c.

References mon_server_info_s::app, mon_app_info_s::app_lock, apps, apps_big_lock, clean_sessions_using_server(), mon_app_info_s::down_servers, INSIST_ERR, mon_app_info_s::key, LOG, mon_app_key_t, mon_app_info_s::node, mon_server_info_s::server_addr, stop_server_probes(), and mon_app_info_s::up_servers.

Referenced by delete_server().

void monitor_remove_session_for_server ( uint16_t  ss_id,
in_addr_t  app_addr,
uint16_t  app_port,
in_addr_t  server_addr 
)

Find the server in the app, and reduce the load by one

Parameters:
[in] ss_id service-set id
[in] app_addr Application address, used to identify the application
[in] app_port Application port
[in] server_addr Server address

Definition at line 1473 of file equilibrium-data_monitor.c.

References mon_server_info_s::app, mon_app_info_s::app_lock, apps, apps_big_lock, INSIST_ERR, mon_app_key_t, mon_server_info_s::server_addr, mon_server_info_s::sessions, and mon_app_info_s::up_servers.

Referenced by aging_cleanup().

void monitor_send_stats ( void   ) 

Send server/application load stats to the mgmt component

Definition at line 1548 of file equilibrium-data_monitor.c.

References mon_server_info_s::app, mon_app_info_s::app_lock, apps, apps_big_lock, INSIST_ERR, mon_app_info_s::key, mon_app_info_s::node, notify_application_sessions(), mon_server_info_s::sessions, and mon_app_info_s::up_servers.

static void probe_server ( evContext ctx  __unused,
void *  uap,
struct timespec due  __unused,
struct timespec inter  __unused 
) [static]

Probe the server

Parameters:
[in] ctx The event context for this application
[in] uap The user data for this callback
[in] due The absolute time when the event is due (now)
[in] inter The period; when this will next be called

Definition at line 580 of file equilibrium-data_monitor.c.

References mon_server_info_s::app, mon_app_info_s::app_lock, init_http_connection(), INSIST_ERR, LOGM, mon_ctx, mon_server_info_s::server_addr, mon_app_info_s::server_mon_params, server_probe_failed(), and mon_server_info_s::test_timer.

static void probe_server ( evContext  c,
void *  u,
struct timespec  d,
struct timespec  i 
) [static]

Forward declaration of function probe server

Referenced by change_monitoring_config(), http_read(), monitor_add_server(), and server_probe_failed().

static void probe_timeout ( evContext ctx  __unused,
void *  uap,
struct timespec due  __unused,
struct timespec inter  __unused 
) [static]

Timeout for the probe the server is hit

Parameters:
[in] ctx The event context for this application
[in] uap The user data for this callback
[in] due The absolute time when the event is due (now)
[in] inter The period; when this will next be called

Definition at line 450 of file equilibrium-data_monitor.c.

References mon_server_info_s::app, mon_app_info_s::app_lock, INSIST_ERR, LOGM, mon_server_info_s::server_addr, mon_app_info_s::server_mon_params, and server_probe_failed().

Referenced by init_http_connection().

static void server_probe_failed ( mon_server_info_t server  )  [static]

When a server probe timeout occurs or connection fails, set timers appropriately and move server depending on timeouts reached. Should have a lock on the application of the server to use this function.

Parameters:
[in] server The server

Definition at line 159 of file equilibrium-data_monitor.c.

References mon_server_info_s::app, clean_sessions_using_server(), mon_server_info_s::is_up, LOGM, mon_ctx, notify_server_status(), probe_server(), mon_server_info_s::server_addr, SERVER_STATUS_DOWN, mon_server_info_s::sessions, stop_server_probes(), mon_server_info_s::test_timer, and mon_server_info_s::timeouts.

Referenced by http_connect(), http_read(), probe_server(), and probe_timeout().

void shutdown_monitor ( void   ) 

Shutdown the monitor

Definition at line 764 of file equilibrium-data_monitor.c.

References mon_server_info_s::app, mon_app_info_s::app_lock, apps, apps_big_lock, doShutdown, mon_app_info_s::down_servers, INSIST_ERR, mon_app_info_s::node, stop_server_probes(), and mon_app_info_s::up_servers.

Referenced by equilibrium_quit().

static void* start_monitor ( void *params  __unused  )  [static]

Run the server monitor main loop

Parameters:
[in] params parameters passed to pthread create
Returns:
NULL

Definition at line 652 of file equilibrium-data_monitor.c.

References doShutdown, INSIST_ERR, keep_alive(), LOGM, and mon_ctx.

Referenced by init_monitor().

static void stop_server_probes ( mon_server_info_t server  )  [static]

Stop any timers and shutdown any probe socket connections to the server. Should have a lock on the application of the server to use this function.

Parameters:
[in] server The server

Definition at line 125 of file equilibrium-data_monitor.c.

References LOGM, and mon_ctx.

Referenced by change_monitoring_config(), http_read(), monitor_remove_all_servers_in_app(), monitor_remove_all_servers_in_service_set(), monitor_remove_server(), server_probe_failed(), and shutdown_monitor().

typedef TAILQ_HEAD ( server_info_set_s  ,
mon_server_info_s   
)

The key of a mon_app_info_t

< service-set id

< application address

< application port

Definition at line 68 of file equilibrium-data_monitor.c.


2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:26:56 2010 for SDK Your Net Corporation Equilibrium Load Balancer Example: equilibrium-data 1.0 by Doxygen 1.5.1