internal MetricsSinkAdapter(string name, string description, MetricsSink sink, string
                             context, MetricsFilter sourceFilter, MetricsFilter recordFilter, MetricsFilter
                             metricFilter, int period, int queueCapacity, int retryDelay, float retryBackoff,
                             int retryCount)
 {
     this.name         = Preconditions.CheckNotNull(name, "name");
     this.description  = description;
     this.sink         = Preconditions.CheckNotNull(sink, "sink object");
     this.context      = context;
     this.sourceFilter = sourceFilter;
     this.recordFilter = recordFilter;
     this.metricFilter = metricFilter;
     this.period       = Contracts.CheckArg(period, period > 0, "period");
     firstRetryDelay   = Contracts.CheckArg(retryDelay, retryDelay > 0, "retry delay");
     this.retryBackoff = Contracts.CheckArg(retryBackoff, retryBackoff > 1, "retry backoff"
                                            );
     oobPutTimeout = (long)(firstRetryDelay * Math.Pow(retryBackoff, retryCount) * 1000
                            );
     this.retryCount = retryCount;
     this.queue      = new SinkQueue <MetricsBuffer>(Contracts.CheckArg(queueCapacity, queueCapacity
                                                                        > 0, "queue capacity"));
     latency = registry.NewRate("Sink_" + name, "Sink end to end latency", false);
     dropped = registry.NewCounter("Sink_" + name + "Dropped", "Dropped updates per sink"
                                   , 0);
     qsize      = registry.NewGauge("Sink_" + name + "Qsize", "Queue size", 0);
     sinkThread = new _Thread_86(this);
     sinkThread.SetName(name);
     sinkThread.SetDaemon(true);
 }
Beispiel #2
0
        /// <summary>
        /// sets the txid and time for this locklist
        /// </summary>
        /// <param name="over">optional, the overrides</param>
        private void SetTxIdAndTime(IOperationOverrides over)
        {
            if (over != null && over.TxId != ulong.MaxValue)
            {
                this.TxId = (long)over.TxId;
            }

            if (over != null && over.TxTime != ulong.MaxValue)
            {
                this.TxTime = (long)over.TxTime;
            }
            else
            {
                this.TxTime = MutableStat.ConvertTime(DateTime.UtcNow);
            }
        }
            /// <summary>
            /// performs the actions on apply, and maybe run the scheduled action
            /// </summary>
            /// <param name="txtime">the time the transaction has</param>
            /// <param name="xid">the id for the transaction</param>
            /// <param name="func">the function to run</param>
            /// <param name="onMultiples">if true, this is only a run in multiples of</param>
            private void DoActionsOnApply(long txtime, long xid, RunOnTxIdMultiplesFunction func, bool onMultiples = true)
            {
                // if we already saw this txid (multiple calls to DoActionsOnApply per txid are possible), exit now
                if (xid == this.lastTxRun)
                {
                    return;
                }

                // if we are still loading, exit now
                if (this.ThisReplicaName == null)
                {
                    return;
                }

                // first produce an instrumentation signal indicating we are applying this transaction
                RingMasterServerInstrumentation.Instance.OnApply(txtime, xid);

                // if we don't have a function, exit now
                if (func == null)
                {
                    return;
                }

                // we only run the periodic action if we have a proper configuration, and it is time to run it based on such config
                if (onMultiples && (this.runOnTxIdMultiplesOf == 0 || (xid % this.runOnTxIdMultiplesOf) != 0))
                {
                    return;
                }

                // if the time is too off, exit
                if (Math.Abs((DateTime.UtcNow - MutableStat.ConvertTime(txtime)).TotalSeconds) > 60)
                {
                    Trace.TraceInformation("skipping action because it likely comes from the past");
                    return;
                }

                // set the last txid seen
                this.lastTxRun = xid;

                // do the action
                func(txtime, xid);
            }
Beispiel #4
0
            /// <summary>
            /// runs the command from the path
            /// </summary>
            /// <param name="req">the request containing the command</param>
            /// <param name="session">the session this command was run from</param>
            /// <param name="lockList">the lock list of the invocation</param>
            /// <returns>the repsonse to the command</returns>
            internal virtual RequestResponse RunCommand(RequestCreate req, ClientSession session, ILockListTransaction lockList)
            {
                if (req == null)
                {
                    throw new ArgumentNullException(nameof(req));
                }

                if (session == null)
                {
                    throw new ArgumentNullException(nameof(session));
                }

                MutableStat stat = new MutableStat(new FirstStat(0, MutableStat.ConvertTime(DateTime.UtcNow), 0));

                // we require the digest 'Commander'
                if (!string.Equals(session.Auth.ClientDigest, CommanderDigest, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(new RequestResponse()
                    {
                        Content = "not executed",
                        ResponsePath = "command",
                        ResultCode = (int)Code.Authfailed,
                        Stat = stat,
                    });
                }

                string requestedCommand;
                object content;
                Code   result = this.RunCommandPath(req.Path, req.Data, session, lockList, out requestedCommand, out content);

                return(new RequestResponse()
                {
                    Content = content,
                    ResponsePath = requestedCommand,
                    ResultCode = (int)result,
                    Stat = stat,
                });
            }
Beispiel #5
0
 internal ContainerMetrics(MetricsSystem ms, ContainerId containerId, long flushPeriodMs
                           , long delayMs)
 {
     // Use a multiplier of 1000 to avoid losing too much precision when
     // converting to integers
     // This tracks overall CPU percentage of the machine in terms of percentage
     // of 1 core similar to top
     // Thus if you use 2 cores completely out of 4 available cores this value
     // will be 200
     // Metrics publishing status
     // true if period elapsed
     // true if container finished
     // unregister
     // lazily initialized
     // Create a timer to unregister container metrics,
     // whose associated thread run as a daemon.
     this.recordInfo        = Interns.Info(SourceName(containerId), RecordInfo.Description());
     this.registry          = new MetricsRegistry(recordInfo);
     this.metricsSystem     = ms;
     this.containerId       = containerId;
     this.flushPeriodMs     = flushPeriodMs;
     this.unregisterDelayMs = delayMs < 0 ? 0 : delayMs;
     ScheduleTimerTaskIfRequired();
     this.pMemMBsStat = registry.NewStat(PmemUsageMetricName, "Physical memory stats",
                                         "Usage", "MBs", true);
     this.cpuCoreUsagePercent = registry.NewStat(PhyCpuUsageMetricName, "Physical Cpu core percent usage stats"
                                                 , "Usage", "Percents", true);
     this.milliVcoresUsed = registry.NewStat(VcoreUsageMetricName, "1000 times Vcore usage"
                                             , "Usage", "MilliVcores", true);
     this.pMemLimitMbs = registry.NewGauge(PmemLimitMetricName, "Physical memory limit in MBs"
                                           , 0);
     this.vMemLimitMbs = registry.NewGauge(VmemLimitMetricName, "Virtual memory limit in MBs"
                                           , 0);
     this.cpuVcoreLimit = registry.NewGauge(VcoreLimitMetricName, "CPU limit in number of vcores"
                                            , 0);
 }
Beispiel #6
0
        /// <summary>
        /// Deserializes this instance from the given <see cref="BinaryReader"/>.
        /// </summary>
        /// <param name="binaryReader">The <see cref="BinaryReader"/> to deserialize from</param>
        public void ReadFrom(BinaryReader binaryReader)
        {
            if (binaryReader == null)
            {
                throw new ArgumentNullException(nameof(binaryReader));
            }

            this.Id   = binaryReader.ReadUInt64();
            this.Name = binaryReader.ReadString();

            int aclCount = binaryReader.ReadInt32();

            if (aclCount > 0)
            {
                List <Acl> list = new List <Acl>(aclCount);

                for (int i = 0; i < aclCount; i++)
                {
                    string identifier = binaryReader.ReadString();
                    string scheme     = binaryReader.ReadString();
                    int    perm       = binaryReader.ReadInt32();
                    Acl    acl        = new Acl(perm, new Id(scheme, identifier));
                    list.Add(acl);
                }

                this.Acl = list.AsReadOnly();
            }
            else
            {
                this.Acl = null;
            }

            IMutableStat loadedStat = new MutableStat();

            loadedStat.Mzxid    = binaryReader.ReadInt64();
            loadedStat.Czxid    = binaryReader.ReadInt64();
            loadedStat.Pzxid    = binaryReader.ReadInt64();
            loadedStat.Aversion = binaryReader.ReadInt32();
            loadedStat.Version  = binaryReader.ReadInt32();
            loadedStat.Cversion = binaryReader.ReadInt32();
            loadedStat.Mtime    = binaryReader.ReadInt64();
            loadedStat.Ctime    = binaryReader.ReadInt64();

            loadedStat.DataLength = binaryReader.ReadInt32();
            if (loadedStat.DataLength == -1)
            {
                loadedStat.DataLength = 0;
                this.Data             = null;
            }
            else
            {
                this.Data = binaryReader.ReadBytes(loadedStat.DataLength);
            }

            // NumEphemeralChildren is 0 after deserialization.
            loadedStat.NumChildren = binaryReader.ReadInt32();
            this.ParentId          = binaryReader.ReadUInt64();

            this.Stat = loadedStat;
            ////Trace.TraceInformation($"PersistedData.Read: Id={this.Id} ParentId={this.ParentId} Name={this.Name} #Children={loadedStat.NumChildren} M={this.Stat.Mzxid}");
        }