send metrics from windows server to pushgateway prometheus

74 Views Asked by At

i have configured pushgateway which is up and running. I have windows server i have configured script which would count rest api numbers from log (just 4 digit numbers) and save it in text file. I wanted to send this metric to pushgateway so that i can get grafana dashboard created from prometheus as database. I am getting error, what am i missing. $number=1234

first method 
$number = Get-Content -Path "C:\path\to\your\numberfile.txt" -Raw
$metricString = "custom_metric $number 1"

echo "$metricString" `r`n | Invoke-WebRequest -Uri "http://localhost:9091/metrics/job/your_job" -Method Post

---------------------------------------------------------
second method 
$number = Get-Content -Path "C:\path\to\your\numberfile.txt" -Raw
$metricString = "custom_metric $number 1"

# Send the metric string via Invoke-WebRequest
$metricString | Invoke-WebRequest -Uri "http://localhost:9091/metrics/job/your_job" -Method Post

when i run this i get error "text format parsing error in line 1, i found this informative command on other issue,

Send metrics with pushgateway (Prometheus) using windows console

my query is if i want to run that command echo then invoke how would i do this, when i try to run echo command then hit shift+ enter go to new line then run | invoke command i am able to send test metric to pushgateway. how would i do this via script

tried adding 'n' or 'r''n etc to getinto new line still now luck can some one please help

also how do i send instance Ip while sending alert??

provide more updates above

1

There are 1 best solutions below

0
valyala On

Prometheus pushgateway accepts metrics in the following format:

metric_name{optional_labels} metric_value

Where:

  • metric_name is the name of the metric. For example, temperature or requests_total
  • {optional_labels} is optional labels for the given metric. For example, {path="/foo",method="POST"}`
  • meteic_value is numeric value for the metric. For example, 123.456.

A single request to pushgateway can contain multiple metrics. They must be delimited by newline aka \n char. For example:

requests_total{path="foo"} 123
requests_total{path="/bar/a/b"} 456

Note also that pushgateway doesn't store all the pushed values for the same time series - it just keeps the last pushed sample and returns it to Prometheus when it scrapes the pushgateway. If you want storing all the samples, then try using /api/v1/import/prometheus endpoint at VictoriaMetrics - this is Prometheus-like monitoring solution I work on.

P.S. See these docs for details on Prometheus data model and key concepts.