Ejemplo n.º 1
0
        public void CreateTimeSeries()
        {
            ProjectName name = new ProjectName(projectId);

            // Prepare a data point.
            Point      dataPoint  = new Point();
            TypedValue salesTotal = new TypedValue
            {
                DoubleValue = 123.45
            };

            dataPoint.Value = salesTotal;
            // Sets data point's interval end time to current time.
            Timestamp timeStamp = new Timestamp();
            DateTime  UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            timeStamp.Seconds = (long)(DateTime.UtcNow - UnixEpoch).TotalSeconds;
            TimeInterval interval = new TimeInterval
            {
                EndTime = timeStamp
            };

            dataPoint.Interval = interval;

            // Prepare custom metric.
            Metric metric = new Metric
            {
                Type = "custom.googleapis.com/shops/daily_sales"
            };

            metric.Labels.Add("store_id", "Pittsburgh");

            // Prepare monitored resource.
            MonitoredResource resource = new MonitoredResource
            {
                Type = "global"
            };

            resource.Labels.Add("project_id", projectId);

            // Create a new time series using inputs.
            TimeSeries timeSeriesData = new TimeSeries
            {
                Metric   = metric,
                Resource = resource
            };

            timeSeriesData.Points.Add(dataPoint);

            // Add newly created time series to list of time series to be written.
            IEnumerable <TimeSeries> timeSeries = new List <TimeSeries> {
                timeSeriesData
            };

            // Write time series data.
            client.CreateTimeSeriesAsync(name, timeSeries);
        }
Ejemplo n.º 2
0
        public async Task CreateTimeSeriesAsync()
        {
            // Snippet: CreateTimeSeriesAsync(string,IEnumerable<TimeSeries>,CallSettings)
            // Additional: CreateTimeSeriesAsync(string,IEnumerable<TimeSeries>,CancellationToken)
            // Create client
            MetricServiceClient metricServiceClient = MetricServiceClient.Create();
            // Initialize request argument(s)
            string formattedName = MetricServiceClient.FormatProjectName("[PROJECT]");
            IEnumerable <TimeSeries> timeSeries = new List <TimeSeries>();
            // Make the request
            await metricServiceClient.CreateTimeSeriesAsync(formattedName, timeSeries);

            // End snippet
        }
Ejemplo n.º 3
0
        /// <summary>Snippet for CreateTimeSeriesAsync</summary>
        public async Task CreateTimeSeriesAsync_RequestObject()
        {
            // Snippet: CreateTimeSeriesAsync(CreateTimeSeriesRequest,CallSettings)
            // Create client
            MetricServiceClient metricServiceClient = await MetricServiceClient.CreateAsync();

            // Initialize request argument(s)
            CreateTimeSeriesRequest request = new CreateTimeSeriesRequest
            {
                ProjectName = new ProjectName("[PROJECT]"),
                TimeSeries  = { },
            };
            // Make the request
            await metricServiceClient.CreateTimeSeriesAsync(request);

            // End snippet
        }
        public async Task ExportAsync(IEnumerable <TimeSeries> timeSeries)
        {
            if (!timeSeries.Any())
            {
                return;
            }

            var callTiming = CallTiming.FromTimeout(_options.ExportInterval);

            var callSettings = new CallSettings(
                _cancellationToken,
                null,
                callTiming,
                null,
                null,
                null);

            await _client.CreateTimeSeriesAsync(
                new ProjectName(_options.ProjectId),
                timeSeries,
                callSettings);
        }
Ejemplo n.º 5
0
 public async Task SendTimeSeriesAsync(TimeSeries[] timeSeries)
 {
     await _client.CreateTimeSeriesAsync(_projectName, timeSeries);
 }