I am doing a collage project that using Laravel, Prometheus and grafana dashboard. I'm supposing to enter the user data to a JQuery Datatable and send those data to a Laravel controller as JSON array. then I need to Dump that associative JSON array to a .yml file (Prometheus config file) from the Laravel Controller. But, The problem is .yml file should have some content structure that help to read it from grafana dashboard. How to do that.
And this is the way i tried.
$inData = array (
["foo"=>'node_exporter_metrics', "time"=>"5s", "bar"=>"123456"],
["foo"=>'node_exporter_metrics_2', "time"=>"5s", "bar"=>"654321"],
);
$json = array ();
$outData = array ();
foreach ($inData as &$value) {
$entry = array (
'job_name' => $value['foo'],
"scrape_interval" => $value['time'],
"static_configs" =>
[
0 =>
[
'targets' =>
[
0 => $value['bar'],
]
]
]
);
array_push($outData, $entry);
}
;
$yaml = Yaml::dump($outData,3);
file_put_contents('config.yaml', $yaml);
I've mentioned below what is the structure I needed in .yml file. But above method did not build the content structure as it is.
- job_name: 'node_exporter_metrics'
scrape_interval: 5s
static_configs:
- targets: ['172.16.155.60:9100']
- job_name: 'node_exporter_metrics_2'
scrape_interval: 5s
static_configs:
- targets: ['172.16.189.68:9112']
It is must to having this content structure with indentation to read it from grafana.
I will send parameters for "job name", "scrape_interval", "targets" through the JQuery DataTable into Laravel Controller.
Please can someone help me to do this work...