Package org.altlinux.jabbix
Class AgentServer
- java.lang.Object
-
- org.altlinux.jabbix.AgentServer
-
- All Implemented Interfaces:
java.lang.Runnable
public class AgentServer extends java.lang.Object implements java.lang.Runnable
The agent server for Zabbix monitoring system. Holds the mapping between a set ofMetricAgent
objects and corresponding set of metric keys. A running agent server is a passive component of the monitoring system and is used to serve metric value queries over a network using Zabbix protocol (i.e.JabbixProtocol
).Each metric key is a textual string value that can be used in bijection with a
MetricAgent
. However, for a projection of multiple metric keys to a single MetricAgent component be also possible, the assumption is made that the '.' (dot) symbol of a key is a component separator. For a given multicomponent key the longest leftmost mapping is selected if any.The incoming requests are processed using a thread pool (i.e.
ThreadPoolExecutor
).- Author:
- Paul Wolneykien
-
-
Constructor Summary
Constructors Constructor Description AgentServer(java.util.concurrent.ThreadPoolExecutor pool)
Creates a new agent server instance with a given thread pool set to process incoming requests.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MetricAgent
getMetricAgent(java.lang.String key)
Returns a metric agent registered for a given metric key.java.util.Map<java.lang.String,MetricAgent>
getMetricAgentMap()
Returns the metric key -> metric agent map.java.util.concurrent.ThreadPoolExecutor
getPool()
Returns the thread pool being used to process incoming requests.int
getPort()
Returns a port number of a server socket.void
run()
Starts a serving cycle.void
setMetricAgentMap(java.util.Map<java.lang.String,MetricAgent> map)
Sets the metric key -> metric agent map.void
setPool(java.util.concurrent.ThreadPoolExecutor pool)
Sets the thread pool to be used to process incoming requests.void
setPort(int port)
Sets a port number for a server socket.
-
-
-
Method Detail
-
getPort
public int getPort()
Returns a port number of a server socket.- Returns:
- server socket port number
-
setPort
public void setPort(int port)
Sets a port number for a server socket. If the server is running modification of this value doesn't change the port number of the opened socket.- Parameters:
port
- port number to listen at
-
run
public void run()
Starts a serving cycle. The server waits for an incoming connection, accepts it if currentSecurityManager
doesn't prevent it, then enqueues a newJabbixRequest
task to the thread pool (seegetPool()
) and starts a new iteration.If the thread pool is built upon a blocking queue the next iteration may be blocked until some previous tasks are done.
- Specified by:
run
in interfacejava.lang.Runnable
-
getMetricAgentMap
public java.util.Map<java.lang.String,MetricAgent> getMetricAgentMap()
Returns the metric key -> metric agent map.- Returns:
- a map of (metric key, metric agent) pairs
-
setMetricAgentMap
public void setMetricAgentMap(java.util.Map<java.lang.String,MetricAgent> map)
Sets the metric key -> metric agent map.- Parameters:
map
- the map of (metric key, metric agent) pairs
-
getMetricAgent
public MetricAgent getMetricAgent(java.lang.String key)
Returns a metric agent registered for a given metric key. Each metric key is a textual string value that can be used in bijection with aMetricAgent
. However, for a projection of multiple metric keys to a single MetricAgent component be also possible, the assumption is made that the '.' (dot) symbol of a key is a component separator. For a given multicomponent key the longest leftmost mapping is selected if any.- Parameters:
key
- the name of a metric- Returns:
- a metric agent that can be used to query the metric value
-
setPool
public void setPool(java.util.concurrent.ThreadPoolExecutor pool)
Sets the thread pool to be used to process incoming requests.- Parameters:
pool
- a thread pool executor object
-
getPool
public java.util.concurrent.ThreadPoolExecutor getPool()
Returns the thread pool being used to process incoming requests.- Returns:
- a thread pool executor object
-
-