PsPromFile
is a cross-platform implementation to generate Prometheus .prom files in the
the prometheus exposition format.
The following metrics are currently supported
- gauge
PSPromFile allows to generate .prom files as the one below
# HELP district_compliance Defines compliancy of some sort
# TYPE district_compliance gauge
district_custom_compliance{PackageName="MyWoopyPackage"} 98
To generate the file above, use the following snippet
import-module PSPromFile -Force
#Create label
$Label = New-PrometheusLabel -Name "PackageName" -Value "MyWoopyPackage"
#Create metric
$Metric = New-PrometheusMetricGauge -Name "district_custom_compliance" -Value 98 -Label $Label
#Create promfile
$Promfile = New-PromFile -MetricName "district_compliance" -HelpText "Defines compliancy of some sort" -Type Gauge -metrics $Metric
#Writing promfile to disk in C:\Export\
Write-PromFile -PromFile $Promfile -FolderPath "C:\Export\"
Read the examples below to learn in more details how to use pspromfile
To install, simply use the command below
install-module PsPromFile
To start using the module, import the module as below
import-module PsPromFile
Below are a few examples of how metrics can be generated
In order to create a new .prom file use new-promFile
New-PromFile -MetricName "district_compliance" -HelpText "Defines some compliancy" -Type Gauge
<#
Metrics : {}
MetricName : district_compliance
HelpText : Defines some compliancy
Type : gauge
FolderPath : C:\Program Files\windows_exporter\textfile_inputs\
#>
Notice that the default export folder path is 'C:\Program Files\windows_exporter\textfile_inputs'.
If you would like to export your .prom
files to C:\MyExportFolder\
do as follows
$Promfile = New-PromFile -MetricName "district_compliance" -HelpText "Defines compliancy of some sort" -Type Gauge -FolderPath "C:\MyExportFolder\"
To create a simple metric, use the following example
New-PrometheusMetricGauge -Name "district_custom_compliance" -Value 98
<#
metricName value Type Labels
---------- ----- ---- ------
district_custom_compliance 98 gauge {}
#>
In order create a label for your metrics, use New-PrometheusLabel
New-PrometheusLabel -Name "PackageName" -Value "MyWoopyPackage"
<#
name value
---- -----
PackageName MyWoopyPackage
#>
Add a label to your metric
$Label = New-PrometheusLabel -Name "PackageName" -Value "MyWoopyPackage"
New-PrometheusMetricGauge -Name "district_custom_compliance" -Value 98 -Label $Label
<#
metricName value Type Labels
---------- ----- ---- ------
district_custom_compliance 98 gauge {PackageName="MyWoopyPackage"}
#>
Add a the metric to your .prom file
#Create a label
$Label = New-PrometheusLabel -Name "PackageName" -Value "MyWoopyPackage"
#Create a metric and add the label
$Metric = New-PrometheusMetricGauge -Name "district_custom_compliance" -Value 98 -Label $Label
#create a promfile and add the metric to it
New-PromFile -MetricName "district_compliance" -HelpText "Defines compliancy of some sort" -Type Gauge -metrics $Metric
<#
Metrics : {district_custom_compliance{PackageName="MyWoopyPackage"} 98}
MetricName : district_compliance
HelpText : Defines compliancy of some sort
Type : gauge
FolderPath : C:\Program Files\windows_exporter\textfile_inputs\
#>
Write the metric to disk
#Create the promFile Object
$PromFile = New-PromFile -MetricName "district_compliance" -HelpText "Defines compliancy of some sort" -Type Gauge -metrics $Metric
#Write the promFile object to disk to an alternate location
$ExportPath = "C:\MyExportFolder"
Write-PromFile -PromFile $promFile -FolderPath $ExportPath
The different metric types are documented here