manuelluis / jsrrdgraph

javascript rrdgraph
61 stars 12 forks source link

Fix flags parsing (options without a value) #11

Closed Lekensteyn closed 10 years ago

Lekensteyn commented 10 years ago

Also fix some typos and white-space issues. Reported at https://github.com/pommi/CGP/issues/88

Lekensteyn commented 10 years ago

By the way, this issue occured because I changed CGP to always include quotes for its options. Previously it would have -E -w 80, after the quoting changes has become "-E" "-w" "80" and obviously '"' != '-' and thus the parser thinks it sees a value.

The cmdline parser is very fragile and does not cope well with deliberate malformed strings, but that should not be an issue most of the time.

manuelluis commented 10 years ago

Thank you.

The parser of the command line is a toy, it was just an easy way to test the functionality.

I think that the interface for the definition of the graph should be a json object, like the example in the code or something in the middle like this:

{
  "slope_mode": true,
  "end": "1305798665",
  "start": "end-1h",
  "width": 600,
  "height": 120,
  "title": "Load",
  "vertical_label": "System load",

  "data": [
    "DEF:s_avg=data/load.rrd:shortterm:AVERAGE",
    "DEF:s_min=data/load.rrd:shortterm:MIN",
    "DEF:s_max=data/load.rrd:shortterm:MAX",
    "DEF:m_avg=data/load.rrd:midterm:AVERAGE",
    "DEF:m_min=data/load.rrd:midterm:MIN",
    "DEF:m_max=data/load.rrd:midterm:MAX",
    "DEF:l_avg=data/load.rrd:longterm:AVERAGE",
    "DEF:l_min=data/load.rrd:longterm:MIN",
    "DEF:l_max=data/load.rrd:longterm:MAX"
  ],

  "graph": [
    "AREA:s_max#B7EFB7",
    "AREA:s_min#FFFFFF",
    "LINE1:s_avg#00E000: 1m average",
    "GPRINT:s_min:MIN:%4.2lf Min,",
    "GPRINT:s_avg:AVERAGE:%4.2lf Avg,",
    "GPRINT:s_max:MAX:%4.2lf Max,",
    "GPRINT:s_avg:LAST:%4.2lf Last\n",
    "LINE1:m_avg#0000FF: 5m average",
    "GPRINT:m_min:MIN:%4.2lf Min,",
    "GPRINT:m_avg:AVERAGE:%4.2lf Avg,",
    "GPRINT:m_max:MAX:%4.2lf Max,",
    "GPRINT:m_avg:LAST:%4.2lf Last\n",
    "LINE1:l_avg#FF0000:15m average",
    "GPRINT:l_min:MIN:%4.2lf Min,",
    "GPRINT:l_avg:AVERAGE:%4.2lf Avg,",
    "GPRINT:l_max:MAX:%4.2lf Max,",
    "GPRINT:l_avg:LAST:%4.2lf Last\n"
  ]
}

Something more in the line of a web interface.