Esempio n. 1
0
 private IEnumerable <MBeanAttributeInfo> GetCurrentAttributes()
 {
     return(_counters.Values.Select(x =>
                                    MBean.ReadOnlyAttribute(x.CounterName,
                                                            string.Format(CultureInfo.CurrentCulture,
                                                                          "Raw counter value for counter {0}.",
                                                                          x.CounterName)).TypedAs(SimpleType.Float)()));
 }
Esempio n. 2
0
 public MBeanInfo GetMBeanInfo()
 {
     return(MBean.Info <SampleDynamicMBean>("Sample dynamic MBean")
            .WithAttributes(
                MBean.WritableAttribute("Attribute", "Sample attribute").TypedAs(TabularType),
                MBean.WritableAttribute("NestedTableAttribute", "Nested Table Attribute").TypedAs(NestedTabularType)
                )
            .AndNothingElse()());
 }
Esempio n. 3
0
 public MBeanInfo GetMBeanInfo()
 {
     return(MBean.Info <SampleDynamicMBean>("Sample dynamic MBean")
            .WithAttributes(
                MBean.WritableAttribute("Tabular", "Sample tabular attribute").TypedAs(_tabularType),
                MBean.WritableAttribute("Array", "Sample array attribute").TypedAs(_arrayType),
                MBean.WritableAttribute("Composite", "Sample composite attribute").TypedAs(_rowType)
                )
            .AndNothingElse()());
 }
Esempio n. 4
0
        public MBeanInfo GetMBeanInfo()
        {
            if (_beanInfoDirty)
            {
                string description;
                if (_perfInstanceName != null)
                {
                    description = string.Format(CultureInfo.CurrentCulture, "Performance counter MBean for {0} of {1}.", _perfObjectName, _perfInstanceName);
                }
                else
                {
                    description = string.Format(CultureInfo.CurrentCulture, "Performance counter MBean for {0}.", _perfObjectName);
                }
                List <object> legalCountersToCreate = new List <object>();
                List <object> legalCountersToRemove = new List <object>();

                foreach (PerformanceCounter counter in _category.GetCounters(_perfInstanceName))
                {
                    if (_counters.ContainsKey(counter.CounterName))
                    {
                        legalCountersToRemove.Add(counter.CounterName);
                    }
                    else
                    {
                        legalCountersToCreate.Add(counter.CounterName);
                    }
                }

                MBeanOperationInfo addOperation =
                    MBean.MutatorOperation("AddPerformanceCounter", "Adds new performance counter")
                    .WithParameters(
                        MBean.Parameter("counterName", "Name of new counter")
                        .WithLimitedValues(legalCountersToCreate)
                        .TypedAs(SimpleType.String)
                        )
                    .Returning(SimpleType.Boolean)();

                MBeanOperationInfo removeOperation =
                    MBean.MutatorOperation("RemovePerformanceCounter", "Removes existing performance counter")
                    .WithParameters(
                        MBean.Parameter("counterName", "Name of new counter")
                        .WithLimitedValues(legalCountersToRemove)
                        .TypedAs(SimpleType.String)
                        )
                    .Returning(SimpleType.Boolean)();

                _beanInfo = MBean.Info(typeof(PerfCounterMBean).AssemblyQualifiedName, description)
                            .WithAttributes(GetCurrentAttributes)
                            .WithOperations(addOperation, removeOperation)
                            .AndNothingElse()();

                _beanInfoDirty = false;
            }
            return(_beanInfo);
        }
Esempio n. 5
0
        public OpenDynamic()
        {
            _tabularType = Tabular.Type("Table", "Table")
                           .WithIndexColumn("ID", "UniqueID").TypedAs(SimpleType.Integer)
                           .WithColumn("Name", "Name").TypedAs(SimpleType.String);

            _tabularValue = new TabularDataSupport(_tabularType);

            _outerTabularType = Tabular.Type("Outer table", "Outer table")
                                .WithIndexColumn("ID", "Unique ID").TypedAs(SimpleType.Integer)
                                .WithColumn("Value", "Tabular value").TypedAs(
                Tabular.Type("Inner table", "Inner table")
                .WithIndexColumn("ID", "Unique ID").TypedAs(SimpleType.Integer)
                .WithColumn("Name", "Name").TypedAs(SimpleType.String)
                .WithColumn("CompositeValue", "Composite Value").TypedAs(
                    Composite.Type("Composite value", "Composite value")
                    .WithItem("Item1", "Item 2").TypedAs(SimpleType.Integer)
                    .WithItem("Item2", "Item 2").TypedAs(SimpleType.Boolean)
                    .WithItem("Item3", "Item 3").TypedAs(
                        Composite.Type("Nested", "Nested composite")
                        .WithItem("NestedItem1", "NestedItem1").TypedAs(SimpleType.String)
                        .WithItem("NestedItem2", "NestedItem2").TypedAs(SimpleType.Double))));

            _nestedTabularValue = new TabularDataSupport(_outerTabularType);

            _beanInfoGetter = MBean.Info <OpenDynamic>("Sample dynamic MBean")
                              .WithAttributes(
                MBean.WritableAttribute("Attribute", "Sample attribute").TypedAs(TabularType),
                MBean.WritableAttribute("NestedTableAttribute", "Nested Table Attribute").TypedAs(NestedTabularType)
                )
                              .WithOperations(
                MBean.MutatorOperation("DoSomething", "Does somthing").WithParameters(
                    MBean.Parameter("First", "First parameter").TypedAs(SimpleType.Double),
                    MBean.Parameter("Second", "Second parameter").TypedAs(TabularType)
                    ).Returning(SimpleType.Void)
                )
                              .AndNothingElse();
        }
Esempio n. 6
0
        /// <summary>
        /// Load the list output from Jolokia, and parse it to MBeans and Operations
        /// </summary>
        /// <param name="domainPath">domain to load, null if all</param>
        /// <param name="mbeanPath">Mbean to load, null if all</param>
        /// <param name="cancellationToken"></param>
        public async Task LoadListAsync(string domainPath = null, string mbeanPath = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            var listUri = _baseUri.AppendSegments("list", domainPath, mbeanPath);
            var jmxInfo = await listUri.GetAsAsync <dynamic>(cancellationToken).ConfigureAwait(false);

            if (jmxInfo.status != 200)
            {
                throw new InvalidOperationException("Status != 200");
            }

            IDictionary <string, dynamic> domains;

            if (!string.IsNullOrEmpty(domainPath))
            {
                IDictionary <string, dynamic> loadedMBeans = jmxInfo.value;
                if (!string.IsNullOrEmpty(mbeanPath))
                {
                    loadedMBeans = new Dictionary <string, dynamic> {
                        { mbeanPath, loadedMBeans }
                    };
                }
                domains = new Dictionary <string, dynamic> {
                    { domainPath, loadedMBeans }
                };
            }
            else
            {
                domains = jmxInfo.value;
            }

            foreach (var domainItem in domains)
            {
                string domainName = domainItem.Key;
                IDictionary <string, MBean> mbeans;
                if (!Domains.TryGetValue(domainName, out mbeans))
                {
                    mbeans = new Dictionary <string, MBean>();
                    Domains.Add(domainName, mbeans);
                }
                foreach (var mbeanItem in (IDictionary <string, dynamic>)domainItem.Value)
                {
                    var mbean = new MBean
                    {
                        Name        = mbeanItem.Key,
                        Domain      = domainName,
                        Description = mbeanItem.Value.desc
                    };

                    // Build attributes
                    var attributes = (IDictionary <string, dynamic>)mbeanItem.Value.attr;
                    if (attributes != null)
                    {
                        foreach (var attributeItem in attributes)
                        {
                            var attribute = new Attr
                            {
                                Name        = attributeItem.Key,
                                Description = attributeItem.Value.desc,
                                Type        = attributeItem.Value.desc,
                                IsReadonly  = attributeItem.Value.rw == false,
                                Parent      = mbean.FullyqualifiedName
                            };
                            mbean.Attributes.Add(attribute.Name, attribute);
                        }
                    }

                    // Build operations
                    var operations = (IDictionary <string, dynamic>)mbeanItem.Value.op;
                    if (operations != null)
                    {
                        foreach (var operationItem in operations)
                        {
                            if (operationItem.Value.GetType() == typeof(JsonArray))
                            {
                                // Skip overloaded for now
                                continue;
                            }
                            var operation = new Operation
                            {
                                Name        = operationItem.Key,
                                Description = operationItem.Value.desc,
                                ReturnType  = operationItem.Value.ret,
                                Parent      = mbean.FullyqualifiedName
                            };
                            // Arguments
                            foreach (var argumentItem in (ICollection <dynamic>)operationItem.Value.args)
                            {
                                operation.Arguments.Add(new Argument
                                {
                                    Name        = argumentItem.name,
                                    Description = argumentItem.desc,
                                    Type        = argumentItem.type
                                });
                            }
                            mbean.Operations.Add(operation.Name, operation);
                        }
                    }
                    if (mbeans.ContainsKey(mbean.FullyqualifiedName))
                    {
                        mbeans[mbean.FullyqualifiedName] = mbean;
                    }
                    else
                    {
                        mbeans.Add(mbean.FullyqualifiedName, mbean);
                    }
                }
            }
        }