Added location storage and handling in Controller and Load Balancer
This commit is contained in:
		
							parent
							
								
									0b6710e4eb
								
							
						
					
					
						commit
						45b5ea30ac
					
				
					 3 changed files with 17 additions and 25 deletions
				
			
		src
|  | @ -551,6 +551,11 @@ void Controller::handleAPICommands(JSON::Value &Request, JSON::Value &Response){ | |||
|       Controller::prometheus = out["prometheus"].asStringRef(); | ||||
|     } | ||||
|     if (in.isMember("defaultStream")){out["defaultStream"] = in["defaultStream"];} | ||||
|     if (in.isMember("location") && in["location"].isObject()){ | ||||
|       out["location"]["lat"] = in["location"]["lat"].asDouble(); | ||||
|       out["location"]["lon"] = in["location"]["lon"].asDouble(); | ||||
|       out["location"]["name"] = in["location"]["name"].asStringRef(); | ||||
|     } | ||||
|   } | ||||
|   if (Request.isMember("bandwidth")){ | ||||
|     if (Request["bandwidth"].isObject()){ | ||||
|  |  | |||
|  | @ -1729,6 +1729,13 @@ void Controller::handlePrometheus(HTTP::Parser &H, Socket::Connection &conn, int | |||
|       resp["bw"].append(servUpBytes); | ||||
|       resp["bw"].append(servDownBytes); | ||||
|       resp["bwlimit"] = bwLimit; | ||||
|       if (Storage["config"].isMember("location") && Storage["config"]["location"].isMember("lat") && Storage["config"]["location"].isMember("lon")){ | ||||
|         resp["loc"]["lat"] = Storage["config"]["location"]["lat"].asDouble(); | ||||
|         resp["loc"]["lon"] = Storage["config"]["location"]["lon"].asDouble(); | ||||
|         if (Storage["config"]["location"].isMember("name")){ | ||||
|           resp["loc"]["name"] = Storage["config"]["location"]["name"].asStringRef(); | ||||
|         } | ||||
|       } | ||||
|       resp["obw"].append(servUpOtherBytes); | ||||
|       resp["obw"].append(servDownOtherBytes); | ||||
| 
 | ||||
|  |  | |||
|  | @ -289,6 +289,11 @@ public: | |||
|     tthread::lock_guard<tthread::mutex> guard(*hostMutex); | ||||
|     cpu = d["cpu"].asInt(); | ||||
|     if (d.isMember("bwlimit") && d["bwlimit"].asInt()){availBandwidth = d["bwlimit"].asInt();} | ||||
|     if (d.isMember("loc")){ | ||||
|       if (d["loc"]["lat"].asDouble() != servLati){servLati = d["loc"]["lat"].asDouble();} | ||||
|       if (d["loc"]["lon"].asDouble() != servLongi){servLongi = d["loc"]["lon"].asDouble();} | ||||
|       if (d["loc"]["name"].asStringRef() != servLoc){servLoc = d["loc"]["name"].asStringRef();} | ||||
|     } | ||||
|     int64_t nRamMax = d["mem_total"].asInt(); | ||||
|     int64_t nRamCur = d["mem_used"].asInt(); | ||||
|     int64_t nShmMax = d["shm_total"].asInt(); | ||||
|  | @ -665,31 +670,6 @@ void handleServer(void *hostEntryPointer){ | |||
| 
 | ||||
|   HTTP::Downloader DL; | ||||
| 
 | ||||
|   if (DL.get(HTTP::URL("http://api.ipstack.com/" + url.host + "?access_key=05eb21db3983dec4cd6d22131ec0a40d&format=1")) && | ||||
|       DL.isOk()){ | ||||
|     JSON::Value &gDet = entry->details->geoDetails; | ||||
|     INFO_MSG("Location: %s", DL.data().c_str()); | ||||
|     gDet = JSON::fromString(DL.data()); | ||||
|     INFO_MSG("Location: %s", gDet.toString().c_str()); | ||||
|     if (gDet && gDet.isMember("latitude") && gDet.isMember("longitude")){ | ||||
|       entry->details->servLati = gDet["latitude"].asDouble(); | ||||
|       entry->details->servLongi = gDet["longitude"].asDouble(); | ||||
|       std::stringstream loc; | ||||
|       if (gDet.isMember("country_name")){ | ||||
|         if (gDet.isMember("city") && gDet["city"].asString().size()){ | ||||
|           entry->details->servLoc = gDet["city"].asString() + ", " + gDet["country_name"].asString(); | ||||
|         }else{ | ||||
|           entry->details->servLoc = gDet["country_name"].asString(); | ||||
|         } | ||||
|         INFO_MSG("%s is in %s", url.host.c_str(), entry->details->servLoc.c_str()); | ||||
|       }else{ | ||||
|         INFO_MSG("%s is at %f, %f", url.host.c_str(), entry->details->servLati, entry->details->servLongi); | ||||
|       } | ||||
|     } | ||||
|   }else{ | ||||
|     WARN_MSG("Could not reach location server for %s", url.host.c_str()); | ||||
|   } | ||||
| 
 | ||||
|   while (cfg->is_active && (entry->state != STATE_GODOWN)){ | ||||
|     if (DL.get(url) && DL.isOk()){ | ||||
|       JSON::Value servData = JSON::fromString(DL.data()); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Thulinma
						Thulinma