예제 #1
0
        private void Send_InfluxDB_EDMS()
        {
            InfluxDB.LineProtocol.Client.LineProtocolClient client =
                new InfluxDB.LineProtocol.Client.LineProtocolClient(new Uri("http://127.0.0.1:8086"), "gravureprint");
            InfluxDB.LineProtocol.Payload.LineProtocolPayload payload =
                new InfluxDB.LineProtocol.Payload.LineProtocolPayload();

            if (distance > 100)
            {
                distance = 0;
            }
            _field.Clear();
            _tags.Clear();
            _tags["model"] = "model123";
            _tags["lot"]   = "lot123";

            var    val  = distance > 10 ? distance % 10 : distance;
            double dval = (double)val / 10.0;

            _field["distance"]  = dval;
            _field["variation"] = dval;
            var data = new InfluxDB.LineProtocol.Payload.LineProtocolPoint("edms", Fields, Tags);

            payload.Add(data);
            client.WriteAsync(payload);
        }
예제 #2
0
        private void Send_InfluxDB_RVMS()
        {
            InfluxDB.LineProtocol.Client.LineProtocolClient client =
                new InfluxDB.LineProtocol.Client.LineProtocolClient(new Uri("http://127.0.0.1:8086"), "gravureprint");
            InfluxDB.LineProtocol.Payload.LineProtocolPayload payload =
                new InfluxDB.LineProtocol.Payload.LineProtocolPayload();

            if (distance > 100)
            {
                distance = 0;
            }
            _field.Clear();
            _tags.Clear();
            _tags["model"] = "model123";
            _tags["lot"]   = "lot123";


            var    val  = distance > 10 ? distance % 10 : distance;
            double dval = (double)val / 10.0;


            _field["distance"] = dval;
            _field["left"]     = dval;
            _field["right"]    = dval;

            var data = new InfluxDB.LineProtocol.Payload.LineProtocolPoint("rvms", Fields, Tags);

            payload.Add(data);
            Task <LineProtocolWriteResult> influxResult = client.WriteAsync(payload);

            if (!influxResult.Result.Success)
            {
                Debug.Print("▶--RVMS--" + influxResult.Result.ErrorMessage + "...\n");
            }
        }
        public void Emit(PointData[] points)
        {
            var payload = new LineProtocolPayload();

            foreach (var point in points)
            {
                payload.Add(new LineProtocolPoint(point.Measurement, point.Fields, point.Tags, point.UtcTimestamp));
            }

            var influxResult = _client.WriteAsync(payload).Result;
            if (!influxResult.Success)
                CollectorLog.WriteLine(influxResult.ErrorMessage);
        }
        public async Task<LineProtocolWriteResult> WriteAsync(LineProtocolPayload payload, CancellationToken cancellationToken = default(CancellationToken))
        {
            var endpoint = $"write?db={Uri.EscapeDataString(_database)}";
            if (!string.IsNullOrEmpty(_username))
                endpoint += $"&u={Uri.EscapeDataString(_username)}&p={Uri.EscapeDataString(_password)}";

            var payloadText = new StringWriter();
            payload.Format(payloadText);
            var content = new StringContent(payloadText.ToString(), Encoding.UTF8);
            var response = await _httpClient.PostAsync(endpoint, content, cancellationToken);
            if (response.IsSuccessStatusCode)
                return new LineProtocolWriteResult(true, null);

            return new LineProtocolWriteResult(false, $"{response.StatusCode} {response.ReasonPhrase}");
        }
예제 #5
0
        private void Send_InfluxDB_Test()
        {
            Task <LineProtocolWriteResult> influxResult = null;

            try
            {
                InfluxDB.LineProtocol.Client.LineProtocolClient client =
                    new InfluxDB.LineProtocol.Client.LineProtocolClient(new Uri("http://127.0.0.1:8086"), "unieye");
                InfluxDB.LineProtocol.Payload.LineProtocolPayload payload =
                    new InfluxDB.LineProtocol.Payload.LineProtocolPayload();

                if (client == null)
                {
                    Debug.Print("@@@@@@@@@@@@@@@@@@@@@\n");
                }

                if (distance > 100)
                {
                    distance = 0;
                }
                _field.Clear();
                _tags.Clear();
                _tags["model"] = "model123";
                _tags["lot"]   = "lot123";


                //var val = distance > 10 ? distance % 10 : distance;
                double val  = distance++;
                double dval = (double)val / 10.0;


                _field["distance"] = dval;
                _field["left"]     = dval;
                _field["right"]    = dval;

                var data = new InfluxDB.LineProtocol.Payload.LineProtocolPoint("rvms", Fields, Tags);
                payload.Add(data);

                //influxResult=client.WriteAsync(payload);

                //influxResult.Wait();
                //if (!influxResult.Result.Success)
                //    Console.Error.WriteLine(influxResult.Result.ErrorMessage);
            }
            catch (Exception e)
            {
                string    err = "";
                Exception er  = e;
                while (er.InnerException != null)
                {
                    err += er.Message + "\n";
                    er   = er.InnerException;
                }
                Debug.Print(err);
            }
            return;
            //influxResult.Wait();
            //await Task.WhenAll(influxResult);
            //var re = await influxResult;
            //if (!influxResult.Result.Success)
            //{
            //    //Debug.Print("▶-----------" + influxResult.ErrorMessage + "...\n");
            //}

            //var client = new LineProtocolClient(new Uri("http://my-server:8086"), "data");
            //var influxResult = await client.WriteAsync(payload);
            //if (!influxResult.Success)
            //    Console.Error.WriteLine(influxResult.ErrorMessage);
        }