<commit_before>﻿/*
 * Copyright (c) 2017 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Google.Cloud.Monitoring.V3;
using CommandLine;
using Google.Api.Gax;
using Google.Api;
using Newtonsoft.Json.Linq;
using static Google.Api.MetricDescriptor.Types;
using Google.Protobuf.WellKnownTypes;
using System.Net;

namespace GoogleCloudSamples
{
    [Verb("create", HelpText = "Create a metric descriptor for this project.")]
    class CreateOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
        [Value(1, HelpText = "The metric type of the metric to create.", Required = false,
            Default = "custom.googleapis.com/stores/daily_sales")]
        public string metricType { get; set; }
    }

    [Verb("list", HelpText = "List metric descriptors for this project.")]
    class ListOptions : CreateAndListOptions { }

    [Verb("listGroups", HelpText = "List metric groups for this project.")]
    class ListGroupsOptions : CreateAndListOptions { }

    [Verb("listResources", HelpText = "List monitored resources for this project.")]
    class ListMonitoredResourcesOptions : CreateAndListOptions { }

    class CreateAndListOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
    }

    [Verb("get", HelpText = "Get a metric descriptor's details.")]
    class GetOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
        [Value(1, HelpText = "The metric descriptor type of the metric to display details for.", Required = true)]
        public string metricType { get; set; }
    }

    [Verb("getResource", HelpText = "Get a monitored resource descriptor.")]
    class GetMonitoredResourceOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
        [Value(1, HelpText = "The resource descriptor ID of the metric to display details for.", Required = true)]
        public string resourceId { get; set; }
    }

    [Verb("write", HelpText = "Write TimeSeries data to custom metric.")]
    class WriteTimeSeriesDataOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
    }

    [Verb("read", HelpText = "Read TimeSeries data from a metric.")]
    class ReadTimeSeriesDataOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
        [Value(1, HelpText = "The metric type of the metric to read timeseries data from.", Required = false,
            Default = "compute.googleapis.com/instance/cpu/utilization")]
        public string metricType { get; set; }
    }

    [Verb("readFields", HelpText = "Reads headers of time series data.")]
    class ReadTimeSeriesFieldsOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
        [Value(1, HelpText = "The metric type of the metric to read timeseries data from.", Required = false, Default = "compute.googleapis.com/instance/cpu/utilization")]
        public string metricType { get; set; }
    }

    [Verb("readAggregate", HelpText = "Aggregates time series data that matches the specified metric type.")]
    class ReadTimeSeriesAggregateOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
        [Value(1, HelpText = "The metric type of the metric to read time series data from.", Required = false, Default = "compute.googleapis.com/instance/cpu/utilization")]
        public string metricType { get; set; }
    }

    [Verb("readReduce", HelpText = "Reduces time series data that matches the specified metric type.")]
    class ReadTimeSeriesReduceOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
        [Value(1, HelpText = "The metric type of the metric to read time series data from.", Required = false, Default = "compute.googleapis.com/instance/cpu/utilization")]
        public string metricType { get; set; }
    }



    [Verb("delete", HelpText = "Delete a metric descriptor for this project.")]
    class DeleteOptions
    {
        [Value(0, HelpText = "The project ID of the project containing the metric descriptor to delete.", Required = true)]
        public string projectId { get; set; }
        [Value(1, HelpText = "The metric descriptor type of the metric to delete.", Required = true)]
        public string metricType { get; set; }
    }

    public class Monitoring
    {
        private static readonly DateTime s_unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

        // [START monitoring_create_metric]
        public static object CreateMetric(string projectId,
            string metricType = "custom.googleapis.com/stores/daily_sales")
        {
            // Create client.
            MetricServiceClient metricServiceClient = MetricServiceClient.Create();

            // Prepare custom metric descriptor.      
            MetricDescriptor metricDescriptor = new MetricDescriptor();
            metricDescriptor.Name = "Daily Sales";
            metricDescriptor.DisplayName = "Daily Sales";
            metricDescriptor.Description = "Daily sales records from all branch stores.";
            metricDescriptor.MetricKind = MetricKind.Gauge;
            metricDescriptor.ValueType = MetricDescriptor.Types.ValueType.Double;
            metricDescriptor.Type = metricType;
            metricDescriptor.Unit = "{USD}";
            LabelDescriptor labels = new LabelDescriptor();
            labels.Key = "store_id";
            labels.ValueType = LabelDescriptor.Types.ValueType.String;
            labels.Description = "The ID of the store.";<commit_msg>Use a machine-readable metric name.<commit_after>﻿/*
 * Copyright (c) 2017 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Google.Cloud.Monitoring.V3;
using CommandLine;
using Google.Api.Gax;
using Google.Api;
using Newtonsoft.Json.Linq;
using static Google.Api.MetricDescriptor.Types;
using Google.Protobuf.WellKnownTypes;
using System.Net;

namespace GoogleCloudSamples
{
    [Verb("create", HelpText = "Create a metric descriptor for this project.")]
    class CreateOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
        [Value(1, HelpText = "The metric type of the metric to create.", Required = false,
            Default = "custom.googleapis.com/stores/daily_sales")]
        public string metricType { get; set; }
    }

    [Verb("list", HelpText = "List metric descriptors for this project.")]
    class ListOptions : CreateAndListOptions { }

    [Verb("listGroups", HelpText = "List metric groups for this project.")]
    class ListGroupsOptions : CreateAndListOptions { }

    [Verb("listResources", HelpText = "List monitored resources for this project.")]
    class ListMonitoredResourcesOptions : CreateAndListOptions { }

    class CreateAndListOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
    }

    [Verb("get", HelpText = "Get a metric descriptor's details.")]
    class GetOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
        [Value(1, HelpText = "The metric descriptor type of the metric to display details for.", Required = true)]
        public string metricType { get; set; }
    }

    [Verb("getResource", HelpText = "Get a monitored resource descriptor.")]
    class GetMonitoredResourceOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
        [Value(1, HelpText = "The resource descriptor ID of the metric to display details for.", Required = true)]
        public string resourceId { get; set; }
    }

    [Verb("write", HelpText = "Write TimeSeries data to custom metric.")]
    class WriteTimeSeriesDataOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
    }

    [Verb("read", HelpText = "Read TimeSeries data from a metric.")]
    class ReadTimeSeriesDataOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
        [Value(1, HelpText = "The metric type of the metric to read timeseries data from.", Required = false,
            Default = "compute.googleapis.com/instance/cpu/utilization")]
        public string metricType { get; set; }
    }

    [Verb("readFields", HelpText = "Reads headers of time series data.")]
    class ReadTimeSeriesFieldsOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
        [Value(1, HelpText = "The metric type of the metric to read timeseries data from.", Required = false, Default = "compute.googleapis.com/instance/cpu/utilization")]
        public string metricType { get; set; }
    }

    [Verb("readAggregate", HelpText = "Aggregates time series data that matches the specified metric type.")]
    class ReadTimeSeriesAggregateOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
        [Value(1, HelpText = "The metric type of the metric to read time series data from.", Required = false, Default = "compute.googleapis.com/instance/cpu/utilization")]
        public string metricType { get; set; }
    }

    [Verb("readReduce", HelpText = "Reduces time series data that matches the specified metric type.")]
    class ReadTimeSeriesReduceOptions
    {
        [Value(0, HelpText = "The project ID of the project to use for monitoring operations.", Required = true)]
        public string projectId { get; set; }
        [Value(1, HelpText = "The metric type of the metric to read time series data from.", Required = false, Default = "compute.googleapis.com/instance/cpu/utilization")]
        public string metricType { get; set; }
    }



    [Verb("delete", HelpText = "Delete a metric descriptor for this project.")]
    class DeleteOptions
    {
        [Value(0, HelpText = "The project ID of the project containing the metric descriptor to delete.", Required = true)]
        public string projectId { get; set; }
        [Value(1, HelpText = "The metric descriptor type of the metric to delete.", Required = true)]
        public string metricType { get; set; }
    }

    public class Monitoring
    {
        private static readonly DateTime s_unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

        // [START monitoring_create_metric]
        public static object CreateMetric(string projectId,
            string metricType = "custom.googleapis.com/stores/daily_sales")
        {
            // Create client.
            MetricServiceClient metricServiceClient = MetricServiceClient.Create();

            // Prepare custom metric descriptor.      
            MetricDescriptor metricDescriptor = new MetricDescriptor();
            metricDescriptor.Name = "daily_sales";
            metricDescriptor.DisplayName = "Daily Sales";
            metricDescriptor.Description = "Daily sales records from all branch stores.";
            metricDescriptor.MetricKind = MetricKind.Gauge;
            metricDescriptor.ValueType = MetricDescriptor.Types.ValueType.Double;
            metricDescriptor.Type = metricType;
            metricDescriptor.Unit = "{USD}";
            LabelDescriptor labels = new LabelDescriptor();
            labels.Key = "store_id";
            labels.ValueType = LabelDescriptor.Types.ValueType.String;
            labels.Description = "The ID of the store.";
{'fraction_non_alphanumeric': 0.09367881548974943, 'fraction_numerical': 0.005125284738041002, 'mean_word_length': 3.062753036437247, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6259945', 'n_tokens_mistral': 3646, 'n_tokens_neox': 3541, 'n_words': 1380}