1 /* 2 * P2PFaaS - A framework for FaaS Load Balancing 3 * Copyright (c) 2019 - 2022. Gabriele Proietti Mattia <pm.gabriele@outlook.com> 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 */ 18 19 package api_monitoring 20 21 import ( 22 "net/http" 23 "scheduler/config" 24 "scheduler/memdb" 25 "scheduler/queue" 26 "strconv" 27 ) 28 29 const ApiMonitoringLoadHeaderKey = "X-P2PFaaS-Load" 30 const ApiMonitoringMaxLoadHeaderKey = "X-P2PFaaS-MaxLoad" 31 const ApiMonitoringQueueLengthHeaderKey = "X-P2PFog-Queue-Length" 32 33 // Retrieve the load of the machine. 34 func LoadGetLoad(w http.ResponseWriter, r *http.Request) { 35 w.Header().Add(ApiMonitoringLoadHeaderKey, strconv.Itoa(int(memdb.GetTotalRunningFunctions()))) 36 w.Header().Add(ApiMonitoringMaxLoadHeaderKey, strconv.Itoa(int(config.GetRunningFunctionMax()))) 37 w.Header().Add(ApiMonitoringQueueLengthHeaderKey, strconv.Itoa(queue.GetLength())) 38 39 w.WriteHeader(200) 40 /* 41 load, err := faas_containers-openfaas.GetCurrentLoad() 42 if err != nil { 43 errors.ReplyWithError(w, errors.GenericError) 44 log.Log.Debugf("%s cannot get current load from openfaas") 45 return 46 } 47 48 res := &types.Load{ 49 SchedulerName: scheduler.GetName(), 50 FunctionsDeployed: load.NumberOfServices, 51 FunctionsRunning: memdb.GetTotalRunningFunctions(), 52 FunctionsRunningMax: config.Configuration.GetRunningFunctionMax(), 53 FunctionsTotalReplicas: load.TotalReplicas, 54 QueueLengthMax: config.Configuration.GetQueueLengthMax(), 55 QueueFill: queue.GetQueueFill(), 56 } 57 58 rep, err := json.Marshal(res) 59 60 utils.SendJSONResponse(&w, 200, string(rep)) 61 */ 62 } 63