diff --git a/submit_metric_with_multible_hosts/README.md b/submit_metric_with_multible_hosts/README.md new file mode 100644 index 0000000..dae28aa --- /dev/null +++ b/submit_metric_with_multible_hosts/README.md @@ -0,0 +1,19 @@ +# code generation Icon + +## What does this script do + +When using the V2 metric submission API endpoint (https://docs.datadoghq.com/api/latest/metrics/#submit-metrics) users cannot specify multiple hots tags on the same `series` parameter. + +Instead, we need to define a seperate `series` for each hostname. + +This could be a tedious process especially if we have a large number of hosts with different metric value and timestamps. + +`generate.sh` will automatically create a ready to use script that contains the proper API call to submit multiple data points for multiple hosts in different timestamps. + +## Instructions + +Before launching the `generate.sh` script, make sure to fill up the `data.csv` file with the list of host names, their metric values and their timestamp accordingly. + +Once done you can launch the `generate.sh` script which will automatically generate another script `send.sh` which could be executed to submit the metrics. + +> **_NOTE:_** Please make sure to replace the API key and the endpoint URL accordingly. diff --git a/submit_metric_with_multible_hosts/data.csv b/submit_metric_with_multible_hosts/data.csv new file mode 100644 index 0000000..47bf73f --- /dev/null +++ b/submit_metric_with_multible_hosts/data.csv @@ -0,0 +1,5 @@ +hostname,value,timestamp +A_host,6,1689773651 +B_host,4,1689773651 +C_host,2,1689773651 +D_host,2.5,1689773651 diff --git a/submit_metric_with_multible_hosts/generate.sh b/submit_metric_with_multible_hosts/generate.sh new file mode 100644 index 0000000..2ed586a --- /dev/null +++ b/submit_metric_with_multible_hosts/generate.sh @@ -0,0 +1,45 @@ +cat > send.sh <> send.sh <> send.sh +else +echo "," >> send.sh +fi +i=$((i+1)) +done < <(tail -n +2 data.csv) +echo "}" >> send.sh +echo "EOF" >> send.sh +bash send.sh