Beispiel #1
0
        private void SendMetricRequest(WriteRequest req)
        {
            var url   = Configuration.GetValue <string>("prom_write_url");
            var token = Configuration.GetValue <string>("prom_write_token");


            if (!String.IsNullOrEmpty(url))
            {
                MemoryStream stream = new MemoryStream();

                req.WriteTo(stream);
                byte[] arrIn = stream.ToArray();

                byte[] arr = SnappyCodec.Compress(arrIn);

                var handler = new HttpClientHandler();

                var httpClient = new HttpClient(handler);

                HttpRequestMessage requestMessage = new HttpRequestMessage(new HttpMethod("POST"), url);

                requestMessage.Headers.Add("Authorization", $"Bearer {token}");

                requestMessage.Content = new ByteArrayContent(arr);
                requestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-protobuf");
                requestMessage.Content.Headers.ContentEncoding.Add("snappy");


                HttpResponseMessage response = httpClient.SendAsync(requestMessage).Result;
            }
        }
Beispiel #2
0
            // This function should be called in busy state (state == 1)
            void BuildWriteBuffer()
            {
                Fx.Assert(this.state == 1, "Should be busy at this time");
                Fx.Assert(this.writeBuffer.Length == 0, "Cannot have payload in the write buffer at this point");
                Fx.Assert(this.firstRequest != null && this.lastRequest != null, "Must have buffer to write at this time");
                int bufferSize = this.writeBuffer.Capacity;
                // take a snapshot so we don't have to lock
                WriteRequest first         = this.firstRequest;
                WriteRequest last          = this.lastRequest;
                WriteRequest request       = first;
                WriteRequest lastCompleted = null;

                while (true)
                {
                    if (!request.WriteTo(this.writeBuffer))
                    {
                        break;
                    }

                    lastCompleted = request;
                    request       = request.Next;
                    if (lastCompleted == last)
                    {
                        break;
                    }
                }

                this.writeAsyncEventArgs.SetBuffer(this.writeBuffer.Buffer, this.writeBuffer.Offset, this.writeBuffer.Length);
                if (lastCompleted != null)
                {
                    this.writeAsyncEventArgs.UserToken = first;
                    lock (this.syncRoot)
                    {
                        this.firstRequest  = lastCompleted.Next;
                        lastCompleted.Next = null;
                        if (this.firstRequest == null)
                        {
                            this.lastRequest = null;
                        }
                    }
                }
            }