std::string service_properties_writer::write(const service_properties& properties, const service_properties_includes& includes) { std::ostringstream outstream; initialize(outstream); write_start_element(xml_service_properties); if (includes.logging()) { write_start_element(xml_service_properties_logging); write_logging(properties.logging(), outstream); write_end_element(); } if (includes.hour_metrics()) { write_start_element(xml_service_properties_hour_metrics); write_metrics(properties.hour_metrics(), outstream); write_end_element(); } if (includes.minute_metrics()) { write_start_element(xml_service_properties_minute_metrics); write_metrics(properties.minute_metrics(), outstream); write_end_element(); } if (includes.cors()) { write_start_element(xml_service_properties_cors); for (auto iter = properties.cors().cbegin(); iter != properties.cors().cend(); ++iter) { write_start_element(xml_service_properties_cors_rule); write_cors_rule(*iter, outstream); write_end_element(); } write_end_element(); } if (!properties.default_service_version().empty()) { write_element(xml_service_properties_default_service_version, properties.default_service_version()); } finalize(); return outstream.str(); }
TIMESTAMP metrics::postsync(TIMESTAMP t0, TIMESTAMP t1) { DATETIME dt; int returnval; bool metrics_written; OBJECT *hdr = OBJECTHDR(this); FILE *FPVal; //Initialization if (curr_time == TS_NEVER) { //Update time value trackers if (metric_interval == 0) //No metric update interval - ensure never goes off { next_metric_interval = TS_NEVER; } else //OK, proceed { next_metric_interval = t1 + metric_interval; } next_report_interval = t1 + report_interval; next_annual_interval = t1 + 31536000; //t1 + 365 days of seconds //Outputs in CSV format - solves issue of column alignment - assuming we want event log if (report_event_log == true) { //Open the file FPVal = fopen(report_file,"at"); //Figure out when we are, roughly (use t1 here) gl_localtime(t1,&dt); //Write header stuffs fprintf(FPVal,"Events for year starting at %04d-%02d-%02d %02d:%02d:%02d\n",dt.year,dt.month,dt.day,dt.hour,dt.minute,dt.second); //Determine which header to write if (secondary_interruptions_count == true) { fprintf(FPVal,"Annual Event #,Metric Interval Event #,Starting DateTime (YYYY-MM-DD hh:mm:ss),Ending DateTime (YYYY-MM-DD hh:mm:ss),Object type,Object Name,Inducing Object,\"Protective\" Device,Desired Fault type,Implemented Fault Type,Number customers affected,Secondary number of customers affected\n"); } else //Nope { fprintf(FPVal,"Annual Event #,Metric Interval Event #,Starting DateTime (YYYY-MM-DD hh:mm:ss),Ending DateTime (YYYY-MM-DD hh:mm:ss),Object type,Object Name,Inducing Object,\"Protective\" Device,Desired Fault type,Implemented Fault Type,Number customers affected\n"); } //Close the file handle fclose(FPVal); } //First run - t1 = t0 (t0 is zero) curr_time = t1; } //Only worry about checks once per timestep if (curr_time != t0) { //Reset temp flag metrics_written = false; if (t0 >= next_report_interval) { //Write the output metric values write_metrics(); //Update variable metrics_written = true; //Update the interval next_report_interval = t0 + report_interval; } //See if it is time to write an update if (t0 >= next_metric_interval) { //See if the metrics were written - if not, dumb them again for posterity if (metrics_written == false) write_metrics(); //Update the interval next_metric_interval = t0 + metric_interval; //Reset the stat variables returnval = ((int (*)(OBJECT *, OBJECT *))(*reset_interval_func))(hdr,module_metrics_obj); if (returnval != 1) //See if it failed { GL_THROW("Failed to reset interval metrics for %s by metrics:%s",module_metrics_obj->name,hdr->name); //Defined above } //Reset the counter metric_interval_event_count = 0; //Indicate a new interval is going on - if we aren't a year (otherwise it happens below) if ((report_event_log == true) && (metric_equal_annual == false)) { //Open the file FPVal = fopen(report_file,"at"); //Figure out when we are gl_localtime(t0,&dt); //Write header stuffs fprintf(FPVal,"\nNew Metric Interval started at %04d-%02d-%02d %02d:%02d:%02d\n\n",dt.year,dt.month,dt.day,dt.hour,dt.minute,dt.second); //Close the file handle fclose(FPVal); } }//End interval metrics update //See if we've exceeded a year if (t0 >= next_annual_interval) { //See if we need to write the file - if "metric_interval" just went off, no sense writing the same thing again if (metrics_written == false) write_metrics(); //Update interval next_annual_interval = t0 + 31536000; //t0 + 365 days of seconds //Reset the stats returnval = ((int (*)(OBJECT *, OBJECT *))(*reset_annual_func))(hdr,module_metrics_obj); if (returnval != 1) //See if it failed { GL_THROW("Failed to reset annual metrics for %s by metrics:%s",module_metrics_obj->name,hdr->name); //Defined above } //Reset the counter annual_interval_event_count = 0; //Indicate a new interval is going on if (report_event_log == true) { //Open the file FPVal = fopen(report_file,"at"); //Figure out when we are gl_localtime(t0,&dt); //Write header stuffs fprintf(FPVal,"\nNew Annual Interval started at %04d-%02d-%02d %02d:%02d:%02d\n\n",dt.year,dt.month,dt.day,dt.hour,dt.minute,dt.second); //Close the file handle fclose(FPVal); } }//End annual update //Update tracking variable curr_time = t0; } //See who to return if (next_metric_interval < next_annual_interval) { if (next_metric_interval < next_report_interval) return -next_metric_interval; else return -next_report_interval; } else { if (next_annual_interval < next_report_interval) return -next_annual_interval; else return -next_report_interval; } }