|
| 1 | +// This source code is dual-licensed under the Apache License, version |
| 2 | +// 2.0, and the Mozilla Public License, version 2.0. |
| 3 | +// |
| 4 | +// The APL v2.0: |
| 5 | +// |
| 6 | +//--------------------------------------------------------------------------- |
| 7 | +// Copyright (c) 2007-2020 VMware, Inc. |
| 8 | +// |
| 9 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +// you may not use this file except in compliance with the License. |
| 11 | +// You may obtain a copy of the License at |
| 12 | +// |
| 13 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +// |
| 15 | +// Unless required by applicable law or agreed to in writing, software |
| 16 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +// See the License for the specific language governing permissions and |
| 19 | +// limitations under the License. |
| 20 | +//--------------------------------------------------------------------------- |
| 21 | +// |
| 22 | +// The MPL v2.0: |
| 23 | +// |
| 24 | +//--------------------------------------------------------------------------- |
| 25 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 26 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 27 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 28 | +// |
| 29 | +// Copyright (c) 2007-2020 VMware, Inc. All rights reserved. |
| 30 | +//--------------------------------------------------------------------------- |
| 31 | + |
| 32 | +using System; |
| 33 | +using System.Diagnostics.Tracing; |
| 34 | +using System.Threading; |
| 35 | + |
| 36 | +namespace RabbitMQ.Client.Logging |
| 37 | +{ |
| 38 | + #nullable enable |
| 39 | + internal sealed partial class RabbitMqClientEventSource |
| 40 | + { |
| 41 | + private static int ConnectionsOpened; |
| 42 | + private static int ConnectionsClosed; |
| 43 | + private static int ChannelsOpened; |
| 44 | + private static int ChannelsClosed; |
| 45 | + private static long BytesSent; |
| 46 | + private static long BytesReceived; |
| 47 | + private static long CommandsSent; |
| 48 | + private static long CommandsReceived; |
| 49 | + |
| 50 | +#if !NETSTANDARD |
| 51 | + private PollingCounter? _connectionOpenedCounter; |
| 52 | + private PollingCounter? _openConnectionCounter; |
| 53 | + private PollingCounter? _channelOpenedCounter; |
| 54 | + private PollingCounter? _openChannelCounter; |
| 55 | + private IncrementingPollingCounter? _bytesSentCounter; |
| 56 | + private IncrementingPollingCounter? _bytesReceivedCounter; |
| 57 | + private IncrementingPollingCounter? _commandSentCounter; |
| 58 | + private IncrementingPollingCounter? _commandReceivedCounter; |
| 59 | + |
| 60 | + protected override void OnEventCommand(EventCommandEventArgs command) |
| 61 | + { |
| 62 | + if (command.Command == EventCommand.Enable) |
| 63 | + { |
| 64 | + _connectionOpenedCounter ??= new PollingCounter("total-connections-opened", this, () => ConnectionsOpened) { DisplayName = "Total connections opened" }; |
| 65 | + _openConnectionCounter ??= new PollingCounter("current-open-connections", this, () => ConnectionsOpened - ConnectionsClosed) { DisplayName = "Current open connections count" }; |
| 66 | + |
| 67 | + _channelOpenedCounter ??= new PollingCounter("total-channels-opened", this, () => ChannelsOpened) { DisplayName = "Total channels opened" }; |
| 68 | + _openChannelCounter ??= new PollingCounter("current-open-channels", this, () => ChannelsOpened - ChannelsClosed) { DisplayName = "Current open channels count" }; |
| 69 | + |
| 70 | + _bytesSentCounter ??= new IncrementingPollingCounter("bytes-sent-rate", this, () => Interlocked.Read(ref BytesSent)) { DisplayName = "Byte sending rate", DisplayUnits = "B", DisplayRateTimeScale = new TimeSpan(0, 0, 1) }; |
| 71 | + _bytesReceivedCounter ??= new IncrementingPollingCounter("bytes-received-rate", this, () => Interlocked.Read(ref BytesReceived)) { DisplayName = "Byte receiving rate", DisplayUnits = "B", DisplayRateTimeScale = new TimeSpan(0, 0, 1) }; |
| 72 | + |
| 73 | + _commandSentCounter ??= new IncrementingPollingCounter("AMQP-method-sent-rate", this, () => Interlocked.Read(ref CommandsSent)) { DisplayName = "AMQP method sending rate", DisplayUnits = "B", DisplayRateTimeScale = new TimeSpan(0, 0, 1) }; |
| 74 | + _commandReceivedCounter ??= new IncrementingPollingCounter("AMQP-method-received-rate", this, () => Interlocked.Read(ref CommandsReceived)) { DisplayName = "AMQP method receiving rate", DisplayUnits = "B", DisplayRateTimeScale = new TimeSpan(0, 0, 1) }; |
| 75 | + } |
| 76 | + } |
| 77 | +#endif |
| 78 | + [NonEvent] |
| 79 | + public void ConnectionOpened() |
| 80 | + { |
| 81 | + Interlocked.Increment(ref ConnectionsOpened); |
| 82 | + } |
| 83 | + |
| 84 | + [NonEvent] |
| 85 | + public void ConnectionClosed() |
| 86 | + { |
| 87 | + Interlocked.Increment(ref ConnectionsClosed); |
| 88 | + } |
| 89 | + |
| 90 | + [NonEvent] |
| 91 | + public void ChannelOpened() |
| 92 | + { |
| 93 | + Interlocked.Increment(ref ChannelsOpened); |
| 94 | + } |
| 95 | + |
| 96 | + [NonEvent] |
| 97 | + public void ChannelClosed() |
| 98 | + { |
| 99 | + Interlocked.Increment(ref ChannelsClosed); |
| 100 | + } |
| 101 | + |
| 102 | + [NonEvent] |
| 103 | + public void DataReceived(int byteCount) |
| 104 | + { |
| 105 | + Interlocked.Add(ref BytesReceived, byteCount); |
| 106 | + } |
| 107 | + |
| 108 | + [NonEvent] |
| 109 | + public void CommandSent(int byteCount) |
| 110 | + { |
| 111 | + Interlocked.Increment(ref CommandsSent); |
| 112 | + Interlocked.Add(ref BytesSent, byteCount); |
| 113 | + } |
| 114 | + |
| 115 | + [NonEvent] |
| 116 | + public void CommandReceived() |
| 117 | + { |
| 118 | + Interlocked.Increment(ref CommandsReceived); |
| 119 | + } |
| 120 | + } |
| 121 | +} |
0 commit comments