MetricsMsg¶
Usage
use MetricsMsg;
or
import MetricsMsg;
- enum MetricCategory { ALL, NUM_REQUESTS, RESPONSE_TIME, AVG_RESPONSE_TIME, TOTAL_RESPONSE_TIME, TOTAL_MEMORY_USED, SYSTEM, SERVER, SERVER_INFO, NUM_ERRORS }¶
- enum constant ALL¶
- enum constant NUM_REQUESTS¶
- enum constant RESPONSE_TIME¶
- enum constant AVG_RESPONSE_TIME¶
- enum constant TOTAL_RESPONSE_TIME¶
- enum constant TOTAL_MEMORY_USED¶
- enum constant SYSTEM¶
- enum constant SERVER¶
- enum constant SERVER_INFO¶
- enum constant NUM_ERRORS¶
- enum MetricScope { GLOBAL, LOCALE, REQUEST, USER }¶
- enum constant GLOBAL¶
- enum constant LOCALE¶
- enum constant REQUEST¶
- enum constant USER¶
- const mLogger = new Logger(logLevel, logChannel)¶
- var metricScope = try! ServerConfig.getEnv(name = "METRIC_SCOPE", default = "MetricScope.REQUEST")¶
- var serverMetrics = new CounterTable()¶
- var requestMetrics = new CounterTable()¶
- var avgResponseTimeMetrics = new AverageMeasurementTable()¶
- var responseTimeMetrics = new MeasurementTable()¶
- var totalResponseTimeMetrics = new MeasurementTable()¶
- var totalMemoryUsedMetrics = new MeasurementTable()¶
- var users = new Users()¶
- var userMetrics = new UserMetrics()¶
- var errorMetrics = new CounterTable()¶
- class Users¶
- var users = new map(string, User)¶
- proc getUser(name: string)¶
- proc getUserNames()¶
- proc getUsers()¶
- class MetricValue¶
- var realValue : real¶
- var intValue : int(64)¶
- var dataType : MetricDataType¶
- proc init(realValue: real)¶
- proc init(intValue: int(64))
- proc update(val)¶
- class AvgMetricValue : MetricValue¶
- var numValues : int¶
- var intTotal : int(64)¶
- var realTotal : real¶
- proc update(val)¶
- class UserMetrics¶
- var metrics = new map(keyType = User, valType = shared CounterTable)¶
- var users = new Users()¶
- proc getUserMetrics(user: User) : borrowed CounterTable¶
- proc incrementPerUserRequestMetrics(userName: string, metricName: string, increment: int = 1)¶
- proc getPerUserNumRequestsPerCommandMetrics(userName: string)¶
- proc getPerUserNumRequestsPerCommandForAllUsersMetrics()¶
- proc incrementNumRequestsPerCommand(userName: string, cmd: string, increment: int = 1)¶
- proc incrementTotalNumRequests(userName: string, increment: int = 1)¶
- class MeasurementTable¶
The MeasurementTable encapsulates real measurements
- var measurements = new map(string, real)¶
- proc get(metric: string) : real throws¶
Returns the measurement corresponding to the metric name If the
metric does not exist, the metric value is set to 0.0 and is returned.
- proc set(metric: string, measurement: real) throws¶
Sets the metrics value
- proc size()¶
Returns the number of measurements in the MeasurementTable.s
- proc add(metric: string, measurement: real) throws¶
Adds a measurement to an existing measurement corresponding to the
metric name, setting the value if the metric does not exist.
- iter items()¶
- class AverageMeasurementTable : MeasurementTable¶
The AverageMeasurementTable extends the MeasurementTable by generating
values that are averages of incoming values for each metric.
- var numMeasurements = new map(string, int(64))¶
- var measurementTotals = new map(string, real)¶
- proc getNumMeasurements(metric: string) throws¶
Returns the number of measurements corresponding to a metric.
- proc getMeasurementTotal(metric: string) : real throws¶
Returns the sum of all measurements corresponding to a metric. Note:
this function is designed to invoked internally in order to
calculate the avg measurement value corresponding to the metric.
- override proc add(metric: string, measurement: real) throws¶
The overridden add method updates the measurement value by doing the following:
adds the measurement to a running total measurement for the metric
increments the number of measurements for the metric
divides the updated total measurement by the number of measurements to
to calculate the avg measurement
- class CounterTable¶
- var counts = new map(string, int)¶
- proc get(metric: string) : int¶
- proc set(metric: string, count: int)¶
- proc increment(metric: string, increment: int = 1)¶
- proc decrement(metric: string, increment: int = 1)¶
- iter items()¶
- proc size()¶
- proc total()¶
- proc exportAllMetrics() throws¶
- proc getUserRequestMetrics(userName: string) throws¶
- proc getAllUserRequestMetrics() throws¶
- proc getServerMetrics() throws¶
- proc getNumRequestMetrics() throws¶
- proc getNumErrorMetrics() throws¶
- proc getPerUserNumRequestMetrics() throws¶
- proc getResponseTimeMetrics() throws¶
- proc getAvgResponseTimeMetrics() throws¶
- proc getTotalResponseTimeMetrics() throws¶
- proc getTotalMemoryUsedMetrics() throws¶
- proc getMaxLocaleMemory(loc) throws¶
- proc getSystemMetrics() throws¶
- proc getServerInfo() throws¶
- class Metric¶
- var name : string¶
- var category : MetricCategory¶
- var scope : MetricScope¶
- var timestamp : dateTime¶
- var value : real¶
- proc init(name: string, category: MetricCategory, scope: MetricScope = MetricScope.GLOBAL, timestamp: dateTime = dateTime.now(), value: real)¶
- class UserMetric : Metric¶
- var user : string¶
- proc init(name: string, category: MetricCategory, scope: MetricScope = MetricScope.USER, timestamp: dateTime = dateTime.now(), value: real, user: string)¶
- class ArrayMetric : Metric¶
- var cmd : string¶
- var dType : DType¶
- var size : int¶
- proc init(name: string, category: MetricCategory, scope: MetricScope = MetricScope.GLOBAL, timestamp: dateTime = dateTime.now(), value: real, cmd: string, dType: DType, size: int)¶
- class LocaleInfo¶
- var name : string¶
- var id : string¶
- var hostname : string¶
- var number_of_processing_units : int¶
- var physical_memory : int¶
- var max_number_of_tasks : int¶
- class ServerInfo¶
- var hostname : string¶
- var version : string¶
- var server_port : int¶
- var locales : [0..numLocales-1] owned LocaleInfo?¶
- var number_of_locales : int¶
- proc init(hostname: string, version: string, server_port: int, locales)¶
- class LocaleMetric : Metric¶
- var locale_num : int¶
- var locale_name : string¶
- var locale_hostname : string¶
- proc init(name: string, category: MetricCategory, scope: MetricScope = MetricScope.LOCALE, timestamp: dateTime = dateTime.now(), value: real, locale_num: int, locale_name: string, locale_hostname: string)¶
- proc metricsMsg(cmd: string, msgArgs: borrowed MessageArgs, st: borrowed SymTab) : MsgTuple throws¶