protected async Task <IStatsOperationResult> PerformStats(string key) { var ops = new List <Tuple <IStatsOperation, INode> >(); // TODO catch this? await cluster.Broadcast(n => { var op = opFactory.Stats(key); ops.Add(Tuple.Create(op, n)); return(op); }).ConfigureAwait(false); var stats = new ServerStats(); StatsOperationResult retval = null; foreach (var pair in ops) { var nodeResult = pair.Item1.Result; if (retval == null) { retval = new StatsOperationResult { Value = stats } }
protected override bool ExecuteAction() { Dictionary<IPEndPoint, Dictionary<string, string>> retval = new Dictionary<IPEndPoint, Dictionary<string, string>>(); foreach (MemcachedNode server in this.ServerPool.WorkingServers) { using (PooledSocket ps = server.Acquire()) { ps.SendCommand("stats"); Dictionary<string, string> serverData = new Dictionary<string, string>(StringComparer.Ordinal); while (true) { string line = ps.ReadResponse(); // stat values are terminated by END if (String.Compare(line, "END", StringComparison.Ordinal) == 0) break; // expected response is STAT item_name item_value if (line.Length < 6 || String.Compare(line, 0, "STAT ", 0, 5, StringComparison.Ordinal) != 0) { if (log.IsWarnEnabled) log.Warn("Unknow response: " + line); continue; } // get the key&value string[] parts = line.Remove(0, 5).Split(' '); if (parts.Length != 2) { if (log.IsWarnEnabled) log.Warn("Unknow response: " + line); continue; } // store the stat item serverData[parts[0]] = parts[1]; } retval[server.EndPoint] = serverData; } } this.results = new ServerStats(retval); return true; }
protected override bool ExecuteAction() { Dictionary <IPEndPoint, Dictionary <string, string> > retval = new Dictionary <IPEndPoint, Dictionary <string, string> >(); foreach (MemcachedNode server in this.ServerPool.WorkingServers) { using (PooledSocket ps = server.Acquire()) { if (ps == null) { continue; } ps.SendCommand("stats"); Dictionary <string, string> serverData = new Dictionary <string, string>(StringComparer.Ordinal); while (true) { string line = ps.ReadResponse(); // stat values are terminated by END if (String.Compare(line, "END", StringComparison.Ordinal) == 0) { break; } // expected response is STAT item_name item_value if (line.Length < 6 || String.Compare(line, 0, "STAT ", 0, 5, StringComparison.Ordinal) != 0) { if (log.IsWarnEnabled) { log.Warn("Unknow response: " + line); } continue; } // get the key&value string[] parts = line.Remove(0, 5).Split(' '); if (parts.Length != 2) { if (log.IsWarnEnabled) { log.Warn("Unknow response: " + line); } continue; } // store the stat item serverData[parts[0]] = parts[1]; } retval[server.EndPoint] = serverData; } } this.results = new ServerStats(retval); return(true); }
public InstanceStatistics(System.Net.IPEndPoint serverEndPoint, Server server, Instance instance, ServerStats serverStats, State serviceState) { string memcachedFileVersion = null; if (File.Exists(Configuration.Default.MemcachedBinarySource) == true) memcachedFileVersion = FileVersionInfo.GetVersionInfo(Configuration.Default.MemcachedBinarySource).FileVersion; _serverName = server.ServerName; _instanceName = instance.DisplayName; _serviceState = serviceState; Instance = instance; _statusIconIndex = StatusIconIndex.CommunicationError; _statusTooltip = Constants.TooltipCommunicationError; if (serverStats != null && serverStats.GetRaw(serverEndPoint, StatItem.Version) != null) { foreach (StatItem statItem in Enum.GetValues(typeof(Enyim.Caching.Memcached.StatItem))) { switch (statItem) { case StatItem.BytesRead: _bytesRead = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.BytesWritten: _bytesWritten = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.ConnectionCount: _connectionCount = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.ConnectionStructures: _connectionStructures = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.GetCount: _getCount = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.GetHits: _getHits = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.GetMisses: _getMisses = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.ItemCount: _itemCount = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.MaxBytes: _maxBytes = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.ServerTime: string serverTimeRaw = serverStats.GetRaw(serverEndPoint, statItem); int serverTimeSeconds; if (serverTimeRaw != null && Int32.TryParse(serverTimeRaw, out serverTimeSeconds) == true) _serverTime = new DateTime(1970, 1, 1).AddSeconds(serverTimeSeconds).ToLocalTime().ToString(); else _serverTime = "<unknown>"; break; case StatItem.SetCount: _setCount = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.TotalConnections: _totalConnections = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.TotalItems: _totalItems = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.Uptime: string uptimeRaw = serverStats.GetRaw(serverEndPoint, statItem); int uptimeSeconds; if (uptimeRaw != null && Int32.TryParse(uptimeRaw, out uptimeSeconds) == true) _uptime = TimeSpan.FromSeconds(uptimeSeconds).ToString(); else _uptime = "<unknown>"; break; case StatItem.UsedBytes: _usedBytes = serverStats.GetValue(serverEndPoint, statItem); break; case StatItem.Version: _version = serverStats.GetRaw(serverEndPoint, statItem); break; } } } if (_serviceState != State.Running && _serviceState != State.Unknown) { _statusIconIndex = StatusIconIndex.ServiceDown; _statusTooltip = Constants.TooltipServiceDown; } else if (_serviceState == State.Unknown) { _statusIconIndex = StatusIconIndex.ServiceNonControllable; _statusTooltip = Constants.TooltipServiceNonControllable; } else if (_version == null || _version == String.Empty) { _statusIconIndex = StatusIconIndex.CommunicationError; _statusTooltip = Constants.TooltipCommunicationError; } else if (memcachedFileVersion != null && memcachedFileVersion != _version) { _statusIconIndex = StatusIconIndex.NeedsUpdate; _statusTooltip = Constants.TooltipNeedsUpdate; } else { _statusIconIndex = StatusIconIndex.Up; _statusTooltip = Constants.TooltipUp; } }