|
| 1 | +!!! important |
| 2 | + To save data to Pushgateway install `garf-io` with Pushgateway support |
| 3 | + |
| 4 | + ```bash |
| 5 | + pip install garf-io[pushgateway] |
| 6 | + ``` |
| 7 | + |
| 8 | + |
| 9 | +`pushgateway` writer allows you to publish `GarfReport` to a Pushgateway endpoint. |
| 10 | + |
| 11 | +/// tab | cli |
| 12 | +```bash |
| 13 | +garf query.sql --source API_SOURCE \ |
| 14 | + --output pushgateway |
| 15 | +``` |
| 16 | +/// |
| 17 | + |
| 18 | +/// tab | python |
| 19 | +```python |
| 20 | +from garf.core import report |
| 21 | +from garf.io.writers import pushgateway_writer |
| 22 | + |
| 23 | +sample_report = report.GarfReport(results=[[1]], column_names=['one']) |
| 24 | + |
| 25 | +writer = pushgateway_writer.PushgatewayWriter() |
| 26 | +writer.write(sample_report, 'grouping_key') |
| 27 | +``` |
| 28 | +/// |
| 29 | + |
| 30 | +## Parameters |
| 31 | +### endpoint |
| 32 | + |
| 33 | +By default writer pushes data to `http://localhost:9091/`. |
| 34 | +You can overwrite it with `endpoint` parameter. |
| 35 | + |
| 36 | +/// tab | cli |
| 37 | +```bash hl_lines="3" |
| 38 | +garf query.sql --source API_SOURCE \ |
| 39 | + --output pushgateway \ |
| 40 | + --pushgateway.endpoint=http://pushgateway:9091 |
| 41 | +``` |
| 42 | +/// |
| 43 | + |
| 44 | +/// tab | python |
| 45 | +```python hl_lines="7" |
| 46 | +from garf.core import report |
| 47 | +from garf.io.writers import pushgateway_writer |
| 48 | + |
| 49 | +sample_report = report.GarfReport(results=[[1]], column_names=['one']) |
| 50 | + |
| 51 | +writer = pushgateway_writer.PushgatewayWriter(endpoint="http://pushgateway:9091") |
| 52 | +writer.write(sample_report, 'grouping_key') |
| 53 | +``` |
| 54 | +/// |
| 55 | + |
| 56 | +### namespace |
| 57 | + |
| 58 | +Every metric pushes to Pushgateway is prefix with `garf_` prefix. |
| 59 | +You can overwrite it with `namespace` parameter. |
| 60 | + |
| 61 | +/// tab | cli |
| 62 | +```bash hl_lines="3" |
| 63 | +garf query.sql --source API_SOURCE \ |
| 64 | + --output pushgateway \ |
| 65 | + --pushgateway.namespace=my_garf |
| 66 | +``` |
| 67 | +/// |
| 68 | + |
| 69 | +/// tab | python |
| 70 | +```python hl_lines="7" |
| 71 | +from garf.core import report |
| 72 | +from garf.io.writers import pushgateway_writer |
| 73 | + |
| 74 | +sample_report = report.GarfReport(results=[[1]], column_names=['one']) |
| 75 | + |
| 76 | +writer = pushgateway_writer.PushgatewayWriter(namespace="my_garf") |
| 77 | +writer.write(sample_report, 'grouping_key') |
| 78 | +``` |
| 79 | +/// |
| 80 | + |
| 81 | +### job |
| 82 | + |
| 83 | +By default all metrics is pushed into `garf` job. |
| 84 | +You can overwrite it with `job` parameter. |
| 85 | + |
| 86 | +/// tab | cli |
| 87 | +```bash hl_lines="3" |
| 88 | +garf query.sql --source API_SOURCE \ |
| 89 | + --output pushgateway \ |
| 90 | + --pushgateway.job=garf_job |
| 91 | +``` |
| 92 | +/// |
| 93 | + |
| 94 | +/// tab | python |
| 95 | +```python hl_lines="7" |
| 96 | +from garf.core import report |
| 97 | +from garf.io.writers import pushgateway_writer |
| 98 | + |
| 99 | +sample_report = report.GarfReport(results=[[1]], column_names=['one']) |
| 100 | + |
| 101 | +writer = pushgateway_writer.PushgatewayWriter(job="garf_job") |
| 102 | +writer.write(sample_report, 'grouping_key') |
| 103 | +``` |
| 104 | +/// |
| 105 | + |
| 106 | +### expose_metrics_with_zero_values |
| 107 | + |
| 108 | +By default only metrics with non-zero values are pushed to Pushgateway. |
| 109 | +You can overwrite it with `expose_metrics_with_zero_values` parameter. |
| 110 | + |
| 111 | +/// tab | cli |
| 112 | +```bash hl_lines="3" |
| 113 | +garf query.sql --source API_SOURCE \ |
| 114 | + --output pushgateway \ |
| 115 | + --pushgateway.expose_metrics_with_zero_values |
| 116 | +``` |
| 117 | +/// |
| 118 | + |
| 119 | +/// tab | python |
| 120 | +```python hl_lines="7" |
| 121 | +from garf.core import report |
| 122 | +from garf.io.writers import pushgateway_writer |
| 123 | + |
| 124 | +sample_report = report.GarfReport(results=[[1]], column_names=['one']) |
| 125 | + |
| 126 | +writer = pushgateway_writer.PushgatewayWriter(expose_metrics_with_zero_values=True) |
| 127 | +writer.write(sample_report, 'grouping_key') |
| 128 | +``` |
| 129 | +/// |
| 130 | + |
| 131 | + |
| 132 | +## Query syntax |
| 133 | + |
| 134 | +In order to expose metrics to Pushgateway you need to ensure that either field name |
| 135 | +or alias should contain `metric` in it. |
| 136 | +So given the query |
| 137 | + |
| 138 | +```sql |
| 139 | +SELECT |
| 140 | + dimension.name AS name, |
| 141 | + metric.name AS field1, |
| 142 | + name AS metric_field2 |
| 143 | +FROM resource |
| 144 | +``` |
| 145 | + |
| 146 | +two metrics will be pushed to Pushgateway - `<namespace>_<job>_field1` and `<namespace>_<job>_field2`. |
0 commit comments