Jump to content

Server Stats Xml Dump


Guest painejake

Recommended Posts

Ok i want to edit the core to dump stats such as memory, CPU etc to a XML stats file in the way that as*ent does. I have looked at their source for a way to do it and found in WorldCreator.cpp this which i THINK is part of what i need:

void BuildStats(MapMgr * mgr, char * m_file, Instance * inst, MapInfo * inf)
{
       char tmp[200];
       strcpy(tmp, "");
#define pushline strcat(m_file, tmp)

       snprintf(tmp, 200, "        <instance>\\n");                                                                                                                                                                                                                                pushline;
       snprintf(tmp, 200, "                <map>%u</map>\\n", mgr->GetMapId());                                                                                                                                                                                pushline;
       snprintf(tmp, 200, "                <maptype>%u</maptype>\\n", inf->type);                                                                                                                                                                                pushline;
       snprintf(tmp, 200, "                <players>%u</players>\\n", mgr->GetPlayerCount());                                                                                                                                                        pushline;
       snprintf(tmp, 200, "                <maxplayers>%u</maxplayers>\\n", inf->playerlimit);                                                                                                                                                pushline;

       //<creationtime>
       if (inst)
       {
               tm *ttime = localtime( &inst->m_creation );
               snprintf(tmp, 200, "                <creationtime>%02u:%02u:%02u %02u/%02u/%u</creationtime>\\n",ttime->tm_hour, ttime->tm_min, ttime->tm_sec, ttime->tm_mday, ttime->tm_mon, uint32( ttime->tm_year + 1900 ));
               pushline;
       }
       else
       {
               snprintf(tmp, 200, "                <creationtime>N/A</creationtime>\\n");
               pushline;
       }

       //<expirytime>
       if (inst && inst->m_expiration)
       {
               tm *ttime = localtime( &inst->m_expiration );
               snprintf(tmp, 200, "                <expirytime>%02u:%02u:%02u %02u/%02u/%u</expirytime>\\n",ttime->tm_hour, ttime->tm_min, ttime->tm_sec, ttime->tm_mday, ttime->tm_mon, uint32( ttime->tm_year + 1900 ));
               pushline;
       }
       else
       {
               snprintf(tmp, 200, "                <expirytime>N/A</expirytime>\\n");
               pushline;

       }
       //<idletime>
       if (mgr->InactiveMoveTime)
       {
               tm *ttime = localtime( &mgr->InactiveMoveTime );
               snprintf(tmp, 200, "                <idletime>%02u:%02u:%02u %02u/%02u/%u</idletime>\\n",ttime->tm_hour, ttime->tm_min, ttime->tm_sec, ttime->tm_mday, ttime->tm_mon, uint32( ttime->tm_year + 1900 ));
               pushline;
       }
       else
       {
               snprintf(tmp, 200, "                <idletime>N/A</idletime>\\n");
               pushline;
       }

       snprintf(tmp, 200, "        </instance>\\n");                                                                                                                                                                                                                        pushline;
#undef pushline
}

void InstanceMgr::BuildXMLStats(char * m_file)
{
       uint32 i;
       InstanceMap::iterator itr;
       InstanceMap * instancemap;
       Instance * in;
       
       m_mapLock.Acquire();
       for(i = 0; i < NUM_MAPS; ++i)
       {
               if(m_singleMaps[i] != NULL)
                       BuildStats(m_singleMaps[i], m_file, NULL, m_singleMaps[i]->GetMapInfo());
               else
               {
                       instancemap = m_instances[i];
                       if(instancemap != NULL)
                       {
                               for(itr = instancemap->begin(); itr != instancemap->end()
                               {
                                       in = itr->second;
                                       ++itr;

                                       if(in->m_mapMgr==NULL)
                                               continue;

                                       BuildStats(in->m_mapMgr, m_file, in, in->m_mapInfo);
                               }
                       }
               }
       }
       m_mapLock.Release();
}

as im not to hot on the C++ side i was just wondering if someone could help me out with this? Any pointers would be great :D

I think i need more code though as that only looks like it generates the Instance stats..

Link to comment
Share on other sites

Yeah thanks for the base :)

The main thing im looking to pull out is the CPU and RAM usage just cause i like to look at those things :P and when im at work i cant do it. It would also be good to hav the instance that are currently being done and or when the instance resets :) If anyone want s to give me and hand with this it would be great as i said my C++ is not very good :P

Thanks for the resonses

Edit: Btw brunogcar what is it that i need to edit in world.h? Also is there a xml file for it or does it actually generate one? Cheers :D

Link to comment
Share on other sites

So, you can either have:

1. The server dumping the stats to an XML file, which is then put online via a webserver.

or

2. The server dumping the stats to a DB table, which is then read by a PHP script and put converted and put online via a webserver.

Personally, I would go with 2, but either would work.

Link to comment
Share on other sites

See the thing is php you may thing why not way easier! Yeah true but:

1. You cannot see how much Memory, CPU usage is used my mangos alone..

2. You cannot see latency (average and each player)

3. You can take ANY info from mangos you need anything!

So IMO the XML dump is the way forward although this thread isnt getting much of a response and as i said Me + C++ = disaster however i am very slowly learning and hope to mayeb get this done if on my own by 2012 xD

We'll see how it goes :)

Edit: Thanks for the link btw RedCell i might read that anyway as its quite interesting :)

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use