Ejemplo n.º 1
0
 public Task<InfluxDbApiResponse> Write(IEnumerable<ApiResponseErrorHandlingDelegate> errorHandlers, string name,
     Serie[] series, string timePrecision)
 {
     return RequestAsync(errorHandlers, HttpMethod.Post, string.Format("db/{0}/series", name), series,
         new Dictionary<string, string>
         {
             {TimePrecision, timePrecision}
         });
 }
Ejemplo n.º 2
0
            public Serie Build()
            {
                Check.NotNullOrEmpty(_name, "Serie name must not be null or empty.");
                var serie = new Serie(_name)
                {
                    Columns = _columns.ToArray()
                };
                var points = new object[_valueRows.Count][];
                for (int i = 0; i < points.GetLength(0); i++)
                {
                    points[i] = new object[_columns.Count];
                }

                int row = 0;
                foreach (var values in _valueRows)
                {
                    points[row] = values.ToArray();
                    row++;
                }
                serie.Points = points;
                return serie;
            }
Ejemplo n.º 3
0
        private async Task<List<Serie>> Query(Serie expected)
        {
            // 0.9.3 need 'group by' to retrieve tags as tags when using select *
            var result = await _influx.QueryAsync(_dbName, String.Format("select * from \"{0}\" group by *", expected.Name));

            result.Should().NotBeNull();
            result.Count().Should().Be(1);

            var actual = result.Single();

            actual.Name.Should().Be(expected.Name);
            actual.Tags.Count.Should().Be(expected.Tags.Count);
            actual.Tags.ShouldAllBeEquivalentTo(expected.Tags);
            actual.Columns.ShouldAllBeEquivalentTo(expected.Columns);
            actual.Columns.Count().Should().Be(expected.Columns.Count());
            actual.Values[0].Count().Should().Be(expected.Values[0].Count());
            ((DateTime)actual.Values[0][0]).ToUnixTime().Should().Be(((DateTime)expected.Values[0][0]).ToUnixTime());

            return result;
        }
 public async Task<InfluxDbApiResponse> WriteData(TimeUnit timeUnit, Serie[] data)
 {
     return await _influxDbClient.WriteAsync(_influxDbName, timeUnit, data);
 }
 private void CleanUpSensorSerial(Serie serie)
 {
     serie.Name = serie.Name.Substring(serie.Name.LastIndexOf('.') + 1);
 }
Ejemplo n.º 6
0
    void SendBatch()
    {
        std::stringstream batchedData;
        MetricData data;
        bool firstLoop = true;
        while (_queuedData.Dequeue(data))
        {
            if (!firstLoop)
                batchedData << "\n";

            batchedData << data.Category;
            if (!_realmName.empty())
                batchedData << ",realm=" << _realmName;

            batchedData << " ";

            switch (data.Type)
            {
                case METRIC_DATA_VALUE:
                    batchedData << "value=" << data.Value;
                    break;
                case METRIC_DATA_EVENT:
                    batchedData << "title=\"" << data.Title << "\",text=\"" << data.Text << "\"";
                    break;
            }

            batchedData << " ";

            batchedData << std::to_string(duration_cast<nanoseconds>(data.Timestamp.time_since_epoch()).count());

            firstLoop = false;
            delete data;
        }

        // Check if there's any data to send
        if (batchedData.tellp() == std::streampos(0))
        {
            ScheduleSend();
            return;
        }

        if (!_dataStream.good() && !Connect())
            return;

        var blah = new InfluxDB.Net.InfluxDb(_hostname, "root", "root", InfluxDB.Net.Enums.InfluxVersion.v010x);
        InfluxDB.Net.Models.Serie b = new InfluxDB.Net.Models.Serie();
        b.Columns
        _dataStream.UploadString( << "POST " << "/write?db=" << _databaseName << " HTTP/1.1\r\n";
        _dataStream << "Host: " << _hostname << ":" << _port << "\r\n";
        _dataStream << "Accept: */*\r\n";
        _dataStream << "Content-Type: application/octet-stream\r\n";
        _dataStream << "Content-Transfer-Encoding: binary\r\n";

        _dataStream << "Content-Length: " << std::to_string(batchedData.tellp()) << "\r\n\r\n";
        _dataStream << batchedData.rdbuf();

        std::string http_version;
        _dataStream >> http_version;
        unsigned int status_code = 0;
        _dataStream >> status_code;
        if (status_code != 204)
        {
            TC_LOG_ERROR("metric", "Error sending data, returned HTTP code: %u", status_code);
        }

        // Read and ignore the status description
        std::string status_description;
        std::getline(_dataStream, status_description);
        // Read headers
        std::string header;
        while (std::getline(_dataStream, header) && header != "\r")
        {
            if (header == "Connection: close\r")
                _dataStream.close();
        }

        ScheduleSend();
    }