| 1 | # CSV formatter |
| 2 | |
| 3 | The CSV formatter presents [results of database queries](/src/web/api/queries/README.md) in the following formats: |
| 4 | |
| 5 | | format|content type|description| |
| 6 | | :----:|:----------:|:----------| |
| 7 | | `csv`|text/plain|a text table, comma separated, with a header line (dimension names) and `\r\n` at the end of the lines| |
| 8 | | `csvjsonarray`|application/json|a JSON array, with each row as another array (the first row has the dimension names)| |
| 9 | | `tsv`|text/plain|like `csv` but TAB is used instead of comma to separate values (MS Excel flavor)| |
| 10 | | `html`|text/html|an html table| |
| 11 | | `markdown`|text/plain|markdown table| |
| 12 | |
| 13 | In all formats the date and time is the first column. |
| 14 | |
| 15 | The CSV formatter respects the following API `&options=`: |
| 16 | |
| 17 | | option|supported|description| |
| 18 | |:----:|:-------:|:----------| |
| 19 | | `nonzero`|yes|to return only the dimensions that have at least a non-zero value| |
| 20 | | `flip`|yes|to return the rows older to newer (the default is newer to older)| |
| 21 | | `seconds`|yes|to return the date and time in unix timestamp| |
| 22 | | `ms`|yes|to return the date and time in unit timestamp as milliseconds| |
| 23 | | `percent`|yes|to replace all values with their percentage over the row total| |
| 24 | | `abs`|yes|to turn all values positive| |
| 25 | | `null2zero`|yes|to replace gaps with zeros (the default prints the string `null`| |
| 26 | |
| 27 | ## Examples |
| 28 | |
| 29 | Get the system total bandwidth for all physical network interfaces, over the last hour, |
| 30 | in 6 rows (one for every 10 minutes), in `csv` format: |
| 31 | |
| 32 | Netdata always returns bandwidth in `kilobits`. |
| 33 | |
| 34 | ```bash |
| 35 | # curl -Ss 'https://registry.my-netdata.io/api/v1/data?chart=system.net&format=csv&after=-3600&group=sum&points=6&options=abs' |
| 36 | time,received,sent |
| 37 | 2018-10-26 23:50:00,90214.67847,215137.79762 |
| 38 | 2018-10-26 23:40:00,90126.32286,238587.57522 |
| 39 | 2018-10-26 23:30:00,86061.22688,213389.23526 |
| 40 | 2018-10-26 23:20:00,85590.75164,206129.01608 |
| 41 | 2018-10-26 23:10:00,83163.30691,194311.77384 |
| 42 | 2018-10-26 23:00:00,85167.29657,197538.07773 |
| 43 | ``` |
| 44 | |
| 45 | --- |
| 46 | |
| 47 | Get the max RAM used by the SQL server and any cron jobs, over the last hour, in 2 rows (one for every 30 |
| 48 | minutes), in `tsv` format, and format the date and time as unix timestamp: |
| 49 | |
| 50 | Netdata always returns memory in `MB`. |
| 51 | |
| 52 | ```bash |
| 53 | # curl -Ss 'https://registry.my-netdata.io/api/v1/data?chart=apps.mem&format=tsv&after=-3600&group=max&points=2&options=nonzero,seconds&dimensions=sql,cron' |
| 54 | time sql cron |
| 55 | 1540598400 61.95703 0.25 |
| 56 | 1540596600 61.95703 0.25 |
| 57 | ``` |
| 58 | |
| 59 | --- |
| 60 | |
| 61 | Get an HTML table of the last 4 values (4 seconds) of system CPU utilization: |
| 62 | |
| 63 | Netdata always returns CPU utilization as `%`. |
| 64 | |
| 65 | ```bash |
| 66 | # curl -Ss 'https://registry.my-netdata.io/api/v1/data?chart=system.cpu&format=html&after=-4&options=nonzero' |
| 67 | <html> |
| 68 | <center> |
| 69 | <table border="0" cellpadding="5" cellspacing="5"> |
| 70 | <tr><td>time</td><td>softirq</td><td>user</td><td>system</td></tr> |
| 71 | <tr><td>2018-10-27 00:16:07</td><td>0.25</td><td>1</td><td>0.75</td></tr> |
| 72 | <tr><td>2018-10-27 00:16:06</td><td>0</td><td>1.0025063</td><td>0.5012531</td></tr> |
| 73 | <tr><td>2018-10-27 00:16:05</td><td>0</td><td>1</td><td>0.75</td></tr> |
| 74 | <tr><td>2018-10-27 00:16:04</td><td>0</td><td>1.0025063</td><td>0.7518797</td></tr> |
| 75 | </table> |
| 76 | </center> |
| 77 | </html> |
| 78 | ``` |
| 79 | |
| 80 | This is how it looks when rendered by a web browser: |
| 81 | |
| 82 |  |
| 83 | |
| 84 | --- |
| 85 | |
| 86 | Get a JSON array with the average bandwidth rate of the mysql server, over the last hour, in 6 values |
| 87 | (one every 10 minutes), and return the date and time in milliseconds: |
| 88 | |
| 89 | Netdata always returns bandwidth rates in `kilobits/s`. |
| 90 | |
| 91 | ```bash |
| 92 | # curl -Ss 'https://registry.my-netdata.io/api/v1/data?chart=mysql_local.net&format=csvjsonarray&after=-3600&points=6&group=average&options=abs,ms' |
| 93 | [ |
| 94 | ["time","in","out"], |
| 95 | [1540599600000,0.7499986,120.2810185], |
| 96 | [1540599000000,0.7500019,120.2815509], |
| 97 | [1540598400000,0.7499999,120.2812319], |
| 98 | [1540597800000,0.7500044,120.2819634], |
| 99 | [1540597200000,0.7499968,120.2807337], |
| 100 | [1540596600000,0.7499988,120.2810527] |
| 101 | ] |
| 102 | ``` |
| 103 | |
| 104 | --- |
| 105 | |
| 106 | Get the number of processes started per minute, for the last 10 minutes, in `markdown` format: |
| 107 | |
| 108 | ```bash |
| 109 | # curl -Ss 'https://registry.my-netdata.io/api/v1/data?chart=system.forks&format=markdown&after=-600&points=10&group=sum' |
| 110 | time | started |
| 111 | :---: |:---: |
| 112 | 2018-10-27 03:52:00| 245.1706149 |
| 113 | 2018-10-27 03:51:00| 152.6654636 |
| 114 | 2018-10-27 03:50:00| 163.1755789 |
| 115 | 2018-10-27 03:49:00| 176.1574766 |
| 116 | 2018-10-27 03:48:00| 178.0137076 |
| 117 | 2018-10-27 03:47:00| 183.8306543 |
| 118 | 2018-10-27 03:46:00| 264.1635621 |
| 119 | 2018-10-27 03:45:00| 205.001551 |
| 120 | 2018-10-27 03:44:00| 7026.9852167 |
| 121 | 2018-10-27 03:43:00| 205.9904794 |
| 122 | ``` |
| 123 | |
| 124 | And this is how it looks when formatted: |
| 125 | |
| 126 | | time | started | |
| 127 | |:--:|:-----:| |
| 128 | | 2018-10-27 03:52:00 | 245.1706149 | |
| 129 | | 2018-10-27 03:51:00 | 152.6654636 | |
| 130 | | 2018-10-27 03:50:00 | 163.1755789 | |
| 131 | | 2018-10-27 03:49:00 | 176.1574766 | |
| 132 | | 2018-10-27 03:48:00 | 178.0137076 | |
| 133 | | 2018-10-27 03:47:00 | 183.8306543 | |
| 134 | | 2018-10-27 03:46:00 | 264.1635621 | |
| 135 | | 2018-10-27 03:45:00 | 205.001551 | |
| 136 | | 2018-10-27 03:44:00 | 7026.9852167 | |
| 137 | | 2018-10-27 03:43:00 | 205.9904794 | |
| 138 | |
| 139 |