Welcome to mirror list, hosted at ThFree Co, Russian Federation.

metric.rb « metrics « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7ea9555cc8c62cda18a22f091c075cef0c8dffe1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Gitlab
  module Metrics
    # Class for storing details of a single metric (label, value, etc).
    class Metric
      attr_reader :series, :values, :tags, :created_at

      # series - The name of the series (as a String) to store the metric in.
      # values - A Hash containing the values to store.
      # tags   - A Hash containing extra tags to add to the metrics.
      def initialize(series, values, tags = {})
        @values     = values
        @series     = series
        @tags       = tags
        @created_at = Time.now.utc
      end

      # Returns a Hash in a format that can be directly written to InfluxDB.
      def to_hash
        {
          series:    @series,
          tags:      @tags,
          values:    @values,
          timestamp: @created_at.to_i * 1_000_000_000
        }
      end
    end
  end
end