Browse files

Get the zpool status parsed and displayed properly in the GUI now. It…

… still needs testing for all the various cases (scrub running/finished, resilver running/finished, disks in non-ONLINE state) to make sure that it is all getting parsed correctly.
  • Loading branch information...
1 parent 34e4929 commit 233d0860603537dbe17e31987fcc629980812be6 @beanpole135 beanpole135 committed Oct 15, 2013
Showing with 79 additions and 43 deletions.
  1. +1 −1 lp-gui/LPBackend.cpp
  2. +3 −2 lp-gui/LPContainers.h
  3. +66 −33 lp-gui/LPGUtils.cpp
  4. +8 −6 lp-gui/LPMain.cpp
  5. +1 −1 lp-gui/LPMain.ui
View
2 lp-gui/LPBackend.cpp
@@ -63,7 +63,7 @@ QStringList LPBackend::listLPSnapshots(QString dataset){
QStringList out = LPBackend::getCmdOutput(cmd);
//Now process the output
QStringList list;
- for(int i=out.length()-1; i>=0; i--){ //go in reverse order for proper time format (newest first)
+ for(int i=0; i<out.length(); i++){ //oldest ->newest
if(out[i].startsWith(dataset+"@")){
QString snap = out[i].section("@",1,3).section(" ",0,0).simplified();;
if(!snap.isEmpty()){ list << snap; }
View
5 lp-gui/LPContainers.h
@@ -12,9 +12,10 @@ class LPDataset{
~LPDataset(){}
//Information needed on each dataset
- QString replicationStatus, mirrorStatus, errorStatus;
+ QString finishedStatus, runningStatus, errorStatus;
QString latestSnapshot;
- QString numberOfDisks;
+ QStringList harddisks;
+ QStringList harddiskStatus;
QString poolStatus;
QHash<QString,QStringList> subsetHash; //<subset, snapshot list> (complete dataset name should be <ds><subset>)
View
99 lp-gui/LPGUtils.cpp
@@ -23,46 +23,79 @@ LPDataset LPGUtils::loadPoolData(QString zpool){
int index = snaps.indexOf(lpsnaps[s]);
if(index > -1){ subsnaps << lpsnaps[s]; snaps.removeAt(index); }
}
- //Now list all the other available snapshots (no certain ordering)
- if(!snaps.isEmpty()){
+ /*//Now list all the other available snapshots (no certain ordering)
+ if(!snaps.isEmpty()){try
subsnaps << "--"; //so we know that this is a divider between the sections
subsnaps << snaps;
- }
+ }*/
DSC.subsetHash.insert(subsets[i],subsnaps); //add it to the internal container hash
}
}
- //Get the time for the latest life-preserver snapshot (and total number)
- /*
- //Find the index for the current list
- int ci = 0;
- while(ci < CLIST.length()){
- if(CLIST[ci].startsWith(zpool+":::")){ break; }
- else{ ci++; }
- }
- if(CLIST.isEmpty()){ ci = -1; } //catch for empty list
- if(DSC.subsetHash.size() < 1){
- DSC.numberOfSnapshots = "0";
- DSC.latestSnapshot= "";
- }else{
- DSC.numberOfSnapshots = QString::number(lpsnaps.length());
- if(lpsnaps.isEmpty()){ DSC.latestSnapshot=""; }
- else if(ci > -1 && ci < CLIST.length()){
- QString sna = CLIST[ci].section(":::",1,1);
- if(sna != "-"){ DSC.latestSnapshot= sna; }
- else{ DSC.latestSnapshot = ""; }
- }else{ DSC.latestSnapshot=lpsnaps[0]; }
+ //Parse "zpool status <pool>"
+ QStringList zstat = LPBackend::getCmdOutput("zpool status "+zpool);
+ //qDebug() << "zpool status "+zpool+":\n" << zstat.join("\n");
+ bool atheader=false;
+ QStringList disks, diskstates, running, errors, finished;
+ for(int i=0; i<zstat.length(); i++){
+ if(zstat[i].isEmpty()){ continue; }
+ else if(zstat[i].startsWith(" scan:")){
+ QString line = zstat[i].section(":",1,50).replace("\t"," ").simplified();
+ if(line.contains("scrub repaired ")){
+ QString timestamp = line.section(" ",9,13,QString::SectionSkipEmpty);
+ QString numerrors = line.section(" ",6,6,QString::SectionSkipEmpty);
+ finished << QString(QObject::tr("Scrub Finished: %1 (%2 errors)")).arg(timestamp, numerrors);
+ }else if(line.contains("scrub")){
+ QString timestamp = line.section(" ",4,8,QString::SectionSkipEmpty);
+ running << QString(QObject::tr("Scrub Started: %1")).arg(timestamp);
+ }else if(line.contains("resilvered")){
+ QString timestamp = line.section(" ",9,13,QString::SectionSkipEmpty);
+ QString numerrors = line.section(" ",6,6,QString::SectionSkipEmpty);
+ finished << QString(QObject::tr("Resilver Finished: %1 (%2 errors)")).arg(timestamp, numerrors);
+ }
+ }else if(zstat[i].contains("NAME") && zstat[i].contains("STATE") && zstat[i].contains("READ") ){
+ //qDebug() <<"Found header";
+ atheader=true;
+ }else if(zstat[i].startsWith("errors:")){
+ atheader=false;
+ }else if(atheader){
+ QString line = zstat[i].replace("\t"," ").simplified();
+ QString dev = line.section(" ",0,0,QString::SectionSkipEmpty);
+ QString state = line.section(" ",1,1,QString::SectionSkipEmpty);
+ //qDebug() << "Found device:" << dev << state;
+ if(dev == zpool){
+ DSC.poolStatus = state;
+ }else if(line.contains("(resilvering)")){
+ disks << dev; diskstates << state; //record this disk and state
+ running << QString(QObject::tr("%1: Currently Resilvering")).arg(dev);
+ }else{
+ disks << dev; diskstates << state; //record this disk and state
+ if(state != "ONLINE"){
+ errors << QString(QObject::tr("%1: %2")).arg(dev, state);
+ }
+ }
+ }
}
- //List the replication status
- if(RLIST.contains(zpool) && (ci > -1)){
- QString rep = CLIST[ci].section(":::",2,2);
- if(rep != "-"){ DSC.latestReplication = rep; }
- else{ DSC.latestReplication= QObject::tr("Enabled"); }
- }else{
- DSC.latestReplication= QObject::tr("Disabled");
+ //Now get the latest Snapshot/Replication information
+ QStringList lpstat = LPBackend::listCurrentStatus();
+ for(int i=0; i<lpstat.length(); i++){
+ if(lpstat[i].section(":::",0,0) == zpool){
+ QString lastSnap = lpstat[i].section(":::",1,1);
+ QString lastRep = lpstat[i].section(":::",2,2);
+ if(lastSnap=="-"){ DSC.latestSnapshot = QObject::tr("No Snapshots Available"); }
+ else{ DSC.latestSnapshot = lastSnap; }
+ if(lastRep!="-"){
+ finished << QString(QObject::tr("Latest Replication: %1")).arg(lastRep);
+ }else if(LPBackend::listReplicationTargets().contains(zpool) ){
+ errors << QObject::tr("No Successful Replication");
+ }
+ }
}
- */
- //Now parse the "zpool status <zpool>" output
-
+ //Now save the info to the dataset
+ DSC.harddisks = disks;
+ DSC.harddiskStatus = diskstates;
+ DSC.errorStatus = errors.join("\n");
+ DSC.runningStatus = running.join("\n");
+ DSC.finishedStatus = finished.join("\n");
//Return the dataset
return DSC;
}
View
14 lp-gui/LPMain.cpp
@@ -145,16 +145,16 @@ void LPMain::updateTabs(){
POOLDATA = LPGUtils::loadPoolData(ui->combo_pools->currentText());
//Now list the status information
ui->label_status->setText(POOLDATA.poolStatus);
- ui->label_numdisks->setText(POOLDATA.numberOfDisks);
+ ui->label_numdisks->setText( QString::number(POOLDATA.harddisks.length()) );
ui->label_latestsnapshot->setText(POOLDATA.latestSnapshot);
- if(POOLDATA.replicationStatus.isEmpty()){ ui->label_replication->setVisible(false); }
+ if(POOLDATA.finishedStatus.isEmpty()){ ui->label_replication->setVisible(false); }
else{
- ui->label_replication->setText(POOLDATA.replicationStatus);
+ ui->label_replication->setText(POOLDATA.finishedStatus);
ui->label_replication->setVisible(true);
}
- if(POOLDATA.mirrorStatus.isEmpty()){ ui->label_mirror->setVisible(false); }
+ if(POOLDATA.runningStatus.isEmpty()){ ui->label_mirror->setVisible(false); }
else{
- ui->label_mirror->setText(POOLDATA.mirrorStatus);
+ ui->label_mirror->setText(POOLDATA.runningStatus);
ui->label_mirror->setVisible(true);
}
if(POOLDATA.errorStatus.isEmpty()){ ui->label_errors->setVisible(false); }
@@ -180,6 +180,8 @@ void LPMain::updateTabs(){
ui->menuDelete_Snapshot->addAction(snaps[i]);
}
ui->menuDelete_Snapshot->setEnabled( !ui->menuDelete_Snapshot->isEmpty() );
+ //Now update the disk menu items
+
}else{
//No Pool selected
ui->label_numdisks->clear();
@@ -217,7 +219,7 @@ void LPMain::updateDataset(){
void LPMain::updateSnapshot(){
int sval = ui->slider_snapshots->value();
QStringList snaps = POOLDATA.snapshots(ui->combo_datasets->currentText());
- qDebug() << "Update Snapshot";
+ //qDebug() << "Update Snapshot";
//Update the previous/next buttons
if(sval == ui->slider_snapshots->minimum() ){ ui->push_prevsnap->setEnabled(false); }
else{ ui->push_prevsnap->setEnabled(true); }
View
2 lp-gui/LPMain.ui
@@ -83,7 +83,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
- <number>1</number>
+ <number>0</number>
</property>
<widget class="QWidget" name="tab_status">
<attribute name="icon">

0 comments on commit 233d086

Please sign in to comment.