Class: Promtest
- Inherits:
-
Object
- Object
- Promtest
- Defined in:
- lib/logstash/outputs/prom_test.rb
Instance Method Summary collapse
- #createClient ⇒ Object
- #getToken(client) ⇒ Object
- #label_set_for(labels) ⇒ Object
- #register ⇒ Object
- #send ⇒ Object
- #stringify_values(labels) ⇒ Object
- #WriteRequest(token) ⇒ Object
Instance Method Details
#createClient ⇒ Object
63 64 65 66 67 |
# File 'lib/logstash/outputs/prom_test.rb', line 63 def createClient() @logger.info("createClient: started method") client = OAuth2::Client.new(@client_id, @client_secret, auth_scheme: "basic_auth", site: @tokenurl_domain,:token_url => @tokenurl_endpoint) return client end |
#getToken(client) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/logstash/outputs/prom_test.rb', line 69 def getToken(client) params = {} opts = {} params = params.merge('scope' => @scopes) access = client.client_credentials.get_token(params, opts) return access end |
#label_set_for(labels) ⇒ Object
35 36 37 38 |
# File 'lib/logstash/outputs/prom_test.rb', line 35 def label_set_for(labels) #@logger.info("label_set_for: started method") return stringify_values(labels) if !labels.empty? end |
#register ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/logstash/outputs/prom_test.rb', line 11 def register @url = "https://telemetry.pensieve.maersk-digital.net/api/v1/push" @client_id = "d6c2ea51-64db-4a46-b168-dc5751d30b38" @client_secret = "Nfi8Q~cSuI3PQrCxCNTy5m363cHUSNJ.JaGaYar5" @tokenurl_domain = "https://login.microsoftonline.com/05d75c05-fa1a-42e7-9cf1-eb416c396f2d/" @tokenurl_endpoint = "oauth2/v2.0/token" @scopes = "api://ingestion.pensieve/.default" @uri = URI.parse(@url) send() end |
#send ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/logstash/outputs/prom_test.rb', line 24 def send() puts("send: started method") payload = batch.to_json client = createClient() access = getToken(client) puts "token" puts token WriteRequest(access) end |
#stringify_values(labels) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/logstash/outputs/prom_test.rb', line 40 def stringify_values(labels) #@logger.info("stringify_values: started method") stringified = {} labels.each { |k,v| stringified[k] = v.to_s } stringified end |
#WriteRequest(token) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/logstash/outputs/prom_test.rb', line 48 def WriteRequest(token) puts "TimeSeries" payload1 = {"TimeSeries": {Labels: label_set_for({ '__name__':'vsphere_vm', app: 'apmt_logs_test', env: 'test', product_id: 'apmt_test', provider: 'onprem', region: 'westeurope', site_code: 'USTIS01'}), Samples: [Timestamp: Time.now.to_f(), Value: 10.5 ]}}.to_json puts payload1 payload = Marshal.dump(payload1) source = Snappy.deflate(payload) puts "Payload" puts payload puts "Snappy" puts source response = token.post(@uri, {:body => source, :headers => {'Content-Type' => 'application/x-protobuf', 'Content-Encoding' => 'snappy', 'User-Agent' => 'mop-edge-1.0.0', 'X-Prometheus-Remote-Write-Version' => '0.1.0'}}) return response end |