Ejemplo n.º 1
0
        //string InfluxdbConnectionString = System.Configuration.ConfigurationManager.AppSettings["InfluxdbConnectionString"];
        //string MetricInfluxdbHost = System.Configuration.ConfigurationManager.AppSettings["MetricInfluxdbHost"];
        //string MetricInfluxdbPort = System.Configuration.ConfigurationManager.AppSettings["MetricInfluxdbPort"];
        //string MetricInfluxdbDBName = System.Configuration.ConfigurationManager.AppSettings["MetricInfluxdbDBName"];
        //string MetricInfluxdbUser = System.Configuration.ConfigurationManager.AppSettings["MetricInfluxdbUser"];
        //string MetricInfluxdbPwd = System.Configuration.ConfigurationManager.AppSettings["MetricInfluxdbPwd"];


        public void ProcessRequest(HttpContext context)
        {
            //context.Response.ContentType = "text/plain";



            try
            {
                context.Response.ContentType = "text/plain";

                string name     = context.Request["name"];
                double value    = Convert.ToDouble(context.Request["value"]);
                string tags_str = context.Request["tags"];

                var tags = new Dictionary <string, string>();

                List <MetricEntity> lst = new List <MetricEntity>();
                MetricEntity        m   = new MetricEntity();
                m.Name  = name;
                m.Value = value;
                if (!string.IsNullOrWhiteSpace(tags_str))
                {
                    var arr_tags = tags_str.Split('&');
                    for (int i = 0; i < arr_tags.Length; i++)
                    {
                        string[] tag       = arr_tags[i].Split('=');
                        string   tag_key   = tag[0];
                        string   tag_value = tag[1];
                        if (!string.IsNullOrWhiteSpace(tag_key))
                        {
                            tags[tag_key] = tag_value;
                        }
                    }
                }
                m.Tags = tags;
                m.Time = Utils.GetUnixTime(DateTime.Now);
                lst.Add(m);
                var w = new InfluxdbReport();
                w.Write(lst);



                context.Response.AddHeader("Access-Control-Allow-Origin", "*"); //允许跨域请求
                                                                                // context.Response.AddHeader("Access-Control-Allow-Credentials", "true");//允许跨域操作cookie

                context.Response.Write("point success :" + context.Request.RawUrl);
            }
            catch (Exception ex)
            {
                context.Response.Write(ex);
                context.Response.Write("point error :" + context.Request.RawUrl);
            }
        }
Ejemplo n.º 2
0
 public void Process(IList <MetricEntity> logs)
 {
     if (Config.MetricInfluxdbVer == "0.8")
     {
         InfluxdbReport report = new InfluxdbReport();
         report.WriteAsync(logs);
     }
     else
     {
         InfluxdbWriter report = new InfluxdbWriter();
         report.WriteAsync(logs);
     }
 }
Ejemplo n.º 3
0
        public dynamic Metric(string name, double value, string tags)
        {
            //string name = Request.Query["name"];
            //double value = Convert.ToDouble(Request.Query["value"]);
            //string tags_str = Request.Query["tags"];

            var tags_dic = new Dictionary <string, string>();

            List <MetricEntity> lst = new List <MetricEntity>();
            MetricEntity        m   = new MetricEntity();

            m.Name  = name;
            m.Value = value;
            if (!string.IsNullOrWhiteSpace(tags))
            {
                var arr_tags = tags.Split('&');
                for (int i = 0; i < arr_tags.Length; i++)
                {
                    string[] tag       = arr_tags[i].Split('=');
                    string   tag_key   = tag[0];
                    string   tag_value = tag[1];
                    if (!string.IsNullOrWhiteSpace(tag_key))
                    {
                        tags_dic[tag_key] = tag_value;
                    }
                }
            }
            m.Tags = tags_dic;
            m.Time = Utils.GetUnixTime(DateTime.Now);
            lst.Add(m);
            var w = new InfluxdbReport();

            w.Write(lst);

            return("point success !");
        }